This project is part of the "Building a 12-Factor Agents App in Python" learning path from CodeSignal Learn. It demonstrates how to build reliable, production-ready LLM-powered applications following the 12-Factor Agents methodology.
The 12-Factor Agents framework, introduced by AI engineer Dex Horthy, provides a blueprint for building reliable, scalable, and maintainable applications powered by Large Language Models (LLMs). Inspired by Heroku's classic 12-Factor App methodology, this framework brings proven software engineering discipline to the world of AI agents.
The framework organizes twelve key principles into four main categories:
-
Structure Prompts, Tools, and Context - Converting natural language to structured tool calls, owning your prompts, managing context windows strategically, and treating tools as structured outputs.
-
Manage State and Control Flow - Unifying execution and business state, owning the control loop, detecting when agents get stuck, and breaking down complex tasks into small, focused units.
-
Error Handling and Human Interaction - Treating errors as context for learning, and designing effective human-in-the-loop workflows.
-
Scalability and Architecture - Making agents triggerable from anywhere, and designing them as stateless reducers for horizontal scaling.
The key insight: successful production AI applications aren't fully autonomous agents—they're well-engineered traditional software with LLM capabilities strategically integrated at key points. As the community says: "LLMs provide intelligence. The 12 Factors provide reliability."
This project implements a production-ready AI agent system that demonstrates the 12-Factor Agents principles in practice. The agent can:
- Process natural language requests and convert them into structured tool calls
- Execute complex multi-step workflows with deterministic control flow
- Maintain unified state across execution steps
- Handle errors gracefully and learn from them
- Support human-in-the-loop interactions when needed
- Resume interrupted workflows from saved state
- Scale horizontally through stateless design
The project is organized into four main components:
backend/core/- Core agent logic, state management, and tool definitionsbackend/server/- FastAPI server exposing REST endpoints for agent operations with SQLite database persistencebackend/client/- Example HTTP client demonstrating agent usagefrontend/- React web UI for managing and monitoring agents
The agent follows a stateless reducer pattern: it takes an input state and event, processes them through controlled steps, and produces an output state. All state is explicitly managed and persisted to a SQLite database, allowing workflows to be resumed, inspected, or debugged at any point. The server provides real-time progress updates as the agent executes.
- Python 3.10+
- Node.js 16+ and npm
- OpenAI API key
- Set your OpenAI API key:
export OPENAI_API_KEY="your-api-key-here"- Install dependencies:
# Backend
cd backend && pip install -r requirements.txt && cd ..
# Frontend
cd frontend && npm install && cd ..- Start both servers:
./start.shThis launches:
- Backend API on
http://localhost:8000 - Frontend UI on
http://localhost:3000
Press Ctrl+C to stop both servers.
Python FastAPI server implementing the core agent system.
- API endpoints for launching, monitoring, and controlling agents
- SQLite persistence for agent states
- Background execution with real-time progress updates
- Human-in-the-loop support via
ask_humantool
See backend/README.md for detailed documentation, API reference, and how to add new tools.
React web interface for agent management.
- Launch agents with natural language prompts
- Real-time monitoring of agent execution
- Execution history sidebar
- Interactive human-in-the-loop dialogs
- Resume/pause controls
See frontend/README.md for frontend-specific documentation.
backend/ # Python FastAPI server
├── core/ # Agent implementation (Agent, State, tools, prompts)
├── server/ # API endpoints and database
├── client/ # Example HTTP client
└── tests/ # Test scripts
frontend/ # React web UI
└── src/ # Components, API client, app logic
See backend/README.md and frontend/README.md for detailed structure.
This project demonstrates all 12 factors:
- Structured tool calls - Natural language → validated tool invocations
- Owned prompts - Version-controlled, file-relative paths
- Context management - Serialized context with explicit format control
- Unified state - Single State model for all data
- Owned control loop - Explicit
Agent.run()with step tracking - Stuck detection -
max_stepsprevents infinite loops - Small units - Single-responsibility tools
- Error as context - Errors returned as tool results
- Human-in-the-loop - Built-in
ask_humantool - Triggerable - REST API from any interface
- Stateless reducer - Agent is pure function (state in → state out)
- Horizontal scaling - Stateless design enables multiple instances
See backend/README.md for implementation details.
This project is designed as a hands-on learning experience. As you progress through the CodeSignal Learn path, you'll understand:
- How to structure LLM applications for production use
- The importance of explicit state management and control flow
- Best practices for error handling and recovery
- How to design scalable, maintainable AI systems
For more information about the 12-Factor Agents methodology, visit the official repository.