Skip to main content

A lightweight framework for building LLM-powered agents.

Project description

FlatAgents

Define LLM agents in YAML. Run them anywhere.

What is FlatAgents?

FlatAgents is a lightweight framework for single LLM calls. Each agent is a YAML config that specifies:

  • Model configuration
  • System and user prompts
  • Structured output schema

For multi-agent orchestration, state machines, and workflows, see flatmachines.

Why?

  • Composition over inheritance — compose stateless agents with simple config
  • Compact structure — easy for LLMs to read and generate
  • Inspectable — every agent is readable config
  • Language-agnostic — reduce code in any particular runtime
  • Common TypeScript interface — single schema for agents

Inspired by Kubernetes manifests and character card specifications.

Versioning

All specs (flatagent.d.ts, profiles.d.ts) and SDKs use lockstep versioning. A single version number applies across the entire repository.

Quick Start

pip install flatagents[all]
from flatagents import FlatAgent

agent = FlatAgent(config_file="reviewer.yml")
result = await agent.call(query="Review this code...")
print(result.output)

Example Agent

reviewer.yml

spec: flatagent
spec_version: "1.0.0"

data:
  name: code-reviewer

  model: "smart-expensive"  # Reference profile from profiles.yml

  system: |
    You are a senior code reviewer. Analyze code for bugs,
    style issues, and potential improvements.

  user: |
    Review this code:
    {{ input.code }}

  output:
    issues:
      type: list
      items:
        type: str
      description: "List of issues found"
    rating:
      type: str
      enum: ["good", "needs_work", "critical"]
      description: "Overall code quality"

What the fields mean:

  • spec/spec_version — Format identifier and version
  • data.name — Agent identifier
  • data.model — Profile name, inline config, or profile with overrides
  • data.system — System prompt (sets behavior)
  • data.user — User prompt template (uses Jinja2, {{ input.* }} for runtime values)
  • data.output — Structured output schema (the runtime extracts these fields)

Model Profiles

Centralize model configurations in profiles.yml and reference them by name:

profiles.yml

spec: flatprofiles
spec_version: "1.0.0"

data:
  model_profiles:
    fast-cheap:
      provider: cerebras
      name: zai-glm-4.6
      temperature: 0.6
      max_tokens: 2048

    smart-expensive:
      provider: anthropic
      name: claude-3-opus-20240229
      temperature: 0.3
      max_tokens: 4096

  default: fast-cheap      # Fallback when agent has no model
  # override: smart-expensive  # Uncomment to force all agents

Agent usage:

# String shorthand — profile lookup
model: "fast-cheap"

# Profile with overrides
model:
  profile: "fast-cheap"
  temperature: 0.9

# Inline config (no profile)
model:
  provider: openai
  name: gpt-4
  temperature: 0.3

Resolution order (low → high): default profile → named profile → inline overrides → override profile

Output Types

output:
  answer:      { type: str }
  count:       { type: int }
  score:       { type: float }
  valid:       { type: bool }
  raw:         { type: json }
  items:       { type: list, items: { type: str } }
  metadata:    { type: object, properties: { key: { type: str } } }

Use enum: [...] to constrain string values.

Multi-Agent Workflows

For orchestration, install flatmachines:

pip install flatmachines[flatagents]
from flatmachines import FlatMachine

machine = FlatMachine(config_file="workflow.yml")
result = await machine.execute(input={"query": "..."})

FlatMachine provides: state transitions, conditional branching, loops, retry with backoff, error recovery, and distributed worker patterns—all in YAML.

Features

  • Python SDK (TypeScript SDK in progress)
  • Structured output extraction
  • Multiple LLM backends (LiteLLM, AISuite)
  • Schema validation
  • Metrics and logging
  • Model profile management

Specs

TypeScript definitions are the source of truth:

Python SDK

pip install flatagents[litellm]

LLM Backends

from flatagents import LiteLLMBackend, AISuiteBackend

# LiteLLM (default)
agent = FlatAgent(config_file="agent.yml")

# AISuite
backend = AISuiteBackend(model="openai:gpt-4o")
agent = FlatAgent(config_file="agent.yml", backend=backend)

Schema 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")  # Respects FLATAGENTS_LOG_LEVEL env var
logger = get_logger(__name__)

Env vars: FLATAGENTS_LOG_LEVEL (DEBUG/INFO/WARNING/ERROR), FLATAGENTS_LOG_FORMAT (standard/json/simple)

For OpenTelemetry metrics:

pip install flatagents[metrics]
export FLATAGENTS_METRICS_ENABLED=true

Metrics are enabled by default and print to stdout every 5s. Redirect to file or use OTLP for production:

# Metrics print to stdout by default
python your_script.py

# Save to file
python your_script.py >> metrics.log 2>&1

# Disable if needed
FLATAGENTS_METRICS_ENABLED=false python your_script.py

# Send to OTLP collector for production
OTEL_METRICS_EXPORTER=otlp \
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317 \
python your_script.py

Env vars for metrics:

Variable Default Purpose
FLATAGENTS_METRICS_ENABLED true Enable OpenTelemetry metrics
OTEL_METRICS_EXPORTER console console (stdout) or otlp (production)
OTEL_EXPORTER_OTLP_ENDPOINT OTLP collector endpoint
OTEL_METRIC_EXPORT_INTERVAL 5000 / 60000 Export interval in ms (5s for console, 60s for otlp)
OTEL_SERVICE_NAME flatagents Service name in metrics

Migration from Pre-1.0

If you were importing machine classes from flatagents:

# Old (deprecated)
from flatagents import FlatMachine, MachineHooks

# New
from flatmachines import FlatMachine, MachineHooks

The flatmachines package contains all orchestration functionality:

  • FlatMachine and state machines
  • Hooks (MachineHooks, LoggingHooks, etc.)
  • Execution types (retry, parallel, MDAP)
  • Persistence and checkpointing
  • Distributed worker patterns
  • GCP backends (Firestore)

Install with FlatAgent support:

pip install flatmachines[flatagents]

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-1.1.0.tar.gz (52.6 kB view details)

Uploaded Source

Built Distribution

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

flatagents-1.1.0-py3-none-any.whl (66.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for flatagents-1.1.0.tar.gz
Algorithm Hash digest
SHA256 42689668d6b75578fa166086c6c104cc2b9d546a56705086c357f82c2eca8514
MD5 0248084201bf75bd41f06afef057eb8b
BLAKE2b-256 0be689544a1a94fe9592d525c03cd85942eba54a3fa7a54b79879151e7b6c06c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for flatagents-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 58a53bca8582df9282f1ae40e542975fcf2f367550c2bef717793a9238e867d1
MD5 8dbf5661e366a21658c5aa8351120eea
BLAKE2b-256 65d5c2ab017ba3f7ac5574b57624205b402631c70366d2baa850828ca96fff12

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