Skip to main content

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 AGENTS.md.

Install

pip install flatagents[litellm]
# or
pip install flatagents[aisuite]

Optional extras:

  • flatagents[validation] – JSON schema validation
  • flatagents[metrics] – OpenTelemetry metrics
  • flatagents[orchestration] – installs flatmachines and 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.* from FlatAgent.call(**input)
  • model.* resolved model config (provider/name/etc)
  • tools and tools_prompt if 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: flatprofile
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)
  • Codex OAuth backend (codex)
  • GitHub Copilot OAuth backend (copilot)

Selection order:

  1. backend argument to FlatAgent(...)
  2. data.model.backend
  3. FLATAGENTS_BACKEND env var ("litellm" or "aisuite")
  4. Auto-detect installed backend (prefers litellm)

Codex and Copilot are explicit only (not auto-detected):

model:
  provider: openai-codex
  name: gpt-5
  backend: codex
  oauth:
    auth_file: ~/.agents/flatmachines/auth.json
model:
  provider: github-copilot
  name: gpt-4o
  backend: copilot
  oauth:
    auth_file: ~/.agents/flatmachines/auth.json

Login helpers:

python -m flatagents.providers.openai_codex_login --auth-file ~/.agents/flatmachines/auth.json
python -m flatagents.providers.github_copilot_login --auth-file ~/.agents/flatmachines/auth.json

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)

Specs

Source of truth:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flatagents-4.0.1.tar.gz (110.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flatagents-4.0.1-py3-none-any.whl (136.6 kB view details)

Uploaded Python 3

File details

Details for the file flatagents-4.0.1.tar.gz.

File metadata

  • Download URL: flatagents-4.0.1.tar.gz
  • Upload date:
  • Size: 110.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for flatagents-4.0.1.tar.gz
Algorithm Hash digest
SHA256 6a1b06f6f6ddb7071f4f7f6e1ac2906092884b674466ee1fafe49fa5d5601ba1
MD5 85593b2409cbc2cd5b650e33d06d4dcb
BLAKE2b-256 f62489a88283d0091dfccd5f9a589c7ecd465cd78fd0c203e15ff9acf20e7128

See more details on using hashes here.

File details

Details for the file flatagents-4.0.1-py3-none-any.whl.

File metadata

  • Download URL: flatagents-4.0.1-py3-none-any.whl
  • Upload date:
  • Size: 136.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for flatagents-4.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f3b8d3b5c87212903e3652efaf6a303e7035a0fb500f70a49bb740eb4a6c8842
MD5 f43ddc6321c267af91d90da046819e63
BLAKE2b-256 113a245ebe116fb39e12d4c946feac7a8c10b92d7fcc1563c9f269ad53154895

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page