Practice: How an agent fetches its own data
For education only. This practice is about agent architecture; it is not investment, financial, or trading advice, and nothing here is a recommendation to buy or sell anything.
Self-check
Section titled “Self-check”Six short questions. Answer each in your head before opening the collapsible. Active retrieval is where the learning sticks.
1. What is a “tool,” and how does it let a text-only model act in the world?
Show answer
A tool is a function the model is allowed to call (fetch price history, pull news, read a balance sheet). The model does not run it; it asks for the call, the system runs the function, and the result is handed back to the model. That request-run-return cycle is what lets a model that can only produce text actually reach into the world.
2. The market analyst is given how many tools, and what are they?
Show answer
Two: get_stock_data (pull the price history) and get_indicators (compute technical measures from it). A narrow toolbox for a narrow job. The instructions tell it the order: call get_stock_data first, then get_indicators.
3. Describe the tool-use loop. What is the one edge that makes it a loop?
Show answer
The model responds; if it asked for a tool, the system runs the tool and sends the result back to the analyst, which decides again. The loop is the edge from the tool step back to the analyst node (workflow.add_edge(current_tools, current_analyst)). The analyst keeps pulling data, one call at a time, until it stops asking.
4. What is the stop condition, and why is it called “structural”?
Show answer
The analyst stops when its latest message contains no tool calls. At that point the prose it wrote is taken as the report. It is structural because nothing counts turns or sets a limit; the loop simply ends when the model makes no more tool requests. “No tool call” is the agent saying “I have enough.”
5. When an analyst finishes, the system wipes its messages before the next one starts. What survives, and why does this matter?
Show answer
Only the finished report survives (saved in shared state); the raw tool chatter and intermediate thoughts are cleared. It matters because each analyst then starts at a clean desk, and the team carries forward tidy summaries instead of every analyst’s scratch paper. (Why the report persists while the scratch does not is the shared-state lesson.)
6. Why is an agent that fetches its own data both more capable and harder to predict, and where does your control live?
Show answer
More capable because it uses its own judgment about what to look at, instead of being limited to whatever you pre-fetched. Harder to predict because it might pull more than expected or stop sooner than you would like. Your control lives in two choices: the tools you give it (the only things it can do) and the stop condition (when it is finished).
Try it yourself: give a role its own tools and a stop
Section titled “Try it yourself: give a role its own tools and a stop”No tooling, no cost; this is design judgment. Pick a gather-style role for a task you understand (for example: a “background checker” that researches a job applicant, or a “trip researcher” that finds options for a weekend away). Then:
1. List the few TOOLS this role needs. Each tool is one capability (look up X, fetch Y). Write a one-line description of each, clear enough that a model would know when to reach for it.2. Describe the LOOP: what does the role do with each result before deciding whether to call another tool?3. Choose an explicit STOP condition: it stops asking, it hits a step budget, or it satisfies a stated goal. Make sure the loop always ends.Show answer (worked example: trip researcher)
- Tools:
search_flights(find flights between two cities on a date range),search_lodging(find places to stay near a location),get_weather(forecast for a date and place). Three capabilities, each described by when to use it. - Loop: the agent checks flights, and if the prices or times are bad, it adjusts the dates and searches again; once flights look workable it searches lodging near the arrival, then checks weather. Each result feeds the next decision.
- Stop: it stops when it has one workable flight-plus-lodging option and a weather check, or after, say, eight tool calls, whichever comes first. The step budget guarantees the loop ends even if nothing perfect turns up.
Notice the shape matches the lesson: a small, well-described toolbox; a loop driven by the agent’s own judgment; and an explicit stop. The domain changed; the pattern did not.
Flashcards
Section titled “Flashcards”Eight cards. Click any card to reveal the answer. Use the Print flashcards button to lay out the full set as one card per page for offline review.
Q. What is a tool, in agent terms?
A function the model is allowed to ask to call. The model does not run it; it requests the call, the system runs the function, and the result is handed back. Tools are what let a text-only model act in the world.
Q. What does bind_tools do?
It attaches a set of tools to the model, telling it which functions it may call. After that, when the model responds it can either write text or ask to call one of those tools.
Q. How many tools does the market analyst get, and which?
Two: get_stock_data (pull the price history) and get_indicators (compute technical measures from it). A narrow toolbox for a narrow job.
Q. What is the tool-use loop?
Think, call a tool, read the result, decide again, repeat. In the code, the loop is the edge from the tool step back to the analyst, so each tool result returns to the analyst for the next decision.
Q. What is the analyst's stop condition?
It stops when its latest message makes no tool calls. At that point the prose it wrote becomes the report. Nothing counts turns; the loop just ends when the model stops asking for tools.
Q. What happens to an analyst's messages when it finishes?
They are wiped, leaving only a placeholder, so the next analyst starts at a clean desk. Only the finished report survives, saved in the team’s shared state.
Q. Why is a tool-using agent harder to predict?
Because it decides for itself what to fetch and when to stop, so it may pull more than you expected or finish sooner. That judgment is also why it is more capable than one you spoon-feed.
Q. Where does your control over a gathering agent live?
In two choices: the tools you give it (the only actions it can take) and the stop condition (what counts as finished). Those, not the model itself, shape what it gathers and when it ends.