The Agentic Loop: Three loops in a trench coat
This technical deep dive unpacks the commonly oversimplified concept of AI "agent loops" into three distinct, interconnected components: Inference, Tool, and Human loops. It provides a practical framework with pseudo-code for building robust agentic systems, appealing to developers and engineers grappling with complex AI architectures. The author emphasizes the crucial, yet challenging, role of the 'Human Loop' in ensuring control and safety within these systems.
The Lowdown
Robert Ross's article, "The Agentic Loop: Three loops in a trench coat," deconstructs the often-oversimplified notion of agent loops in AI. He argues that a truly "agentic" customer experience is not a single loop, but rather an intricate combination of three distinct loops working in concert. The piece uses pseudo-code examples to illustrate these concepts.
- The Inference Loop: This is the primary "outer" loop responsible for calling chat completion APIs, inferring the next words/tokens, passing tool usage requests, and crucially, managing chat history persistence. It highlights the stateless nature of most LLM APIs, requiring the entire conversation context to be sent with each request.
- The Tool Loop: This loop is where an LLM transitions from a "brain in a jar" to an active agent. It involves executing the external tools that the model infers it should use based on its prompts. The article warns about potential issues like hallucinated tool calls and the necessity of handling tool call IDs and error states.
- The Human Loop: This third, and arguably most difficult, loop provides a critical layer of oversight. It allows for human approval or denial of tool actions, effectively acting as a "Safety" or "Sanity Loop." While not a programmatic loop in the traditional sense, it represents a blocking function call that requires robust, durable execution frameworks to manage.
By elucidating these three interconnected loops—Inference, Tool, and Human—the article offers a foundational understanding for constructing sophisticated and controlled agentic AI systems, applicable to advanced functionalities like RAG and progressive discovery.