A lightweight framework for building LLM-powered agents.
Project description
FlatAgents (Python SDK)
Define single-call LLM agents in YAML. Use this package when you want one structured call per agent, with optional MCP tools and profile-driven model configs. For orchestration, install flatmachines separately.
For LLM/machine readers: see MACHINES.md.
Install
pip install flatagents[litellm]
# or
pip install flatagents[aisuite]
Optional extras:
flatagents[validation]– JSON schema validationflatagents[metrics]– OpenTelemetry metricsflatagents[orchestration]– installsflatmachinesand re-exports its APIs
Quick Start
from flatagents import FlatAgent
agent = FlatAgent(config_file="reviewer.yml")
result = await agent.call(code="...")
print(result.output)
Agent Config (YAML)
spec: flatagent
spec_version: "0.10.0"
data:
name: code-reviewer
model: "smart" # profile name or inline dict
system: "You are a careful reviewer."
user: "Review this code: {{ input.code }}"
output:
issues: { type: list, items: { type: str } }
rating: { type: str, enum: [good, needs_work, critical] }
Templates
system and user are Jinja2 templates with:
input.*fromFlatAgent.call(**input)model.*resolved model config (provider/name/etc)toolsandtools_promptif MCP tools are configured
Output Schema
If data.output is provided, FlatAgents requests JSON mode and parses the response. Invalid JSON falls back to {"_raw": "..."}.
Model Profiles (profiles.yml)
spec: flatprofiles
spec_version: "0.10.0"
data:
model_profiles:
fast: { provider: cerebras, name: zai-glm-4.6, temperature: 0.6 }
smart: { provider: anthropic, name: claude-3-opus-20240229 }
default: fast
# override: smart
Resolution order: default → named profile → inline overrides → override.
Python behavior: FlatAgent auto-discovers the nearest profiles.yml next to the config file. If a parent machine passes profiles_dict, it is used only as a fallback (no merging).
Backends
Built-in backends:
- LiteLLMBackend (default,
litellm) - AISuiteBackend (
aisuite)
Selection order:
backendargument toFlatAgent(...)data.model.backendFLATAGENTS_BACKENDenv var ("litellm" or "aisuite")- Auto-detect installed backend (prefers litellm)
MCP Tools
Configure MCP in data.mcp and pass a MCPToolProvider implementation. The SDK does not ship a provider; you supply one (e.g., from aisuite.mcp). Tool calls are returned in AgentResponse.tool_calls.
Validation
from flatagents import validate_flatagent_config
warnings = validate_flatagent_config(config)
Logging & Metrics
from flatagents import setup_logging, get_logger
setup_logging(level="INFO")
logger = get_logger(__name__)
Env vars: FLATAGENTS_LOG_LEVEL, FLATAGENTS_LOG_FORMAT, FLATAGENTS_LOG_DIR.
Metrics (OpenTelemetry):
pip install flatagents[metrics]
export FLATAGENTS_METRICS_ENABLED=true
Optional Orchestration
If flatmachines is installed (flatagents[orchestration]), the FlatMachine APIs are re-exported from flatagents for convenience:
from flatagents import FlatMachine
Examples (Repo)
- character_card
- coding_agent_cli
- custom_coding_workflow
- dfss_deepsleep
- distributed_worker
- dynamic_agent
- error_handling
- gepa_self_optimizer
- helloworld
- human-in-the-loop
- mdap
- multi_paper_synthesizer
- parallelism
- peering
- research_paper_analysis
- rlm
- story_writer
- support_triage_json
- writer_critic
Specs
Source of truth:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flatagents-2.2.1.tar.gz.
File metadata
- Download URL: flatagents-2.2.1.tar.gz
- Upload date:
- Size: 61.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
574e878bbf776e9a00e757259f78b7297d84cfbb10b9ad0b56c5a0d051f21dc1
|
|
| MD5 |
a8f454fc2594aa524406338988334c64
|
|
| BLAKE2b-256 |
20a4c72233562ed73a661fb46ee30eb2a8b9a649c444047fb32b3fa2c10b8ca6
|
File details
Details for the file flatagents-2.2.1-py3-none-any.whl.
File metadata
- Download URL: flatagents-2.2.1-py3-none-any.whl
- Upload date:
- Size: 75.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16e841b53cd34ddb4bc0dce741a8083d4d8c990c1ae66c5684e9f9332fb56f87
|
|
| MD5 |
09d3e90e2df2c32bffd62b407e5595a7
|
|
| BLAKE2b-256 |
653de9d5490a07ade17bb2534506c65bf46b5917ad6a3637b631d1a42401bb22
|