The algorithm is the decision procedure the agent uses to choose the next action.

The algorithm is what turns the agent loop into a policy. Without an algorithm, the agent loop is just a cycle; with an algorithm, the agent loop is a procedure that makes progress toward a goal. The algorithm is the operator's handle on the agent's behavior.

What the algorithm decides

The algorithm decides, at each loop iteration, what the agent should do next. The decision can be:

1. Tool call. Invoke a specific tool with a specific argument. The algorithm has decided that the next step is a tool call.

2. Sub-agent. Spawn a sub-agent to handle a subtask. The algorithm has decided that the next step is a sub-agent.

3. Wait. Wait for a specific event or for a specific time. The algorithm has decided that the next step is waiting.

4. Ask. Ask the user for clarification or approval. The algorithm has decided that the next step is a human-in-the-loop.

5. Stop. Stop the loop. The algorithm has decided that the work is done.

The algorithm's inputs

The algorithm typically takes the following inputs:

  • The current state of the agent (the working memory).
  • The session's memory (the long-term persistent state).
  • The available tools (what the agent can do).
  • The session's history (what the agent has done).
  • The user's intent (what the agent is trying to accomplish).

The algorithm uses these inputs to produce the next action. The algorithm is the function that maps the inputs to the action.

Why the algorithm matters

The algorithm is the right place to start when an operator is debugging an agent that is making the wrong decisions. Most operator issues with agents are not about the model's capabilities or the tools' implementations — they are about the algorithm: the algorithm is choosing the wrong tool, the algorithm is choosing the wrong argument, the algorithm is not handling a specific edge case, the algorithm is terminating too early, or the algorithm is not terminating at all. The algorithm is also the right place to start when an operator is adding capabilities — the canonical question is "should the algorithm be extended to handle this new case?"

The algorithm's evolution

The algorithm evolves over time. The algorithm starts simple (the model is asked to choose the next action), and the algorithm gets more complex as the operator adds constraints (the model is asked to choose from a constrained set of actions, the model is asked to choose based on a specific prompt, the model is asked to choose based on a learned policy). The algorithm's evolution is tracked through the observability layer, and the algorithm's regressions are the most common source of production incidents.

Related terms

The algorithm is the decision function in the agent loop. The algorithm's choices are recorded in the session's log. The algorithm's policy is one of the inputs to the memory layer. The algorithm's behavior is one of the inputs to the HITL approval workflow.

For the full primer, see First Steps: Sessions and Memory.

The algorithm's role in the agent's evolution

The algorithm's evolution is the agent's evolution. The agent's capabilities are the algorithm's capabilities; the agent's limitations are the algorithm's limitations; the agent's behavior is the algorithm's behavior. The operator's job is to evolve the algorithm as the operator's understanding of the work deepens.

The algorithm's evolution is tracked through the operator's observability layer. The algorithm's regressions are the most common source of production incidents. The algorithm's improvements are the most common source of production wins. The algorithm's evolution is the operator's most important work.