Patterns
๐Ÿ—๏ธ

12-Factor Agent Methodology(12FA)

Production-ready methodology adapting 12-factor app principles for scalable, maintainable agent systems with comprehensive monitoring and evaluation.

Complexity: highEvaluation and Monitoring

๐ŸŽฏ 30-Second Overview

Pattern: Production-ready methodology adapting 12-factor app principles for scalable, maintainable agent systems

Why: Moves agents beyond 70-80% prototype reliability to production-grade systems with human-in-the-loop workflows

Key Insight: Most successful agents aren't the most 'agentic' โ€” they're well-engineered software systems leveraging LLMs for controlled transformations

โšก Quick Implementation

1Design:Start with JSON extraction as foundation
2Structure:Own prompts, context windows, and control flow
3Architect:Build stateless, focused agents with explicit error handling
4Integrate:Add human-in-the-loop and multi-channel support
5Deploy:Monitor observability and iterate at the bleeding edge
Example: agent = Agent(prompt=owned, context=managed, flow=explicit, state=stateless, humans=first_class)

The 12 Factors in Detail

1

JSON Extraction as Foundation

Core LLM superpower: converting natural language to structured data. The ability to take a string and turn it into JSON.

2

Own Your Prompts

Production quality requires hand-crafted prompts, not abstractions. Own your prompts to tweak token order and system/user roles as models change.

3

Manage Context Windows Explicitly

Don't blindly append; actively manage what the LLM sees. Own the context window, squeezing traces and error summaries for self-healing.

4

Tools Are Just JSON and Code

Demystify "tool use" as simple routing. Treat tools as structured JSON outputs validated through switch statements.

5

Own Your Control Flow

Agents = prompt + switch + context + loop. Keep control-flow in code with explicit OODA loops and convergence heuristics.

6

Stateless Agent Design

Enable pause/resume and horizontal scaling. Persist execution state for idempotent restarts.

7

Separate Business from Execution State

Different lifecycles, different needs. Expose launch/pause/resume endpoints for safe replay runs.

8

Contact Humans as First-Class Operations

Not an edge case, but core functionality. Route high-stakes steps to humans as first-class tool calls.

9

Meet Users Where They Are

Email, Slack, Discord โ€” multi-channel by design. Trigger agents from wherever users already work.

10

Small, Focused Agents Beat Monoliths

3-10 steps max for reliability. Build small, single-purpose agents instead of chatty monoliths.

11

Explicit Error Handling

Process errors intelligently, not blindly. Compact errors into the next prompt to close the feedback loop.

12

Find the Bleeding Edge

Engineer reliability where models almost succeed. Find what's at the boundary of model capability and make it reliable.

๐Ÿ“‹ Do's & Don'ts

โœ…Hand-craft prompts for production quality, avoid prompt abstractions
โœ…Actively manage context windows with traces and error summaries
โœ…Build stateless agents that enable pause/resume functionality
โœ…Route high-stakes operations to humans as first-class tool calls
โœ…Keep agents small and focused (3-10 steps max)
โŒBlindly append to context windows without management
โŒBuild chatty monolithic agents instead of focused ones
โŒNest prompts - use explicit control flow in code instead
โŒIgnore error handling - compact errors into next prompt
โŒTreat human interaction as edge case rather than core feature

๐Ÿšฆ When to Use

Use When

  • โ€ข Building production-ready AI agents for enterprise
  • โ€ข Scaling beyond 70-80% prototype functionality
  • โ€ข Need reliable, maintainable agent systems
  • โ€ข Require human-in-the-loop workflows
  • โ€ข Building multi-channel agent experiences

Avoid When

  • โ€ข Simple demos or proof-of-concept projects
  • โ€ข Single-use or throwaway agent tasks
  • โ€ข Research experiments without production requirements
  • โ€ข Cases where 70-80% reliability is sufficient
  • โ€ข Purely automated workflows without human oversight needs

๐Ÿ“Š Key Metrics

Production Reliability
>90% success rate in production environments
Agent Response Time
P95 latency for agent task completion
Human Escalation Rate
% of tasks requiring human intervention
Context Window Utilization
Efficiency of context management
Error Recovery Success
% of errors resolved through self-healing
Multi-Channel Adoption
Usage across different user interfaces

๐Ÿ’ก Top Use Cases

Enterprise Customer Support: Human-escalated agent handling complex support tickets across multiple channels
Financial Operations: Stateless agents processing transactions with explicit error handling and audit trails
Content Management: Small, focused agents for content creation, review, and publication workflows
DevOps Automation: Agents managing deployment pipelines with human approval gates for production releases
Sales Enablement: Multi-channel agents supporting sales teams through CRM, Slack, and email integrations

References & Further Reading

Deepen your understanding with these curated resources

Contribute to this collection

Know a great resource? Submit a pull request to add it.

Contribute

Patterns

closed

Loading...

Built by Kortexya