An agent is a system that uses a model’s output to choose its next action, feeds the result back as input, and continues the task. Distinguish the model that requests a tool call from the program that actually runs it.
1. An execution loop with state
Provide the goal and current results as input, then let the model choose its next action from the allowed tools. The program validates the tool input and records either the result or the error in state. The model uses that information to choose what to do next. ReAct studies the interaction between reasoning and action. Frameworks vary in how they implement that interaction.
2. Enforce limits in the program
Put limits on the number of actions, elapsed time and cost in the program, along with retry and stopping conditions. Verify permissions and approvals again when a tool performs an external write. Text returned by a tool must never change the system’s permissions. With multiple agents, responsibilities and shared state still need to be defined.
3. Evaluate with a small example
Start with read-only document retrieval. Include valid input, a tool failure and a case where the material contains no answer. Log the chosen tool, its input, its output and the final answer so you can tell a bad decision from an execution error. For the specific APIs of a stateful framework such as LangGraph, consult the official documentation for your version. This article reports no benchmark results it has not reproduced.
4. Break a research task into state transitions
Suppose a fictional agent is investigating a service outage using three documents. Its initial state contains the question and the list of documents it can read. It saves the IDs and relevant passages returned by the search tool and searches again if information is missing. Once it has enough evidence, it writes an answer. If it reaches a limit before confirming the cause, it reports the facts it found and the remaining uncertainty. Requiring a single definitive success statement can prompt it to invent a conclusion on weak evidence.
The state needs a record of past actions as well as the final answer. If the agent keeps finding the same document with the same query, it should be possible to see that it has learned nothing new. Recording call counts, the last time it made progress, open questions and error types makes it easier to implement a stop rule. Structure the information needed to resume and review the work, avoiding unlimited storage of internal text.
One sequence is “search needed → run search → review results → search again or stop.” The model may propose another search, but the program checks the remaining budget and permitted tools before running it. The model’s output on its own grants no permission to act. This structure works without a complex framework. Even with one, the designer must define what each state and transition means.
5. Distinguish retries from duplicate execution
A transient read failure can be handled with a bounded retry. For tools that change external state, such as creating an order or submitting a file, automatically repeating a call after a lost response may duplicate the action. The tool needs a way to prevent duplicates using a request ID, or to check the prior result before retrying. A prompt saying “be careful when retrying” cannot reveal the status of a request already sent.
Classify the errors too. A malformed input calls for corrected parameters. Rephrasing a request cannot confer missing permission. If the service is temporarily down, a delayed retry may help within the time limit. A document that contains no answer is a valid search result. The agent should be able to report it to the user without trying an endless series of new search terms.
Show the approver exactly what they are reviewing. If a document will be shared outside the system, establish the recipient, the document and the scope of access before execution. If a later model decision changes those details, a new approval is needed. Save both the approval state and the action’s target so a reviewer can compare what the person approved with what actually ran.
6. Decide why you need several agents
Splitting research and review lets the two roles apply different criteria. With the same model and sources, they may still repeat the same mistake. Give the reviewer specific checks, such as whether each claim has evidence or whether an effective date is correct. Simply adding agents does not make an answer more accurate.
Consider conflicts in shared state when tasks run in parallel. Two researchers may read different versions of a document, or one may restore a conclusion the other deleted. Attach document versions and task IDs to the results and decide who consolidates the final findings. If concurrent editing is unnecessary, run reading and suggestions in parallel while applying the actual changes sequentially at one point. Weigh the gains from division of labor against the coordination cost.
Evaluate successful runs and cases that should stop. Check whether the agent stops within its limits after repeated failures, avoids routing unauthorized requests through a different tool, and reports unconfirmed findings when evidence is thin. Even a correct final answer cannot justify reading a document outside the permitted set. Record process constraints and output quality separately.
Use logs to check what actually happened instead of relying on a model’s lengthy account. Record the tool actually called, validated arguments, success or failure, state changes and why the run ended. Consider separately whether the log needs to reproduce sensitive document text. An identifier that lets you reproduce the error and the minimum supporting information often suffice for operations.
For a small automation with a fixed sequence, use code for prescribed lookups and checks. Reserve model decisions for interpretation or choosing search terms. Match the scope of autonomy to the task so stopping conditions and responsibilities are clear. Judge the loop by how reliably it completes the necessary work within the available evidence and permissions, rather than by how long it can run on its own.
Resuming from saved state and preventing duplicate external actions require separate controls. A request may succeed just after the state is saved, and the process may exit before recording that success. On restart, check the actual external result using a request ID or lookup tool. That boundary remains part of tool design even with a framework for long-running tasks. Reproducing a recovery scenario helps reveal how saving, execution and confirmation fit together.