How does an AI agent decide what to do next?
An AI agent decides what to do next by comparing its current goal and state with the actions available to it, then choosing the action that is most useful for making progress.
The decision is usually based on four things:
- what the agent is trying to achieve
- what it currently knows
- what actions or tools are available
- what happened in previous steps
1. Start from the goal
The agent first considers the objective it is working toward.
For example:
> Identify why a software deployment failed.
The goal gives the agent a basis for judging whether a possible next action is useful.
If the agent has already interpreted the user's request into a clear objective, that interpreted goal becomes part of its working state.
See “How does an AI agent interpret a user goal?” for the previous stage.
2. Examine the current state
The agent then looks at what is already known.
This may include:
- the original request
- completed steps
- tool results
- retrieved information
- errors
- pending tasks
- constraints
- previous decisions
For example, if the agent has already checked the deployment status and found an error code, there may be no reason to repeat the same check.
Instead, the error code becomes information for choosing the next step.
3. Consider the available actions
The agent can only choose from actions it is allowed and able to perform.
Possible actions might include:
- call an API
- query a database
- search a knowledge base
- read a file
- run code
- ask the user for missing information
- retry a failed operation
- produce the final answer
The available tools and permissions therefore directly affect the agent's decision.
4. Evaluate which action is most useful
The agent compares possible actions and chooses one that best supports the goal.
For example, after receiving an error code, it might consider:
- checking application logs
- checking infrastructure logs
- reviewing the latest deployment
- asking the user for more information
The best action depends on the current context.
In many modern agents, an LLM helps make this decision. Some systems also combine the LLM with rules, planners, policies, or deterministic control logic.
5. Use feedback from earlier actions
Results from previous actions influence future decisions.
For example:
Previous action: Query payment service Result: Payment service reports a timeout.
The agent may now decide to inspect service health or retry under an approved policy rather than continuing with an unrelated action.
This feedback-driven behavior is what makes the execution adaptive.
6. Decide whether another action is needed
Sometimes the correct next decision is not to call another tool.
The agent may determine that:
- the goal has already been achieved
- enough information exists to answer
- user input is required
- the task cannot continue safely
- a stopping condition has been reached
Choosing to stop is also part of the decision process.
Example
Suppose an agent is asked:
> Find out why my order has not shipped.
A simplified decision sequence might be:
- Goal: identify the shipping delay.
- Current state: order exists but has not shipped.
- Available actions: check payment, inventory, warehouse status, or carrier information.
- Decision: check inventory because shipment cannot proceed without available stock.
- Result: item is out of stock.
- Next decision: determine whether a restock date is available.
- Final decision: explain the cause and expected next step.
Each decision is based on the goal plus the latest information.
In short
An AI agent decides what to do next by using its goal, current state, available actions, constraints, and feedback from previous steps to select the most appropriate next action.
The chosen action is then executed, its result becomes new information, and the decision process repeats until the task is complete or another stopping condition is reached.
The next article, “How does an AI agent execute an action?”, covers what happens after the agent has selected its next step.
Learning Sequence
AI Agents Curriculum
Explore Related Questions
Deepen your understanding across related AI Agents topics.