AI Agents
An AI agent is a system that uses a model to choose actions in an environment. Agents often combine reasoning, memory, tools, retrieval, and feedback so they can complete multi-step tasks.
Why is state management important for long-running agents?
State management is important for long running agents because the agent must preserve reliable context across many steps, pauses, failures, and restarts . A short task may finish in a few seconds, but a long running task can continue for minutes, hours, or even longer. During that time, the agent needs a dependable record of what has already happened and what still needs to happen. Long running agents cannot rely on temporary context alone A long running agent may need to: wait for an external API pause for human approval retry a failed operation resume after a worker restart continue after an application deployment process many subtasks over time If important state exists only in temporary process memory, that information can be lost when execution stops or moves to another worker. Persistent state allows the agent to continue from the latest valid point. State prevents repeated work Suppose an agent is processing a large research task. It has already: collected data from source A analyzed source B completed three subtasks identified two remaining tasks If the agent loses that information, it may repeat work that was already completed. Good state management lets it resume with: Completed: A, B, C Pending: D, E This saves time, tool calls, and cost. State helps agents resume after interruptions Long running workflows are more likely to experience interruptions. For example: a worker crashes a network request fails a service becomes temporarily unavailable execution is intentionally paused a human response is required If the latest valid state has been stored, the system can restore it and continue instead of restarting the entire workflow. This is one reason checkpointing is important in long running agent systems. State keeps decisions consistent As execution progresses, the agent may accumulate important facts and decisions. For example: Goal: Investigate a production incident Database checked: Healthy Recent deployment checked: Suspicious Rollback approval: Pending The next execution step needs this information. Without reliable state, another worker or resumed process might make decisions based on incomplete or outdated context. State supports waiting and resuming Some long running tasks contain natural waiting periods. For example: 1. Submit a request. 2. Wait for approval. 3. Resume after approval. 4. Perform the approved action. 5. Verify the result. The agent should not remain actively running while waiting. Instead, the workflow can save its state, pause, and resume later when the required event occurs. State helps recover from failures When a step fails, state can preserve: the failed action the error retry count completed work available fallback options This allows recovery logic to make an informed decision. Without state, the system may retry from the beginning or repeat the same failed operation. State supports distributed execution Long running agent systems often use multiple workers. One worker may execute an early step, while another worker continues later. For example: Worker A: Collect data Worker B: Analyze results Worker C: Prepare final output Shared persistent state gives each worker the execution context it needs without depending on the previous worker remaining alive. State should be durable but selective Long running agents need durable state, but that does not mean every intermediate detail should be stored forever. The system should preserve information that is useful for: continuing execution tracking progress recovering from failure evaluating dependencies determining completion Large or outdated data can be summarized, archived, or referenced externally. Example Suppose an agent is processing a multi day vendor approval workflow. Before pausing, its state might contain: Goal: Approve new vendor Vendor review: Completed Security review: Completed Finance approval: Pending Current status: Waiting for finance Next action: Continue after finance decision When approval arrives the next day, the workflow can reload this state and continue immediately. It does not need to repeat the vendor and security reviews. In short State management is essential for long running agents because it preserves task progress and execution context across time, pauses, failures, restarts, and multiple workers. Reliable state allows the agent to resume from the correct point, avoid duplicated work, recover safely, and make consistent decisions throughout a long execution.
What is transient agent state?
Transient agent state is temporary information that an AI agent keeps only for the current execution or a short period of time. It helps the agent make decisions during an active task, but it is not necessarily saved permanently after the run ends. Why transient state exists Many pieces of information are useful only while a task is in progress. For example, an agent investigating a failed API request may temporarily track: the current retry count the latest error the last tool response which troubleshooting step is active Once the task finishes, some or all of this information may no longer be needed. Example Suppose an agent is processing: Find the cheapest direct flight to Mumbai tomorrow morning. During execution, the agent may temporarily store: candidate flights already checked current cheapest price search filters current search step temporary comparison results This information helps the agent complete the task. After the final answer is returned, the system may discard that working state. Transient state usually belongs to the current run Transient state is commonly scoped to: one agent execution one workflow run one session one temporary worker process It is useful while the task is active but may disappear when that execution finishes or the process terminates. What can be stored in transient state? Examples include: current step number intermediate calculations temporary tool outputs retry counters current branch temporary candidate lists active subtask status short lived flags The exact contents depend on the task. Transient state vs. persistent state Transient state is temporary and may exist only during the active execution. Persistent state is stored durably so it can survive pauses, restarts, or later execution. For example: Transient: Current API response being evaluated. Persistent: The workflow has completed the payment check and is waiting for human approval. The next article, “What is persistent agent state?” , covers persistent state in more detail. Transient state can still be important Temporary does not mean unimportant. If transient state is lost in the middle of execution, the agent may: repeat work lose intermediate results make inconsistent decisions restart from an earlier point For short tasks, this may be acceptable. For long running or critical workflows, important transient information may need to be promoted into persistent state or checkpointed. Transient state should stay small and relevant Because transient state is used repeatedly during execution, it should contain only information that helps the current task. Keeping unnecessary data can: increase context size increase token usage make relevant information harder to find preserve stale intermediate data The best transient state is focused on what the agent needs right now. Example of state evolution A troubleshooting agent may begin with: Retry count: 0 Last error: None Current step: Check service After a failed call: Retry count: 1 Last error: Timeout Current step: Retry service After recovery: Retry count: 1 Last error: Timeout Current step: Validate response These values may exist only during the current run. In short Transient agent state is short lived working information used during the current execution of an AI agent. It helps the agent track immediate progress and intermediate results, but it may be discarded when the run ends unless some of that information needs to be persisted for recovery or future execution.
What is persistent agent state?
Persistent agent state is information about an AI agent's execution that is stored durably so it can survive pauses, restarts, crashes, or changes in workers. Unlike temporary working state, persistent state remains available after the current process or execution step ends. Why persistent state is needed Some agent tasks cannot be completed in a single uninterrupted run. An agent may need to: wait for human approval pause for an external event continue after a worker restart recover from a system failure resume a long running workflow later Persistent state gives the system a reliable record of where the task currently stands. Example Suppose an agent is processing a vendor approval workflow. Its persistent state might contain: vendor review — completed security review — completed finance approval — pending current status — waiting for finance next action — continue after approval If the worker stops and another worker resumes the workflow later, this information is still available. The workflow does not need to start again from the beginning. Where persistent state can be stored Persistent state is usually written to durable storage such as: a database a workflow state store a checkpoint store durable object storage another persistent backend The exact storage mechanism depends on the agent architecture. What matters is that the state survives the lifetime of an individual process. What can persistent state contain? Useful persistent state may include: current goal completed and pending tasks important tool results approvals task dependencies retry information execution status checkpoint position identifiers needed to continue later The system should persist information that is necessary to restore meaningful execution context. Persistent state vs. transient state Transient state is temporary working information used during the current execution. Persistent state is durable information that must remain available across interruptions or later execution. For example: Transient: A temporary list of candidate results being compared right now. Persistent: The workflow has completed three subtasks and is waiting for approval before continuing. Not every temporary value needs to become persistent. Persistent state supports recovery Suppose a long running agent completes several steps and then its worker crashes. Without persistent state, the system may lose: completed work discovered information task progress retry history the correct next step With persistent state, a new worker can reconstruct the execution context and continue from the latest valid point. Persistent state supports distributed workers A workflow does not always stay on the same machine or process. For example: Worker A: Collect customer information Worker B: Validate eligibility Worker C: Continue after human approval Persistent state allows each worker to access the same durable execution context. This separates the workflow's identity from the lifetime of any particular worker. State should be saved at meaningful points Persistent state is often updated after important changes such as: a subtask completes a tool produces an important result an approval is received a retry count changes the workflow enters a waiting state the execution plan changes Saving at useful boundaries makes recovery more reliable. Persistent does not mean permanent Persistent state may survive execution interruptions without being stored forever. After a workflow is complete, the system may: archive the state retain only required audit information summarize it delete temporary execution data according to retention rules Persistence describes durability across execution boundaries, not unlimited retention. Store only what is needed Persisting everything can create unnecessary storage, privacy, and consistency problems. A good persistent state should contain enough information to: understand current progress continue safely avoid repeated work recover after failure determine the next valid action Large raw outputs may instead be stored separately and referenced from the state. In short Persistent agent state is durable execution information that remains available across pauses, failures, restarts, and worker changes. It allows an AI agent workflow to continue from the correct point instead of losing progress whenever the active process ends.
How do agents resume interrupted tasks?
An AI agent resumes an interrupted task by restoring previously saved execution state, identifying the last valid point in the workflow, and continuing from the next required step . The goal is to preserve progress instead of restarting the entire task. Why interruption recovery matters Agent workflows can be interrupted for many reasons, such as: worker crashes network failures service restarts deployment events waiting for human approval temporary external service outages intentional pauses If the system has saved the agent's progress, execution can continue later. 1. Save state before or during execution To resume reliably, the system must first persist important state while the task is running. This may include: current goal completed subtasks pending subtasks important tool results retry counts approvals workflow position current status Without saved state, the agent may not know what happened before the interruption. 2. Load the latest valid state When execution resumes, the system retrieves the most recent valid state or checkpoint. For example: Goal: Resolve customer account issue Completed: Verify identity, check account status Pending: Reset credentials Status: Interrupted This tells the agent what has already been completed. 3. Determine the correct resume point The system then identifies which step should run next. If the last successfully completed step was: Check account status the next step may be: Reset credentials The agent should not automatically repeat earlier successful work unless verification is required. 4. Verify uncertain actions before repeating them Some interruptions happen after an external action was sent but before the agent received confirmation. For example: Action: Create calendar event Interruption: Worker crashed before receiving the response The system should not immediately create another event. Instead, it should first check whether the original action succeeded. This helps prevent duplicate external actions. 5. Restore required context The resumed execution needs enough context to make the next correct decision. This may include: task inputs previous observations tool outputs task dependencies current plan user approvals relevant constraints The context should be reconstructed from durable state rather than depending on the memory of the previous process. 6. Continue with a new worker if necessary The same worker does not need to resume the task. For example: Worker A: Completes steps 1–4 and then crashes. Worker B: Loads the saved state and continues from step 5. This is possible because the workflow's progress is stored independently of the worker process. 7. Update state after resumption Once the task continues, state management works normally again. The system should: mark the resumed task as active record new results update completed work store new checkpoints continue until completion or another stopping condition Example Suppose an agent is processing a purchase approval. Before interruption: product selected — completed price verified — completed manager approval — pending purchase — blocked The workflow pauses while waiting for approval. Later, approval arrives. The agent reloads the state: product selected — completed price verified — completed manager approval — approved purchase — ready It can now continue with the purchase step without repeating the earlier work. Resume does not always mean start at the exact next line The system may need to revalidate some information before continuing. For example: a price may have changed an authorization token may have expired an external reservation may no longer be valid So a safe resume process may restore the previous state and then verify time sensitive information before proceeding. Checkpoints make resumption easier A checkpoint is a saved snapshot of workflow state at a meaningful execution point. Instead of reconstructing the entire history from scratch, the system can load the latest checkpoint and continue from there. The next article, “What is checkpointing in an agent workflow?” , covers this in more detail. In short An AI agent resumes an interrupted task by loading durable state or a checkpoint, determining the last successfully completed work, validating anything uncertain, and continuing from the next safe step . Reliable resumption allows long running workflows to survive interruptions without losing progress or accidentally repeating completed actions.
What is checkpointing in an agent workflow?
Checkpointing in an agent workflow is the practice of saving a durable snapshot of the workflow's current state at a meaningful point during execution. That saved checkpoint can later be loaded so the agent resumes from a known state instead of restarting the entire task. What a checkpoint represents A checkpoint captures enough information to reconstruct the workflow at a particular point. It may include: current goal completed subtasks pending subtasks important tool results current workflow position retry counters approvals execution status information required for the next step The exact contents depend on the workflow architecture. Example Suppose an agent is processing a vendor approval workflow. After the security review finishes, the system might save a checkpoint containing: Vendor review: Completed Security review: Completed Finance approval: Pending Current status: Waiting for finance Next step: Resume after finance decision If execution stops later, the workflow can reload this checkpoint and continue from the finance approval stage. When checkpoints can be created A system may create checkpoints: after every workflow step after important milestones before a risky external action before pausing for human approval before waiting for an external event after completing a major subtask Saving after every tiny operation may create unnecessary overhead, so checkpoint frequency is usually chosen based on the workflow's needs. Checkpointing is more than storing a final result A final result describes what happened after the task finished. A checkpoint stores the intermediate execution state needed to continue later . For example: Final result: Vendor approved. Checkpoint: Security review completed, finance approval pending, workflow waiting. The second representation is useful because the task is still in progress. Checkpointing supports pause and resume Checkpointing is especially useful when a workflow intentionally pauses. For example: 1. Collect information. 2. Save checkpoint. 3. Request human approval. 4. Pause execution. 5. Approval arrives later. 6. Load checkpoint. 7. Continue with the next step. The agent does not need to remain actively running while waiting. Checkpoints can survive worker changes A checkpoint should normally be stored outside the memory of a single worker. For example: Worker A: Completes several steps and saves a checkpoint. Worker A later stops. Worker B: Loads the checkpoint and continues execution. This makes the workflow less dependent on any particular process or machine. A checkpoint should represent a valid state A checkpoint should ideally be saved after the workflow reaches a consistent execution boundary. For example, if a task updates several pieces of state together, the checkpoint should not capture a partially updated version that could confuse a resumed run. The stored snapshot should give the next execution enough reliable information to continue safely. Checkpoint vs. persistent state Persistent state is the broader concept of storing workflow information durably. A checkpoint is a specific saved snapshot of that state at a particular execution point . A workflow may continuously maintain persistent state while also creating identifiable checkpoints that can be used for recovery or resumption. Checkpoint vs. execution history An execution history records what happened over time. A checkpoint records the state needed to continue from a particular moment. For example: History: Step 1 ran, then Step 2, then Step 3. Checkpoint after Step 3: Current goal, completed tasks, latest results, and the next valid action. Both can be useful, but they serve different purposes. Checkpoints may be versioned Some systems keep multiple checkpoints rather than only the latest one. For example: checkpoint after task 2 checkpoint after task 5 checkpoint before approval checkpoint after approval This can help with recovery, debugging, or inspecting how state changed over time. In short Checkpointing in an agent workflow means saving durable snapshots of execution state at useful points so the workflow can later restore that state and continue safely. A checkpoint captures where the workflow is, what has already happened, and what information is needed to proceed from that point.
How does checkpointing improve agent reliability?
Checkpointing improves agent reliability by preserving known good execution state so the workflow can recover from interruptions without losing all previous progress . Instead of treating every failure as a full restart, the system can restore a recent checkpoint and continue from a safe point. 1. It reduces the cost of failures Suppose an agent has completed 8 of 10 workflow steps and then crashes. Without checkpoints, the system may need to repeat all 8 completed steps. With a checkpoint after step 8, it can recover close to where execution stopped. This reduces: repeated tool calls repeated model calls latency external API usage execution cost 2. It preserves completed work A checkpoint records which parts of the workflow have already succeeded. For example: customer verified — completed account checked — completed eligibility confirmed — completed final action — pending After a restart, the agent can continue with the pending work instead of redoing completed tasks. 3. It makes long running workflows resumable Long running agents often pause naturally. They may wait for: human approval an external event a scheduled time another system a background job Checkpointing lets the workflow save its position before waiting and resume later with the correct state. 4. It improves recovery from worker crashes The process executing an agent may fail even when the workflow itself is still valid. If execution state exists only in worker memory, that state disappears with the worker. A durable checkpoint allows another worker to load the same workflow state and continue. This makes execution less dependent on any individual process or machine. 5. It supports safer retries Retries can be dangerous when the system does not know which work was already completed. For example, an agent may have successfully created an order but crash before recording the response. A reliable checkpoint strategy can help the system determine: what was definitely completed what was definitely not completed what is uncertain and must be verified This reduces the chance of blindly repeating external actions. Checkpointing does not replace idempotency, but it gives retry logic better execution context. 6. It gives the workflow a known recovery point A checkpoint should represent a valid and consistent state. If something goes wrong later, the system has a known state from which it can recover. For example: Checkpoint inputs validated account loaded authorization confirmed payment action not yet started If a later step fails, the workflow can return to this well defined point rather than reconstructing state from incomplete information. 7. It helps preserve consistency A resumed workflow should continue with the same important decisions and results that were already established. A checkpoint may preserve: selected plan completed tasks relevant observations approvals dependency status retry information This helps prevent a restarted agent from behaving as if earlier execution never happened. 8. It limits the amount of work lost Checkpoint frequency determines how much recent progress may be lost after a failure. For example: Checkpoint every major milestone If a failure occurs, only work since the latest milestone may need to be repeated. Saving checkpoints more frequently can reduce lost progress, but it may also increase storage and coordination overhead. The right checkpoint frequency depends on the cost and importance of the workflow. 9. It improves operational control Checkpoints can also help operators understand where a workflow stopped. For example: Last checkpoint: Security review completed Current task: Waiting for finance approval This makes it easier to inspect, resume, or intervene in long running executions. Checkpointing does not make every action safe by itself Checkpointing improves reliability, but it does not solve every failure problem. Agent systems may still need: idempotent actions bounded retries transaction handling validation duplicate action protection timeout handling human escalation Checkpointing works alongside these mechanisms. Example Suppose an agent is processing a multi step refund. It completes: 1. Verify customer. 2. Verify purchase. 3. Check refund eligibility. 4. Save checkpoint. 5. Issue refund. 6. Confirm refund. If the system crashes before step 5, it can resume from the checkpoint without repeating the earlier checks. If it crashes after sending the refund request but before confirmation, the resumed workflow should verify the refund status before trying again. This combination of checkpointing and safe recovery behavior makes the workflow more reliable. In short Checkpointing improves agent reliability by limiting lost progress, enabling recovery after failures, supporting pause and resume workflows, and giving retries a reliable view of what has already happened. It turns an agent workflow from a fragile uninterrupted process into an execution that can recover and continue from known good states.
What is agent context?
Agent context is the set of information currently available to an AI agent when it decides what to do next. It is the information the agent can actively use during reasoning or execution at that moment. What can be part of agent context? Agent context may include: the user's current request system instructions the current goal recent conversation history relevant agent state retrieved documents tool results task progress constraints selected memories information passed from previous workflow steps The exact contents depend on the agent architecture. Context is what the agent can see right now An agent may have a large amount of information stored across different systems, but only some of it is brought into the active context for a particular step. For example, an agent may have access to: thousands of documents long term memory workflow history database records But for the current decision, it may receive only: the user's question two relevant documents the current task status the latest tool result That smaller set is the active context for the step. Example Suppose an agent is helping investigate a failed payment. Its current context might contain: Goal: Determine why payment failed Customer ID: C102 Payment status: Declined Latest tool result: Card expired Current task: Determine next action Using this context, the agent may decide to ask the customer to update the payment method. Context can change from step to step Agent context is not necessarily fixed for the entire workflow. After a new action or tool call, new information may become relevant. For example: Before tool call Context: customer ID payment failure unknown reason After tool call Context: customer ID payment failure card expired replacement payment method required The new observation changes what the agent should consider next. Agent context vs. agent state Agent state is the structured information that represents the current condition and progress of the workflow. Agent context is the information actually provided to the agent for the current decision. State can be one source of context. For example: State contains: 20 completed task results retry history full workflow metadata several external references The current context may include only: the current goal the latest relevant result the next pending task one important constraint The entire state does not always need to be placed into context. Agent context vs. memory Memory stores information that may be useful across time. Context is what is actively available to the agent now. For example: Memory: The user prefers concise reports. Context: The current request, relevant documents, task status, and the retrieved preference that reports should be concise. Memory becomes useful to the current step only when relevant information is retrieved and included in context. Agent context vs. model training knowledge The model may already contain general knowledge from training. Agent context is different because it provides task specific information at execution time. For example, context may contain: a company's private policy today's tool result a user's current instruction the status of an active workflow These are not necessarily part of the model's static training knowledge. Why context should be relevant Giving the agent more information is not always better. Large amounts of irrelevant context can: distract the model hide important instructions increase token usage increase latency and cost make conflicting information harder to resolve A good agent system tries to provide the information needed for the current decision without flooding the model with unrelated data. Context can come from multiple sources An agent system may build context from: user input system instructions state memory retrieval systems databases files previous tool calls other agents The orchestration layer may select and combine the relevant pieces before the model is called. Context is limited Language models have a finite context window. This means an agent cannot always include every conversation, document, tool output, and state value at once. Agent systems may therefore: select relevant information summarize older information retrieve only needed documents remove stale details keep large outputs outside the active prompt and reference them when required Good context management helps the agent use its available context window effectively. In short Agent context is the information currently available to an AI agent for understanding the situation and deciding what to do next. It can be built from user input, state, memory, retrieved knowledge, tool outputs, and workflow information, but only the relevant subset needs to be active at any given step.
How should context be updated during an agent workflow?
Agent context should be updated throughout a workflow by adding new relevant information, replacing stale information, and removing details that are no longer useful for the current decision . The goal is to keep the agent's active context aligned with the latest state of the task. Add new observations When the agent receives new information, relevant parts should be added to the context. For example, after a tool call: Before Payment status: Unknown After Payment status: Declined Reason: Card expired The next agent step should use the updated information rather than the earlier incomplete view. Update information that has changed Some context becomes outdated during execution. For example: Earlier Task status: Waiting for approval Later Task status: Approved The old status should not remain active as if it were still true. When facts change, the context should reflect the latest valid version. Remove stale or irrelevant details Not every piece of earlier information needs to remain in the active context forever. For example, once a flight has been selected, dozens of rejected flight options may no longer be useful. The system may: remove them summarize them store them outside the active context keep only the final decision and important evidence This keeps the context focused. Preserve important constraints Some information should remain available throughout the workflow because it affects many later steps. Examples include: user requirements safety rules budget limits deadlines authorization boundaries task success criteria These should not accidentally disappear when context is refreshed. Include the latest relevant state Agent state is an important source of context. For example, if the state says: research completed comparison completed recommendation pending the current context should make that progress visible when the agent decides what to do next. The agent does not necessarily need the entire state object, only the parts relevant to the current step. Add tool results selectively Tool outputs can be large. Instead of adding every raw response to the active context, the system can include only the useful information. For example: Raw API response: Hundreds of fields Context added: Order status = delayed, estimated delivery = Friday This reduces unnecessary context while preserving the facts needed for the next action. Update context after each meaningful event Useful points for refreshing context include: user provides new information a tool call finishes a subtask completes an error occurs an approval is received the plan changes the workflow moves to another branch The context should represent the latest situation before the next important decision. Summarize older information when necessary As a workflow becomes longer, keeping every previous message and tool result may exceed the model's useful context capacity. Older information can be summarized. For example, instead of including 20 earlier troubleshooting steps individually: Summary: Network, authentication, and account status checks passed. The remaining suspected issue is an expired credential. This keeps the important conclusion without carrying every intermediate detail. Retrieve information again when needed Some information does not need to stay permanently in active context. A system may keep documents, memory, or large tool results outside the prompt and retrieve them only when relevant. For example: Current task: Compare contract termination terms. The agent can retrieve the relevant contract section at that point rather than keeping the entire contract in context during every earlier step. Keep context consistent with state The active context and stored workflow state should not contradict each other. For example, if state says: Refund completed the context should not still tell the agent: Refund pending Context construction should use the latest authoritative information available. Avoid adding everything A context update should not simply append every new event forever. Uncontrolled accumulation can create: duplicated facts conflicting information higher token usage slower model calls difficulty identifying what matters Good context management is selective. Example Suppose an agent is investigating why an order is delayed. Initial context: order ID customer request delivery status unknown After checking the order system: order ID shipment dispatched carrier identified tracking number available After checking the carrier: shipment dispatched delivery delayed by weather new estimated arrival: Friday At each stage, the context evolves to reflect the most useful current information. In short Agent context should be updated by bringing in new relevant observations, replacing outdated facts, preserving important constraints, summarizing older information, and removing details that no longer help the current step . A well maintained context gives the agent the information it needs now without carrying unnecessary history through every step of the workflow.
How can irrelevant context hurt agent performance?
Irrelevant context can hurt agent performance because it adds information that does not help the current task and can make important signals harder for the agent to identify . More context is not always better. Good agent systems try to provide the most useful information for the current decision rather than everything that is available. Irrelevant context can distract the agent Suppose an agent needs to decide whether a customer is eligible for a refund. Useful context might include: purchase date refund policy order status payment method previous refund attempts If the context also includes unrelated marketing history, old support conversations, unused product data, and irrelevant logs, the agent has more information to process without gaining anything useful. This can make the important facts less prominent. Important instructions can become diluted Critical constraints should be easy to identify. For example: Important rule: Refunds above a certain amount require human approval. If this rule is surrounded by a large amount of unrelated text, the model may give less attention to it than when the context is concise and focused. This is sometimes described as context dilution. Conflicting information can create confusion Irrelevant context may also contain old or contradictory information. For example: Old context: Customer account is inactive. Current state: Customer account has been reactivated. If both remain in the prompt without clear ordering or authority, the agent may use the wrong fact. Removing or replacing stale information reduces this risk. Large context increases token usage Every piece of text included in the model's context consumes tokens. Unnecessary context can therefore increase: input token usage execution cost latency processing overhead If the same unnecessary information is passed through many agent steps, the cost can accumulate significantly. Irrelevant context can hide relevant evidence Suppose a tool returns a response containing hundreds of fields, but only three fields matter for the next decision. Passing the entire response may make it harder for the agent to focus on: status error code recommended next action Extracting the useful fields produces a cleaner context. It can increase the chance of using stale information Long running workflows can accumulate old observations. For example: Earlier in the workflow: Inventory: Out of stock Later: Inventory: Restocked If both versions remain in context without clear updates, the agent may make a decision using the outdated value. Context should reflect the latest authoritative information. It can reduce planning quality An agent creating a plan should focus on information related to: the goal current state constraints dependencies available tools Unrelated history can lead the model to introduce unnecessary steps or pursue irrelevant branches. A focused context makes planning more aligned with the actual task. It can make tool selection worse If irrelevant details suggest unrelated actions, the agent may select the wrong tool. For example, a customer support workflow may include old billing information even though the current request is about delivery tracking. The agent could mistakenly choose a billing tool instead of the shipping status tool. Keeping context task specific reduces such mistakes. Context window limits make relevance even more important Models have finite context windows. If too much irrelevant information is included, useful information may: receive less attention be pushed farther away from the current instruction require aggressive truncation or summarization be excluded entirely The available context window should therefore be treated as a limited resource. Context should be selected, not accumulated blindly A weak strategy is: Add every message, tool output, document, and state field forever. A better strategy is to: keep current goals and constraints include relevant state add useful new observations summarize older history retrieve documents only when needed remove stale or unrelated details This keeps the active context aligned with the current step. Example Suppose an agent must determine why an API call failed. Useful context: request parameters response status error message latest retry result relevant API documentation Irrelevant context: earlier unrelated API calls user profile details old deployment logs unrelated tool results The smaller focused context gives the agent a clearer basis for diagnosis. In short Irrelevant context can reduce agent performance by distracting the model, diluting important instructions, introducing stale or conflicting information, increasing token cost, and making planning or tool selection less accurate. Effective agent systems keep context focused on what is useful for the current decision instead of continuously accumulating everything that has happened.
How can an agent maintain state across multiple execution steps?
An AI agent can maintain state across multiple execution steps by keeping a structured state object, updating it after each meaningful step, and passing or restoring the latest state before the next step runs . This allows later steps to build on earlier work instead of starting from scratch. Start with an initial state When a workflow begins, the system creates an initial state containing the information needed for execution. For example: Goal: Investigate failed order Order ID: O104 Completed tasks: None Current status: In progress Next task: Check payment This becomes the shared working record for the run. Each step reads the latest state Before performing work, a step should use the most recent state. For example: Step 1: Check payment It reads: order ID current goal current task Then it performs the payment lookup. The next step should not depend on hidden information that existed only inside Step 1. Each step writes back meaningful changes After execution, the step updates the state with information that later steps need. For example: Before Payment status: Unknown After Step 1 Payment status: Confirmed Payment check: Completed Next task: Check inventory The updated state becomes the input for the next step. Pass state explicitly between steps In a simple agent workflow, the state can be passed directly from one step to another. Conceptually: State → Step 1 → Updated state → Step 2 → Updated state → Step 3 This makes execution easier to understand because each step receives the current state and returns its changes. Keep state structured Structured state is easier to update reliably than one large block of unorganized text. Useful fields may include: goal inputs task statuses observations tool results errors retry counts approvals next action completion status Not every workflow needs all of these fields. The state should contain only what is useful for continuing execution. Update only the parts that changed A step usually does not need to rebuild the entire state. For example, an inventory step may update only: inventory status inventory task status next task Other information such as the order ID and payment result can remain unchanged. This reduces the chance of accidentally overwriting valid state. Persist state when execution may not stay in one process If all steps run immediately inside one process, in memory state may be enough. But persistent storage is useful when the workflow can: pause restart move to another worker wait for external input run for a long time In those cases, the latest state can be stored in a database, workflow store, or checkpoint system and loaded again before the next step. Use a run identifier Each workflow execution should have an identifier so its state can be separated from other runs. For example: Run ID: RUN 4821 The state store can associate all updates with that run. This is especially important when many agent executions happen concurrently. Keep completed work visible Later steps should be able to see what has already been completed. For example: Verify customer — completed Check payment — completed Check inventory — in progress Prepare response — pending This prevents the agent from unnecessarily repeating earlier work. Store important outputs, not just status A state entry should often preserve the result of a completed step. For example: Check inventory Status: Completed Result: Item unavailable Available again: Friday The next step can use this result without calling the inventory tool again. Validate state transitions The system should ensure that state changes make sense. For example: A task should not normally move from: Pending → Completed without the required execution taking place. Validation can help prevent invalid or contradictory state from propagating through later steps. Handle concurrent updates carefully If multiple steps run in parallel, they may update the same workflow state. For example: Step A: Updates pricing result Step B: Updates integration result The system should merge these changes safely so one update does not erase the other. Possible mechanisms include: transactional updates version checks separate state fields controlled merge rules The exact method depends on the architecture. Example Suppose an agent is resolving a delivery problem. Initial state: order identified payment check pending shipment check pending After Step 1: payment confirmed payment check completed shipment check ready After Step 2: shipment delayed shipment check completed reason: weather response task ready After Step 3: customer response prepared workflow completed Each step reads the accumulated state and adds the information needed by later steps. In short An AI agent maintains state across multiple execution steps by using a structured state record, reading the latest version before each step, writing back meaningful updates afterward, and persisting that state when execution spans time, workers, or interruptions . This creates continuity across the workflow and allows every step to build safely on the work completed before it.