How AI Agents Think and Act: Interleaved Reasoning and Multi-Turn Execution
Reliable multi-step agents must continuously revise their decisions based on real tool feedback. This article explains how interleaved reasoning, retained reasoning state, and per-turn thinking budgets improve agent reliability, while covering context costs, safety controls, observability, validation, and common implementation pitfalls.
1. Early Errors Are Amplified in Multi-Step Tasks
Agent tasks usually involve several stages: understanding the goal, breaking it into steps, calling tools, reading returned results, revising the plan, and producing a conclusion. The output of each stage becomes the input for the next.
If the initial judgment is wrong—for example, if the agent misunderstands a query condition or selects the wrong tool—later steps will continue from that incorrect assumption. The model may spend many tool calls solving a problem that was flawed from the beginning. The result not only wastes resources; the incorrect conclusion may also appear reasonable.
The central challenge for an agent system is therefore not whether the model can reason everything out in a single pass. It is whether the model can revise its judgment at every step based on real feedback.
2. Interleaved Reasoning: Breaking Plans into Correctable Steps
A common traditional approach is to create a complete plan first and then execute it step by step. This works well when the environment is stable and the workflow is predictable. However, in situations where information is incomplete or tool results are difficult to predict, a fixed plan can become obsolete quickly.
Interleaved reasoning alternates between reasoning and action. Each round consists of three steps:
- The model makes a short judgment based on the current context and decides whether a tool call is needed.
- The system executes the tool call and writes the result back into the context as an observation.
- The model reads the observation, updates its judgment, and decides whether to take another action or finish the task.
The key benefit is that every reasoning step is based on the latest real information. The plan is no longer a one-time artifact. Instead, it becomes a state that is continuously revised as new observations arrive.
The following example illustrates the loop structure. Error handling and security validation are omitted:
def run_agent(task, llm, tools, max_turns=10):context = [{"role": "user", "content": task}]for turn in range(max_turns):reply = llm.generate(context) # Includes reasoning and optional tool callscontext.append({"role": "assistant", "content": reply.text})if not reply.tool_calls:return reply.text # No tool call means the response is finalfor call in reply.tool_calls:result = tools.execute(call.name, call.arguments)context.append({"role": "tool","name": call.name,"content": result.to_text(),})raise RuntimeError("Maximum number of turns exceeded; task incomplete")
3. Retained Reasoning: Preserving the Basis for Decisions Across Turns
In a multi-turn interaction, the model’s judgment from the previous turn often remains useful. It may have already ruled out a hypothesis or confirmed the meaning of a field. If the model starts reasoning from scratch on every turn, it may repeat the same work or even overturn conclusions that have already been validated.
Retaining reasoning state—sometimes described as preserving reasoning across turns—allows the model to access the basis for earlier decisions and maintain consistency in later rounds. This is its primary value.
However, retention introduces three costs:
- Context cost: Reasoning content is often lengthy. The more content that is retained, the longer each input becomes, increasing latency and cost.
- Information boundaries: The reasoning process may contain intermediate assumptions or sensitive data. The system must define whether this information can be returned and which components may receive it.
- Accumulated noise: If an incorrect intermediate judgment is retained, it can continue influencing later decisions.
A common engineering compromise is to retain the complete reasoning from the most recent few turns while reducing earlier reasoning to a summary of conclusions.
def compact_history(context, keep_recent=4):old, recent = context[:-keep_recent], context[-keep_recent:]summary = summarize_reasoning(old) # Compress early reasoning into conclusions and verified factsreturn [{"role": "system", "content": summary}] + recent
4. Controlling Reasoning Depth Per Turn
Not every step requires the same level of reasoning. Reading a file from a known path or assembling a request with a fixed format can usually be handled quickly. Selecting a data source, determining whether an anomaly affects the result, or deciding whether to perform an irreversible action deserves more careful analysis.
Per-turn reasoning control allocates the reasoning budget to critical decision points. Common practices include:
- Set an output-length limit for each turn to prevent unlimited expansion.
- Require more detailed reasoning for high-risk actions such as writing data, deleting resources, sending messages, or changing permissions. Request human confirmation before execution when appropriate.
- Stop early and request more input when several consecutive turns produce no new observations or when the same tool is repeatedly called with identical parameters.
Whether an agent should spend more time reasoning can be evaluated using three factors: the side-effect level of the tool operation, the reversibility of the task outcome, and the degree of uncertainty in the current context.
5. Engineering Considerations
- Validate tool arguments: Parameters generated by a model are untrusted input. Perform type and range checks before making a call. Values inserted into commands or queries must be escaped, or parameterized interfaces should be used instead.
- Process observations safely: Text returned by a tool should also be treated as data. If it contains instruction-like text, the system should treat it as ordinary content rather than automatically following it.
- Apply least privilege: Grant each tool only the permissions required to complete its task. Separate read operations from write operations.
- Build observability: Record the tool name, a parameter summary, execution time, and result status for each turn. Avoid logging secrets, personal information, or other sensitive fields.
- Track evaluation metrics: Useful metrics include task completion rate, average number of turns, the percentage of failures caused by early errors, and the rate of human intervention. These measurements directly reflect the quality of initial decisions.
6. Common Misconceptions
Misconception 1: Longer reasoning is always better
Excessively long reasoning increases latency and may cause the model to spend attention on irrelevant details. Effective reasoning should support the next action.
Misconception 2: Retained reasoning is a memory system
Reasoning traces are evidence for decisions made during the current task. They cannot replace long-term memory or a knowledge base. Facts that need to be persisted should be stored in a dedicated system together with their source and timestamp.
Misconception 3: Validation is only necessary after an error
A more effective approach is to add checkpoints at critical stages. For example, validate the format of a tool result after it is returned and confirm the target of an operation before writing data.
7. Summary
The reliability of an agent performing a multi-step task depends on whether it can revise its judgment based on real feedback at every stage. Interleaved reasoning allows the plan to evolve as observations arrive. Retained reasoning state keeps decisions consistent across turns. Per-turn control ensures that reasoning resources are spent where they matter most.
Combined with validation, permission controls, and observability, these practices help agents move beyond merely being able to reason toward reliably completing tasks.
