Speaker Notes

12-Factor Agents: Patterns of reliable LLM applications — Dex Horthy, HumanLayer

Building reliable LLM agents requires treating them as pure functions and owning the control flow, context windows, and state rather than relying on black-box frameworks.

AI Engineer · 17:06 · YouTube ↗

Talk · solo speaker  Intermediate · concepts and agent patterns

Highlights

2 clips · 4 min of 17 min
    • Relying on naive loops where the LLM decides every step without control flow breaks down on longer workflows.
    • Pumping millions of tokens into a context window reduces reliability compared to carefully controlled token limits.
    • An agent harness consists of a prompt, a switch statement for output JSON, context building, and a clear exit loop.
    • Production systems work best when wrapping small, 3-to-10-step agent loops inside mostly deterministic CI/CD DAGs.
    • Handing off specific tasks like deployment steps to an LLM and then returning to deterministic code ensures high reliability.
    • Keep responsibilities narrow and manage state explicitly rather than letting agents run unchecked for too long.

Questions this video answers

10 · every answer cites the moment it was said
01 Why should I avoid complex black-box agent frameworks? 2 sources · 0:50

Heavy abstraction layers can trap you deep in call stacks when you try to push past 80% reliability. Instead, owning your control flow and building software from first principles gives you the flexibility needed for production.

02 How should I handle tool use errors without breaking the model? 2 sources · 10:46

Blindly appending error stack traces to the context window causes agents to spin out and lose context. Instead, clear pending errors and summarize them so the model receives clean input for the next valid tool call.

03 Why are large context windows less reliable than controlled ones? 2 sources · 6:33

While massive context windows can accept millions of tokens, they yield noisier results compared to curated inputs. Controlling and limiting the tokens in your context window consistently produces tighter and higher-reliability outcomes.

04 How do I manage execution state and persistence for agents? 2 sources · 7:43

You can manage agent state by placing your agent behind a REST API or MCP server. This allows you to serialize the context window into a database when waiting on tools and resume seamlessly using a state ID.

05 When should I use micro-agents instead of a single massive agent? 2 sources · 12:28

Micro-agents work best by combining a mostly deterministic DAG with small loops of three to ten steps for complex tasks. This keeps context manageable while allowing deterministic code to handle the rest of the pipeline.

06 How do I handle human-in-the-loop interactions effectively? 2 sources · 11:25

You can handle human intervention by pushing the choice between a tool call and a human message into a natural language token. This allows the model to explicitly state when it needs clarification or management approval using concepts it already understands.

07 Why do LLMs work best when treated as pure functions? 2 sources · 9:04

Treating large language models as pure functions means focusing entirely on token inputs and outputs. The reliability of your agent depends directly on the quality and density of the tokens you engineer into the context window.

08 How do I structure control flow for reliable agent execution? 2 sources · 5:20

Rather than trusting a black-box framework to guess the execution path, you should own your control flow with standard loops and switch statements. This lets you implement programmatic checks like breaking, switching, and summarization to guide the model.

09 How do I optimize prompt engineering for production apps? 2 sources · 8:58

While automated prompt generators can give you a strong starting point, reaching high reliability requires writing every token by hand. Testing numerous knobs and carefully curating your inputs helps you discover optimal prompt performance.

10 Why is designing small specialized agents better than monolithic ones? 2 sources · 12:28

Monolithic agents often fail on long workflows due to bloated context windows and untrackable behavior. By isolating specific tasks into small loops embedded within deterministic workflows, you achieve robust error handling and predictable execution.

Section-by-section summary

3 parts

Moving beyond naive agent prototypes

Many developers build agents that reach 70 to 80 percent reliability before stalling out in complex call stacks. Instead of writing massive prompt walls or relying on rigid black-box frameworks, developers can apply software engineering principles and modular patterns inspired by cloud-native design.

Owning control flow and context windows

LLMs are pure functions taking tokens in and spitting tokens out, meaning reliability depends entirely on what you put into the context window. By owning your prompt construction, context building, and execution loop, you can handle errors cleanly and prevent the model from getting stuck in infinite loops.

Deploying micro-agents with human oversight

Successful production architectures use micro-agents embedded within larger deterministic pipelines, such as deployment scripts. Integrating human-in-the-loop approvals via natural language tokens lets agents pause, wait for feedback, and resume execution safely without losing state.

0:00 / 17:06
k play/pause · f fullscreen · m mute
n next · p previous clip · t highlights/full
< > slower/faster · / search what was said
  • 12-Factor Agents2× · first 2:33

    A set of patterns for building reliable LLM applications based on software engineering principles.

  • MCP server1× · first 7:48

    A server protocol used to standardize tool interactions and agent communication.

  • Context engineering1× · first 10:16

    The practice of curating tokens, memory, and history to optimize LLM performance.

  • Micro-agents1× · first 12:32

    Small, focused agent loops combined with deterministic workflows for reliable execution.

  • A2 protocol1× · first 16:28

    A proposed protocol for standardizing how agents contact humans.

  • DAG4× · first 5:15

    Directed acyclic graph used to model workflows and control flow in software and agents.