A lightweight framework for building LLM-powered agents with pluggable backends.
Project description
FlatAgents Python SDK
Reference implementation of the FlatAgents spec.
Installation
pip install flatagents[litellm] # LiteLLM backend
pip install flatagents[aisuite] # AISuite backend
pip install flatagents[all] # Both backends
Usage
From YAML/JSON Config
from flatagents import DeclarativeAgent
agent = DeclarativeAgent(config_file="agent.yaml")
result = await agent.execute(input={"question": "What is 2+2?"})
From Dictionary
from flatagents import DeclarativeAgent
config = {
"spec": "declarative_agent",
"spec_version": "0.4.0",
"data": {
"name": "calculator",
"model": {"provider": "openai", "name": "gpt-4"},
"system": "You are a calculator.",
"user": "Calculate: {{ input.expression }}",
"output": {
"result": {"type": "float", "description": "The calculated result"}
}
}
}
agent = DeclarativeAgent(config_dict=config)
result = await agent.execute(input={"expression": "2 + 2"})
Custom Agent (Subclass FlatAgent)
from flatagents import FlatAgent
class MyAgent(FlatAgent):
def create_initial_state(self):
return {"count": 0}
def generate_step_prompt(self, state):
return f"Count is {state['count']}. What's next?"
def update_state(self, state, result):
return {**state, "count": int(result)}
def is_solved(self, state):
return state["count"] >= 10
agent = MyAgent(config_file="config.yaml")
trace = await agent.execute()
LLM Backends
Two backends available:
from flatagents import LiteLLMBackend, AISuiteBackend
# LiteLLM - model format: provider/model
backend = LiteLLMBackend(model="openai/gpt-4o", temperature=0.7)
# AISuite - model format: provider:model
backend = AISuiteBackend(model="openai:gpt-4o", temperature=0.7)
Custom Backend
Implement the LLMBackend protocol:
class MyBackend:
total_cost: float = 0.0
total_api_calls: int = 0
async def call(self, messages: list, **kwargs) -> str:
self.total_api_calls += 1
return "response"
agent = MyAgent(backend=MyBackend())
License
MIT License - see LICENSE for details.
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
flatagents-0.1.0.tar.gz
(9.5 kB
view details)
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-0.1.0.tar.gz.
File metadata
- Download URL: flatagents-0.1.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f40236208680a18701e621abdaca567d4fe62de72c369dd526cc4efd54e3848
|
|
| MD5 |
a3cee4cdc5530ea3f997ee25b94465c8
|
|
| BLAKE2b-256 |
56c98cb8cb51692afdeefa20e3d9cdb537777b0b993bd42b3dcd4614c7c8c3ea
|
File details
Details for the file flatagents-0.1.0-py3-none-any.whl.
File metadata
- Download URL: flatagents-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.4 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 |
ced908e225c135f92230819c859d2ff5e39446bf48405ea41847884869537b89
|
|
| MD5 |
5aea8ec8953f6d58049cf53dee5b6d46
|
|
| BLAKE2b-256 |
bad6352db4e4874e159e6fa49bef87c06ff5c4f9953b7440e4b158b599451e86
|