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.
What is an agent step?
An agent step is one individual unit of work performed by an AI agent during task execution. A step usually starts with the agent's current state, produces a decision or action, receives a result, and updates the state before the next step begins. A simplified view is: Current state → Decide or act → Receive result → Update state What happens in one agent step? Depending on the agent design, a step may include: reading the current goal and state deciding what to do next calling a tool processing the tool result updating task state determining whether another step is needed Not every step must contain a tool call. For example, one step might decide that the agent already has enough information to return a final answer. Example Suppose an agent is investigating why an order has not shipped. The current state says: order exists payment completed shipping status unknown One agent step might be: Decision: Check inventory availability. Action: Query inventory system. Result: Item is out of stock. State update: Record that inventory is the likely cause of the delay. The next agent step can now use this updated state. Steps build on previous steps Agent execution is usually sequential in the sense that each step can use information produced by earlier steps. For example: Step 1: Check payment status. Step 2: Check inventory. Step 3: Check expected restock date. Step 4: Return the explanation to the user. The exact number of steps depends on the task and what happens during execution. A step is not the entire task A single agent step is only one part of the overall execution. For a simple task, one step may be enough. For a complex task, the agent may need many steps before the goal is complete. The broader repeated process is covered in “What is an agent execution cycle?” Step boundaries depend on the framework Different agent systems define a step differently. In one framework, a step may mean: one model decision In another, it may include: one model decision plus one tool execution In a graph based agent system, a step may correspond to: execution of one node or transition The important idea is that a step represents a bounded unit of progress inside the larger agent run. Why agent steps matter Tracking work as steps helps developers: monitor agent progress debug failures record tool usage enforce execution limits measure cost and latency prevent uncontrolled loops For example, an agent may be configured to stop after a maximum number of steps if it has not completed the task. That concept is covered separately in “What is a maximum step limit in an agent?” In short An agent step is one bounded unit of execution inside an AI agent's larger task processing cycle . Each step uses the current state to make progress, produces new information or an action, updates the state, and prepares the agent for the next step.
What is an agent trajectory?
An agent trajectory is the complete sequence of states, decisions, actions, observations, and results that an AI agent goes through while working on a task. It shows the path the agent followed from the beginning of execution to the final outcome. A simplified trajectory might look like this: Initial state → Decision → Action → Observation → Updated state → Decision → Action → Final result Why is it called a trajectory? The word trajectory describes the path an agent takes through a task. Two agents can start with the same goal but follow different trajectories depending on: what they observe which actions they choose what tools return whether errors occur how the agent adapts The final answer may be the same even if the path taken is different. Example Suppose an agent is asked: Find out why my order has not shipped. A possible trajectory could be: 1. Receive the order ID. 2. Check payment status. 3. Observe that payment succeeded. 4. Check inventory. 5. Observe that the product is out of stock. 6. Check the expected restock date. 7. Receive the restock estimate. 8. Explain the shipping delay to the user. That complete sequence is the agent's trajectory for the task. What can a trajectory contain? Depending on the system, a recorded trajectory may include: user input agent state decisions tool selections tool inputs tool outputs observations errors retries intermediate results final output stopping reason The exact amount of information recorded depends on the agent framework and observability setup. Trajectory vs. agent step An agent step is one bounded unit of execution. An agent trajectory is the sequence of many steps that occurred during the whole run. For example: Step 1: Check payment Step 2: Check inventory Step 3: Check restock date Step 4: Return answer Together, those steps form the trajectory. For the smaller unit, see “What is an agent step?” Why trajectories are useful Agent trajectories are useful for understanding how an agent behaved. They can help developers: debug unexpected behavior see which tools were used understand where a failure occurred compare successful and unsuccessful runs evaluate whether the agent took unnecessary steps measure cost and latency improve prompts, policies, or tool selection For example, if an agent repeatedly calls the same tool without making progress, that pattern becomes visible in its trajectory. Successful and unsuccessful trajectories A successful trajectory reaches the intended goal. An unsuccessful trajectory may end because: a tool failed required information was unavailable the agent chose poor actions permissions prevented progress a maximum step limit was reached a stopping condition ended execution Studying both types can help improve the agent system. Trajectory does not mean hidden reasoning An agent trajectory generally refers to observable execution events , such as actions, tool calls, state changes, and results. It does not require exposing private internal reasoning or hidden chain of thought. A system can log useful execution behavior without recording or revealing hidden reasoning. In short An agent trajectory is the complete path an AI agent follows through a task, including its sequence of steps, actions, observations, state changes, and final outcome . It provides a practical record of how the agent moved from the initial task to completion or failure.
What is an agent state?
An agent state is the current collection of information an AI agent uses to understand where it is in a task and what has happened so far. It acts like the agent's working snapshot during execution. As the agent performs actions and receives new results, the state can change. Why agent state is needed AI agents often work across multiple steps. Without state, the agent may lose track of: what the user asked what has already been completed what information has been discovered what errors occurred what still needs to be done State helps maintain continuity from one step to the next. Example Suppose an agent is investigating why an order has not shipped. At one point, its state might represent: Goal: Identify the shipping delay Payment: Confirmed Inventory: Out of stock Restock date: Not checked yet Task status: In progress The next decision can use this state to avoid repeating earlier checks and focus on what is still missing. State changes during execution Agent state is usually dynamic. For example: Initial state Goal received No actions completed After the first step: Payment checked Payment successful After the second step: Inventory checked Item unavailable After another step: Restock date found The state evolves as the agent learns more and makes progress. State connects one step to the next Each agent step can read the current state and then update it. A simplified flow is: Read state → Decide → Act → Observe result → Update state → Next step This allows later steps to build on earlier work. For example, if the state already records that a warehouse has no inventory, the agent can move on instead of checking the same warehouse again. State can be temporary or persistent Some state exists only while a single agent run is active. For example: current task progress recent tool results temporary calculations Other systems may persist state so execution can resume later after an interruption. Whether state is temporary or stored persistently depends on the agent architecture. Agent state vs. memory State and memory are related but not identical. Agent state usually describes the information needed for the current execution or task. Memory often refers to information retained for longer periods, potentially across multiple tasks or conversations. For example: “The inventory check failed during this run” is task state. “The user generally prefers morning meetings” could be longer term memory. A system may use both. State does not have to contain everything Good state management does not mean storing every piece of information produced during execution. The state should contain information that is useful for: making future decisions tracking progress avoiding repeated work determining completion handling failures The next article, “What information should be stored in agent state?” , covers this in more detail. In short An agent state is the current working representation of an AI agent's task, progress, observations, and execution context . It changes as the agent works and allows each new step to use what happened in previous steps instead of starting from scratch.
What information should be stored in agent state?
The agent state should store the information an AI agent needs to continue a task correctly without losing track of what has already happened . The goal is not to save everything. Good agent state keeps the information that is useful for future decisions, progress tracking, recovery, and completion. 1. The current goal The agent should know what it is trying to accomplish. For example: Goal: Identify why an order has not shipped. Keeping the goal in state helps later steps remain aligned with the original task. 2. Important task inputs and constraints State should include information that affects how the task must be completed. Examples include: order ID customer ID requested date budget location required output format deadlines permissions business rules These details prevent the agent from repeatedly asking for information it already received. 3. Current progress The agent should track what has already been completed and what remains. For example: payment checked inventory checked restock date still pending This helps prevent repeated work and supports better next step decisions. 4. Relevant observations and tool results Important results from previous actions should be retained. For example: Inventory result: Product is out of stock. The agent may not need to preserve every raw response forever, but it should keep the information needed for later reasoning. For large outputs, the system may store a summary, reference, identifier, or selected fields instead of copying the entire result into working state. 5. Errors and failed actions Failures can influence later decisions, so important error information should also be part of state. For example: API request timed out authentication failed warehouse A already checked retry count: 2 Without this information, an agent may repeatedly attempt the same failed action. 6. Pending work State should make it clear what still needs attention. For example: Completed: check payment check inventory Pending: check restock date prepare final explanation This becomes especially useful in longer multi step tasks. 7. Execution status The state may also contain information about the overall run, such as: not started in progress waiting for user input waiting for approval completed failed This helps the orchestration layer determine what should happen next. 8. Information needed for stopping conditions If task completion depends on specific criteria, the state should contain enough information to evaluate them. For example, if the goal is: Find three valid hotel options under ₹8,000 per night. the state might track: number of valid hotels found whether each meets the budget whether location requirements are satisfied Once the required conditions are met, the agent can stop. What should not be stored unnecessarily? Agent state should avoid becoming an uncontrolled dump of every message and tool response. Storing too much can: increase processing cost make relevant information harder to find introduce outdated context create unnecessary privacy or security exposure The state should therefore contain the minimum useful information needed to continue execution correctly . Example For an order investigation agent, a useful state might contain: Goal: Explain shipping delay Order ID: A1045 Payment: Confirmed Inventory: Out of stock Restock date: October 9 Completed: Payment check, inventory check, restock lookup Pending: Return explanation Status: In progress This gives the next step enough context without requiring the agent to repeat earlier work. In short Agent state should store the goal, important inputs and constraints, completed work, relevant observations, errors, pending tasks, execution status, and information needed to determine completion . The best state is not the largest state. It is the smallest reliable representation that gives the agent enough context to make the next correct decision.
What is the difference between stateful and stateless agents?
A stateful agent keeps relevant information from earlier steps or interactions and uses it later. A stateless agent treats each request or execution independently unless the required context is provided again. The key difference is whether the agent itself carries forward task context. Stateful agent A stateful agent maintains information as a task progresses. For example, suppose an agent is investigating a delayed order. After several steps, its state might contain: payment confirmed inventory unavailable restock date found final explanation still pending The next step can use this information directly. The agent does not need to repeat earlier checks because the results are already available in state. Stateless agent A stateless agent does not automatically retain information from a previous request or execution. Each request must contain the information needed to complete that request. For example, if a stateless service receives: Check order status for A1045. it processes that request and returns the result. If another request arrives later, the service does not automatically know what happened before unless the required context is supplied again. Example Imagine a multi step support task. A stateful agent may work like this: Step 1: Check payment → store result Step 2: Check inventory → use payment result plus new result Step 3: Check shipping → use all relevant previous results Step 4: Return final explanation A stateless agent would need the necessary earlier context to be passed into each new request. For example: Request: Using payment=confirmed and inventory=out of stock, determine the next action. The agent can still make the correct decision, but the state is being supplied externally rather than maintained by the agent itself. Stateful does not necessarily mean long term memory A stateful agent may keep information only for the duration of one task. For example, it might remember several tool results during a single execution and then discard them when the task ends. Long term memory is a separate capability. State usually describes the information needed to continue the current execution. Stateless does not mean context free A stateless agent can still receive a large amount of context. The difference is that the context must be provided as part of the current request. For example, an application could store task state in a database and send the relevant information to a stateless agent every time it is invoked. In that architecture, the agent call is stateless even though the overall application maintains state. Advantages of stateful agents Stateful agents are useful for: multi step tasks long running workflows tasks with dependencies avoiding repeated work recovering from interruptions tracking task progress They can naturally build on earlier results. Advantages of stateless agents Stateless designs can be useful because they are often: simpler to scale easier to retry easier to reproduce less dependent on local execution history They work well when each request is self contained or when state is managed by another system. Which approach should be used? It depends on the task and architecture. Use stateful behavior when later decisions depend strongly on earlier results. Use stateless behavior when each request can be handled independently or when another component is responsible for storing and supplying all required context. Many production systems combine both approaches: persistent state is stored externally individual model or worker calls remain stateless the orchestration layer reconstructs the necessary context for each step In short A stateful agent carries relevant task context across steps or interactions , while a stateless agent processes each request independently unless earlier context is supplied again . The difference is not simply whether information exists, but where that information is maintained and how it is made available to the next step.
How does an agent know when a task is complete?
An AI agent knows a task is complete when the current state satisfies the success criteria defined for the goal . In other words, the agent should not stop simply because it has taken several actions. It should stop because there is enough evidence that the requested outcome has been achieved. Start with a clear goal Completion depends on having a goal that can be evaluated. For example: Find three hotels near the conference venue for under ₹8,000 per night. This goal suggests measurable completion criteria: three hotels have been found each is near the required location each is within the budget enough information is available to present the options Once those conditions are satisfied, the agent can consider the task complete. Compare the current state with the success criteria As the agent works, it updates its state with results from each step. For example: Goal: Schedule a team meeting Required participants: 5 Available time found: Yes Calendar event created: Yes Invitations sent: Yes The agent can compare this state with the expected outcome. If all required conditions are satisfied, another action may be unnecessary. Completion should be based on evidence The agent should use actual results rather than assumptions. For example: Action: Create calendar event Tool result: Event created successfully with ID 4821 That tool result provides evidence that the action succeeded. If the tool instead returns: Request timed out. the agent should not mark the task complete unless it can independently confirm that the event was created. Different tasks have different completion criteria For an information task, completion might mean: the required facts were found the answer addresses the user's question important constraints were satisfied For an action task, completion might require: the external action actually succeeded the expected system state was reached For a multi step task, completion may require several conditions to be true at the same time. Example Suppose an agent receives: Find out why order A1045 has not shipped and tell me the reason. The agent might progress through these states: 1. Payment checked: successful 2. Inventory checked: item unavailable 3. Restock information found 4. Cause of delay identified 5. Explanation prepared At this point, the requested outcome has been achieved. The agent does not need to keep checking unrelated systems. The final response can be part of completion Sometimes finding the answer is not enough. If the user asked to receive the result, the task may not be complete until the agent returns it. For example: Goal: Analyze the failed deployment and explain the cause. The agent may identify the cause internally, but it should still deliver the explanation before marking the user facing task complete. Completion is different from forced stopping An agent can stop without successfully completing the task. For example, execution might end because: required information is unavailable permission is missing human approval is required an execution limit is reached continuing would be unsafe These are stopping conditions, but they do not necessarily mean the goal was achieved. The next article, “What is a stopping condition in an AI agent?” , covers those conditions separately. Why explicit completion criteria matter Without clear completion criteria, an agent may: stop too early perform unnecessary extra steps repeat work continue indefinitely claim success without evidence Good completion criteria give the agent a concrete way to evaluate progress and decide when successful execution should end. In short An AI agent knows a task is complete by comparing its current state and verified results with the success criteria for the goal . When the required outcome has been achieved and any necessary final response or action has been completed, the agent can stop successfully.
What is a stopping condition in an AI agent?
A stopping condition is a rule or situation that tells an AI agent to end its current execution instead of taking another step. A stopping condition does not always mean the task was successfully completed. It simply means the agent should stop continuing the loop. Why stopping conditions are needed AI agents often work in repeated cycles such as: Observe → Decide → Act → Observe again Without clear stopping conditions, the agent may: continue after the goal is already complete repeat the same actions waste tool calls or computation keep retrying a failed operation enter an infinite loop continue into unsafe or unauthorized actions Stopping conditions place boundaries around execution. 1. Goal completed The most desirable stopping condition is successful completion. For example: Find three hotels under ₹8,000 per night. If the agent has found three valid options that satisfy the requirements, it can stop. This type of stopping condition is based on the task's success criteria. 2. Required information is unavailable The agent may need to stop when it cannot obtain information required to continue. For example: a required file is missing an API does not provide the needed data the user has not supplied a necessary value The agent may stop and request the missing information instead of continuing blindly. 3. Human approval is required Some actions should not be performed automatically. For example: issuing a large refund deleting important data making a purchase changing production infrastructure The stopping condition may be: Stop and request approval before executing this action. Execution can continue later if approval is received. 4. Maximum number of steps reached An agent may be given an execution limit. For example: Maximum steps: 20 If the agent reaches step 20 without finishing the task, the system stops the run. This prevents uncontrolled loops and limits cost. The dedicated article “What is a maximum step limit in an agent?” covers this mechanism in more detail. 5. Retry or error limit reached The agent may also stop after repeated failures. For example: API failed three times authentication cannot be restored the same tool keeps returning the same error Instead of retrying forever, the system can stop or escalate the task. 6. Safety or permission boundary reached An agent should stop if continuing would require an action that is not allowed. For example: required permission is missing requested action violates a policy tool access is restricted the action exceeds an approved limit This is different from successful task completion, but stopping is still the correct behavior. 7. No meaningful progress Some systems detect that the agent is repeating actions or failing to reduce uncertainty. For example: Step 8: Search source A Step 9: Search source A again Step 10: Search source A again If repeated steps produce no useful new information, the system can stop or switch to escalation. This helps prevent infinite or unproductive loops. Completion vs. stopping condition Task completion means the intended outcome has been achieved. A stopping condition is any condition that ends execution. Therefore: Goal achieved → stop successfully. Human approval needed → stop temporarily. Step limit reached → stop without completion. Safety rule triggered → stop to protect the system. Required information missing → stop and request input. The previous article, “How does an agent know when a task is complete?” , focuses specifically on successful completion. Good stopping conditions should be explicit A well designed agent should have clear rules for when execution ends. These rules may include: success criteria maximum steps maximum retries time limits budget limits approval requirements safety boundaries unrecoverable errors The exact conditions depend on the task and the risk of allowing the agent to continue. In short A stopping condition is a rule that ends an AI agent's execution when continuing is no longer necessary, useful, permitted, or safe . Stopping conditions help agents finish cleanly, avoid unnecessary work, control cost, and prevent uncontrolled execution.
How do you prevent an agent from entering an infinite loop?
You prevent an AI agent from entering an infinite loop by giving its execution clear limits and checking whether each step is making meaningful progress . The safest approach is to combine several controls rather than rely on a single rule. 1. Define explicit stopping conditions The agent should know when execution must end. Examples include: the goal has been achieved required information is unavailable human approval is needed continuing is not permitted no valid next action exists Without explicit stopping rules, the agent may continue taking actions even when there is nothing useful left to do. 2. Set a maximum number of steps A hard step limit prevents an agent from running indefinitely. For example: Maximum steps: 20 If the agent reaches that limit without completing the task, the execution stops or escalates. This acts as a final safety boundary even if other loop detection logic fails. The next article, “What is a maximum step limit in an agent?” , covers this control in more detail. 3. Limit retries Failures should not trigger unlimited retries. For example: API call failed → Retry up to 3 times → Use fallback or stop Retry limits are especially important for: unavailable APIs authentication failures timeouts repeated tool errors The agent should record retry counts in state so it knows when the limit has been reached. 4. Detect repeated actions The system can track recent actions and identify when the agent is repeating the same behavior. For example: check inventory check inventory check inventory check inventory If the inputs and results are effectively unchanged, repeating the same action is unlikely to make progress. The system can then stop, choose another strategy, or escalate. 5. Detect lack of progress Not all loops repeat the exact same action. An agent may take different actions while still failing to get closer to the goal. A useful control is to ask whether recent steps produced meaningful new information or completed any pending work. For example: Goal: Identify the cause of an error. If ten steps produce no new evidence and the uncertainty remains unchanged, the agent may be stuck even though the actions are different. 6. Track completed work in state Good state management helps prevent the agent from forgetting what it has already done. For example: source A checked source B checked authentication already retried user already asked for missing ID The next decision can use this information to avoid repeating completed work. 7. Use time, cost, or resource limits Execution can also be bounded by limits such as: maximum runtime maximum tool calls token budget cost budget API quota These limits prevent a poorly behaving agent from consuming unlimited resources. 8. Escalate when the agent is stuck Stopping does not always need to mean abandoning the task. When repeated attempts fail, the agent may: ask the user for missing information request human review use an approved fallback return a partial result with the blocking issue This is often better than continuing an unproductive loop. Example Suppose an agent is trying to retrieve an unavailable customer record. A safe execution might be: 1. Query the primary system. 2. Receive a timeout. 3. Retry once. 4. Receive another timeout. 5. Try an approved fallback source. 6. Fallback also fails. 7. Stop and report that the required data could not be retrieved. An unsafe agent might simply continue retrying the first tool forever. Use multiple safeguards together A robust agent might combine: clear completion criteria stopping conditions a maximum step limit retry limits repeated action detection no progress detection resource budgets escalation paths Each mechanism protects against a different type of loop. In short To prevent an AI agent from entering an infinite loop, bound its execution and monitor whether it is actually making progress . Clear stopping conditions, step and retry limits, state tracking, repetition detection, progress checks, and escalation rules help ensure the agent stops or changes strategy instead of continuing indefinitely.
What is a maximum-step limit in an agent?
A maximum step limit is the highest number of execution steps an AI agent is allowed to take during a single run. If the agent reaches that limit before completing the task, the system stops the execution instead of allowing the agent to continue indefinitely. Why a maximum step limit is useful Agents often work in loops: Observe → Decide → Act → Observe again If something goes wrong, the agent may: repeat the same action keep retrying a failed tool explore unnecessary paths fail to recognize that it is stuck A maximum step limit provides a hard boundary that guarantees the run eventually stops. Example Suppose an agent is configured with: Maximum steps: 10 The agent may perform: 1. Check payment status. 2. Check inventory. 3. Check warehouse status. 4. Check carrier status. 5. Inspect an error. 6. Retry an API call. If the task finishes at step 6, execution stops normally. If the agent reaches step 10 without completing the task, the system stops because the maximum step limit has been reached. What counts as a step? The exact meaning of a step depends on the agent framework. A step might represent: one model decision one tool call one model and tool interaction one graph node execution one iteration of an agent loop Because frameworks define steps differently, the configured limit should match the architecture of the system. For the general concept, see “What is an agent step?” What should happen when the limit is reached? Reaching the maximum step limit should not be treated as successful completion unless the goal was actually achieved. The agent system may instead: stop execution return a partial result explain that the task could not be completed within the limit save the current state request human review allow a controlled continuation later The stopping reason should be recorded so developers and users can distinguish a completed task from a terminated run. Maximum step limit vs. retry limit A maximum step limit restricts the total number of execution steps. A retry limit restricts how many times a particular failed action may be attempted again. For example: Maximum steps: 20 API retry limit: 3 Both controls can be used together. Maximum step limit vs. task completion The step limit is a safety boundary, not a definition of success. For example: Goal: Find three valid suppliers. If the agent finds all three suppliers after eight steps, the task is complete even if the maximum is twenty. If the agent reaches twenty steps with only one supplier found, execution stops, but the goal has not been completed. Choosing the right limit The limit should be high enough for legitimate tasks but low enough to prevent uncontrolled execution. Factors may include: expected task complexity number of tools involved typical number of subtasks cost per step latency requirements risk of repeated actions Simple agents may need only a few steps, while complex research or troubleshooting agents may require more. Why a step limit alone is not enough A maximum step limit is an important safeguard, but it should not be the only one. A robust agent can also use: clear stopping conditions retry limits repeated action detection no progress detection time limits cost or token budgets These controls can stop a bad execution earlier instead of waiting for the maximum step limit. In short A maximum step limit is a hard cap on how many execution steps an AI agent may take in one run . It prevents runaway or infinite execution and provides a final safety boundary when other stopping or progress checks fail.
How should an agent handle a failed execution step?
When an AI agent encounters a failed execution step, it should first recognize the failure, record what happened, and then choose a controlled recovery path instead of blindly repeating the same action . A useful pattern is: Detect failure → Understand the cause → Update state → Retry, change strategy, escalate, or stop 1. Detect that the step failed The agent should not assume that every action succeeds. Failure may be indicated by: an error response a timeout a missing result invalid data a permission error a failed validation check an unexpected system state For example: Action: Retrieve customer account Result: Permission denied The agent should treat this as a failed step, not as a successful lookup with no data. 2. Record the failure in state Important failure information should be added to the agent's state. This may include: which action failed which tool was used the error type retry count relevant error details whether a fallback has already been attempted Recording this prevents the agent from forgetting the failure and repeating the same action indefinitely. 3. Determine whether the failure is recoverable Not every failure should be handled in the same way. A temporary failure may be recoverable. Examples: network timeout temporary service outage rate limit transient tool error A non recoverable failure may require a different path. Examples: missing permission invalid identifier unavailable required data prohibited action The agent should choose the recovery strategy based on the type of failure. 4. Retry only when it makes sense Some failures justify a retry. For example: API timeout → Wait briefly → Retry But retries should be limited. A safe pattern might be: Attempt → Failure → Retry 1 → Failure → Retry 2 → Stop or use fallback Unlimited retries can create loops and unnecessary cost. 5. Change strategy when retrying will not help If the same action keeps failing, the agent should consider another approach. For example: Primary API unavailable Possible alternatives: use an approved backup API query another data source ask the user for the missing information defer the task escalate to another system or person The agent should not keep repeating an action when the evidence suggests the strategy itself is failing. 6. Ask for human input or approval when necessary Some failures cannot be resolved automatically. For example: missing authorization ambiguous business decision high risk operation conflicting data required approval The agent may pause and request human assistance rather than making an unsafe assumption. 7. Preserve partial progress A failed step does not always mean the entire task must restart. If useful work has already been completed, the agent should preserve it in state. For example: payment status already checked inventory already checked shipping lookup failed The agent can continue from the useful results instead of repeating earlier successful steps. 8. Stop when recovery is no longer productive The agent should stop when: retry limits are reached no approved fallback exists required permissions are unavailable continuing would be unsafe the maximum step limit is reached repeated attempts produce no meaningful progress Stopping safely is better than continuing indefinitely. Example Suppose an agent is checking an order status. 1. Action: Query order API. 2. Failure: Request times out. 3. State update: Record timeout and retry count. 4. Decision: Retry once. 5. Failure: Second timeout. 6. Decision: Use approved backup system. 7. Result: Order data retrieved successfully. 8. Continue: Resume the original task using the recovered information. The failure changes the execution path without forcing the agent to abandon all previous progress. Failure handling should be predictable A well designed agent should have explicit policies for: which errors can be retried maximum retry counts available fallback tools when human escalation is required which failures must immediately stop execution This makes recovery behavior more reliable and easier to test. In short An AI agent should handle a failed execution step by detecting and recording the failure, evaluating whether it is recoverable, retrying only within defined limits, switching strategies when appropriate, preserving useful progress, and escalating or stopping when recovery is not possible . The goal is not to avoid every failure, but to recover from failures in a controlled way without creating loops or unsafe behavior.