Agentform Architecture
Agentform is built as a modular system with five core packages, each with a specific responsibility.
System Overview
flowchart TB
subgraph User["User Layer"]
Agentform["📄 .agentform Spec"]
CLI["⚡ agentform-cli"]
Agentform --> CLI
end
subgraph Core["Core Layer"]
SCHEMA["📦 agentform-schema"]
COMPILER["🔧 agentform-compiler"]
RUNTIME["🚀 agentform-runtime"]
COMPILER --> SCHEMA
COMPILER --> RUNTIME
end
subgraph Integration["Integration Layer"]
MCP["🔌 agentform-mcp"]
LLM["🧠 LLM Providers"]
TOOLS["🛠️ External Tools"]
end
CLI --> COMPILER
RUNTIME --> MCP
RUNTIME --> LLM
MCP --> TOOLS
Core Packages
| Package | Description |
|---|---|
| agentform-schema | Core Pydantic models for specs and Intermediate Representation |
| agentform-compiler | Parses .agentform files, validates specs, and generates IR for the runtime |
| agentform-runtime | Workflow execution engine with LLM integration and policy enforcement |
| agentform-mcp | MCP (Model Context Protocol) client for connecting to external tool servers |
| agentform-cli | Command-line interface for validating and running workflows |
Package Details
agentform-schema
The foundation of Agentform, providing:
- Type-safe data models for all Agentform constructs
- Intermediate Representation (IR) schema
- Validation rules and constraints
Key Components:
models.py: Core data models (agents, workflows, policies, etc.)ir.py: Intermediate Representation schemaversion.py: Version management
agentform-compiler
Transforms .agentform files into executable IR:
- Parsing: Converts HCL-like syntax to Abstract Syntax Tree (AST)
- Normalization: Resolves references and applies defaults
- Validation: Ensures type safety and constraint satisfaction
- IR Generation: Produces the Intermediate Representation
Key Components:
agentform_parser.py: Parses.agentformfilesagentform_resolver.py: Resolves references and dependenciesagentform_validator.py: Validates configurationsir_generator.py: Generates IR from validated ASTagentform_module_loader.py: Loads external modules
agentform-runtime
Executes workflows defined in the IR:
- State Management: Tracks workflow execution state
- Step Execution: Executes individual workflow steps
- LLM Integration: Calls LLM providers for
llmsteps - Policy Enforcement: Enforces budgets, timeouts, and capability limits
- Tracing: Records execution traces for debugging
Key Components:
engine.py: Main workflow execution enginestate.py: State managementllm.py: LLM provider integrationpolicy.py: Policy enforcementtracing.py: Execution tracingapproval.py: Human-in-the-loop approval
agentform-mcp
Connects Agentform to external tools via Model Context Protocol:
- MCP Client: Communicates with MCP servers
- Capability Mapping: Maps MCP tools to Agentform capabilities
- Server Management: Manages connections to multiple MCP servers
Key Components:
client.py: MCP client implementationserver.py: Server connection managementtypes.py: MCP type definitions
agentform-cli
Provides the command-line interface:
- Command Parsing: Parses CLI arguments
- Orchestration: Coordinates compiler and runtime
- Output Formatting: Formats results for display
Key Components:
main.py: CLI entry pointcommands/: Individual command implementationsinit.py: Module initializationvalidate.py: Validation commandcompile.py: Compilation commandrun.py: Workflow execution
Data Flow
Compilation Flow
1
2
3
4
5
6
7
8
9
.agentform files
↓
[Parser] → AST
↓
[Resolver] → Resolved AST
↓
[Validator] → Validated AST
↓
[IR Generator] → IR JSON
Execution Flow
1
2
3
4
5
6
7
8
9
10
11
IR JSON
↓
[Runtime Engine] → Workflow State
↓
[Step Executor] → Step Results
↓
[LLM/MCP Integration] → External Calls
↓
[Policy Enforcement] → Constraint Checks
↓
[Output] → Final Results
Extension Points
Adding LLM Providers
- Implement provider interface in
agentform-runtime - Add provider type to schema
- Update compiler to recognize new provider
Adding Step Types
- Define step type in schema
- Implement step executor in runtime
- Update compiler validation
Adding Capabilities
- Connect MCP server via
agentform-mcp - Define capabilities in
.agentformfiles - Use in workflows via
callsteps
Design Principles
- Separation of Concerns: Each package has a single, well-defined responsibility
- Type Safety: Extensive use of Pydantic for runtime type checking
- Extensibility: Clear interfaces for adding providers, steps, and capabilities
- Declarative: Users describe what they want, not how to achieve it
- Observability: Built-in tracing and logging throughout