The core loop

Every AI agent, regardless of framework or implementation, executes a loop: receive input, decide what to do next, take an action, observe the result, and repeat until the task is complete or a stopping condition is reached. The complexity of a production agent is almost entirely in how that loop handles the cases where each step produces something unexpected. The happy path is easy. Production is the sum of all the unhappy paths.

The orchestrator

The orchestrator is the component that runs the loop. It holds the current state of the task, decides when to call the model, passes the assembled context, parses the model output, and routes the next action. Most agent frameworks, LangChain, LlamaIndex, AutoGen, Pydantic AI, provide an orchestrator. Building your own is appropriate for use cases where the framework abstractions produce more friction than value.

The orchestrator is where most production bugs live, because it is the component that has to handle every combination of model output and environment state. When a model returns a tool call with a malformed argument, when a tool returns an error partway through a multi-step task, when the task goal becomes unreachable due to an intermediate result, the orchestrator is what decides what happens next. That logic is almost never covered in a tutorial.