Build, debug, evaluate, and operate AI agents. The only SDK with fork-and-rerun Agent Replay.
Project description
FastAIAgent SDK
Build, debug, evaluate, and operate AI agents. The only SDK with Agent Replay — fork-and-rerun debugging for AI agents.
Works standalone or connected to the FastAIAgent Platform for visual editing, production monitoring, and team collaboration.
Quickstart
from fastaiagent import Agent, LLMClient
# Create an LLM client
llm = LLMClient(provider="openai", model="gpt-4o")
# Create an agent
agent = Agent(
name="my-agent",
system_prompt="You are a helpful assistant.",
llm=llm,
)
# Run it
result = agent.run("What is the capital of France?")
print(result.output)
print(result.trace_id) # every run is traced — use this ID for replay/debugging
Debug a failing agent in 30 seconds
from fastaiagent.trace import Replay
# Load a trace from a production failure
replay = Replay.load("trace_abc123")
# Step through to find the problem
replay.step_through()
# Step 3: LLM hallucinated the refund policy ← found it
# Fork at the failing step, fix, rerun
forked = replay.fork_at(step=3)
forked.modify_prompt("Always cite the exact policy section...")
result = forked.rerun()
No other SDK can do this.
Evaluate agents systematically
from fastaiagent.eval import evaluate
results = evaluate(
agent_fn=my_agent.run,
dataset="test_cases.jsonl",
scorers=["correctness", "relevance"]
)
print(results.summary())
# correctness: 92% | relevance: 88%
Trace any agent — yours or LangChain/CrewAI
import fastaiagent
fastaiagent.integrations.langchain.enable()
# Your existing LangChain agent, now with full tracing
result = langchain_agent.invoke({"input": "..."})
# → Traces stored locally or pushed to FastAIAgent Platform
Build agents with guardrails and cyclic workflows
from fastaiagent import Agent, Chain, LLMClient, Guardrail
from fastaiagent.guardrail import no_pii, json_valid
agent = Agent(
name="support-bot",
system_prompt="You are a helpful support agent...",
llm=LLMClient(provider="openai", model="gpt-4o"),
tools=[search_tool, refund_tool],
guardrails=[no_pii(), json_valid()]
)
# Chains with loops (retry until quality is good enough)
chain = Chain("support-pipeline", state_schema=SupportState)
chain.add_node("research", agent=researcher)
chain.add_node("evaluate", agent=evaluator)
chain.add_node("respond", agent=responder)
chain.connect("research", "evaluate")
chain.connect("evaluate", "research", max_iterations=3, exit_condition="quality >= 0.8")
chain.connect("evaluate", "respond", condition="quality >= 0.8")
result = chain.execute({"message": "My order is late"}, trace=True)
Expose agents as MCP servers (Claude Desktop / Cursor / Continue / Zed)
Any Agent or Chain becomes an MCP server with one line:
from fastaiagent import Agent, LLMClient
agent = Agent(name="research_assistant", llm=LLMClient(provider="openai", model="gpt-4o"))
if __name__ == "__main__":
import asyncio
asyncio.run(agent.as_mcp_server(transport="stdio").run())
Register it in claude_desktop_config.json:
{
"mcpServers": {
"research-assistant": {
"command": "python",
"args": ["/absolute/path/to/my_agent.py"]
}
}
}
Claude Desktop now treats your fastaiagent as a callable tool. Same config shape for Cursor / Continue / Zed. Or use the CLI: fastaiagent mcp serve my_agent.py:agent. See docs/tools/mcp-server.md.
Install: pip install 'fastaiagent[mcp-server]'.
Peer-to-peer swarms with handoffs
Beyond the central-coordinator Supervisor/Worker pattern, agents can hand off to each other directly:
from fastaiagent import Agent, LLMClient, Swarm
llm = LLMClient(provider="openai", model="gpt-4o-mini")
triage = Agent(name="triage", llm=llm, system_prompt="Hand off to the right specialist.")
coder = Agent(name="coder", llm=llm, system_prompt="Answer Python questions.")
writer = Agent(name="writer", llm=llm, system_prompt="Help with prose.")
swarm = Swarm(
name="help_desk",
agents=[triage, coder, writer],
entrypoint="triage",
handoffs={"triage": ["coder", "writer"], "coder": [], "writer": []},
)
result = swarm.run("How do I reverse a list in Python?")
The currently active agent decides when to transfer control — no central LLM. See docs/agents/swarm.md for the full guide, and Swarm vs Supervisor for when to pick which.
Long-term memory with composable blocks
Beyond a sliding window, layer static facts, a rolling summary, semantic recall, and fact extraction into one memory object:
from fastaiagent import Agent, LLMClient, ComposableMemory, AgentMemory
from fastaiagent import StaticBlock, SummaryBlock, VectorBlock, FactExtractionBlock
from fastaiagent.kb.backends.faiss import FaissVectorStore
llm = LLMClient(provider="openai", model="gpt-4o-mini")
agent = Agent(
name="assistant",
llm=llm,
memory=ComposableMemory(
blocks=[
StaticBlock("User is Upendra. Prefers terse answers."),
SummaryBlock(llm=llm, keep_last=10, summarize_every=5),
VectorBlock(store=FaissVectorStore(dimension=384)),
FactExtractionBlock(llm=llm, max_facts=100),
],
primary=AgentMemory(max_messages=20),
),
)
VectorBlock works with any VectorStore (Qdrant / Chroma / custom). Write your own block by subclassing MemoryBlock with two methods. See docs/agents/memory.md.
Swap the KB storage layer
Default LocalKB ships with FAISS + BM25 + SQLite — zero setup. Point at Qdrant, Chroma, or your own backend with one kwarg:
from fastaiagent.kb import LocalKB
from fastaiagent.kb.backends.qdrant import QdrantVectorStore
kb = LocalKB(
name="product-docs",
search_type="vector",
vector_store=QdrantVectorStore(
url="http://localhost:6333",
collection="product-docs",
dimension=1536,
),
)
kb.add("docs/")
results = kb.search("refund policy", top_k=5)
Adapters shipped: FAISS, BM25, SQLite (defaults), Qdrant (fastaiagent[qdrant]), Chroma (fastaiagent[chroma]). Write your own against the VectorStore / KeywordStore / MetadataStore protocols — see docs/knowledge-base/backends.md.
Shape agent behavior with middleware
Compose pre/post model hooks and tool wrappers without subclassing Agent:
from fastaiagent import Agent, LLMClient, TrimLongMessages, RedactPII, ToolBudget
agent = Agent(
name="controlled",
llm=LLMClient(provider="openai", model="gpt-4o"),
tools=[search_tool],
middleware=[
TrimLongMessages(keep_last=30), # cap history size
RedactPII(), # scrub emails/phones/SSNs both directions
ToolBudget(max_calls=5), # cooperatively stop after 5 tool calls
],
)
Write your own by subclassing AgentMiddleware and overriding before_model, after_model, or wrap_tool. See docs/agents/middleware.md for ordering, hook reference, and custom patterns.
Multi-agent teams with context
from fastaiagent import Agent, LLMClient, RunContext, Supervisor, Worker, tool
@tool(name="get_tickets")
def get_tickets(ctx: RunContext[AppState], status: str) -> str:
"""Get support tickets for the current user."""
return ctx.state.db.query("tickets", user_id=ctx.state.user_id, status=status)
support = Agent(name="support", llm=llm, tools=[get_tickets], system_prompt="Handle tickets.")
billing = Agent(name="billing", llm=llm, tools=[get_billing], system_prompt="Handle billing.")
supervisor = Supervisor(
name="customer-service",
llm=LLMClient(provider="openai", model="gpt-4o"),
workers=[
Worker(agent=support, role="support", description="Manages tickets"),
Worker(agent=billing, role="billing", description="Handles billing"),
],
system_prompt=lambda ctx: f"You lead support for {ctx.state.company}. Be helpful.",
)
# Context flows to all workers and their tools
ctx = RunContext(state=AppState(db=db, user_id="u-1", company="Acme"))
result = supervisor.run("Show my open tickets and billing", context=ctx)
# Stream the supervisor's response
async for event in supervisor.astream("Help me", context=ctx):
if isinstance(event, TextDelta):
print(event.text, end="")
Connect to FastAIAgent Platform (optional)
import fastaiagent as fa
fa.connect(api_key="fa-...", project="my-project")
# Traces automatically sent to platform dashboard
result = agent.run("Help me")
# Pull versioned prompts from platform
prompt = PromptRegistry().get("support-prompt")
# Publish eval results to platform
results = evaluate(agent, dataset=dataset)
results.publish()
SDK works standalone. Platform adds: production observability, prompt management, evaluation dashboards, team collaboration, HITL approval workflows.
Install
pip install fastaiagent
With optional integrations:
pip install "fastaiagent[openai]" # OpenAI auto-tracing
pip install "fastaiagent[langchain]" # LangChain auto-tracing
pip install "fastaiagent[kb]" # Local knowledge base
pip install "fastaiagent[all]" # Everything
Documentation
Contributing
We welcome contributions! See CONTRIBUTING.md for guidelines.
License
Apache 2.0 — see LICENSE.
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 fastaiagent-0.6.0.tar.gz.
File metadata
- Download URL: fastaiagent-0.6.0.tar.gz
- Upload date:
- Size: 400.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42f4120ec90ade57fe508263e086221496a630e5c244b396d9e43e3277ae310a
|
|
| MD5 |
719faad97c14b4cde96cfff1ab0931a8
|
|
| BLAKE2b-256 |
e8efe8fcf7bfa9d11a26d5c5f45431ff7d1fe3b4f8c35eab40930fb5f303c2a0
|
File details
Details for the file fastaiagent-0.6.0-py3-none-any.whl.
File metadata
- Download URL: fastaiagent-0.6.0-py3-none-any.whl
- Upload date:
- Size: 156.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4c4703934561cf24f3b3b3a2f96e4aef22902ef8c2aa075170c72bd7e0ecaa4
|
|
| MD5 |
9f32d6487cedd6b8ad37aa629b92a187
|
|
| BLAKE2b-256 |
75e1639881b595ebd0e89f1b134fe0b1f0455236b9df5e066ad83ad18437879e
|