Production-grade AI agent framework — the Next.js for AI agents
Project description
ahzan-agentforge
Production-grade AI agent framework — the Next.js for AI agents. Python SDK.
AgentForge owns the agent loop — LLM calls, tool execution, state checkpointing, crash recovery, cost governance, rollback, and full run tracing. You write tools and prompts. Everything else is handled.
Also available as a TypeScript package:
@ahzan-agentforge/core
Install
pip install ahzan-agentforge
With LLM providers:
pip install ahzan-agentforge[anthropic] # Anthropic Claude
pip install ahzan-agentforge[openai] # OpenAI GPT
pip install ahzan-agentforge[all] # All providers + Redis
Quick Start
import asyncio
from agentforge import define_agent, define_tool, create_llm
from pydantic import BaseModel
class OrderInput(BaseModel):
order_id: str
class OrderOutput(BaseModel):
id: str
status: str
total: float
get_order = define_tool(
name="get_order",
description="Fetch order details by ID",
input_schema=OrderInput,
output_schema=OrderOutput,
execute=lambda inp: OrderOutput(id=inp.order_id, status="shipped", total=49.99),
)
agent = define_agent(
name="support-agent",
tools=[get_order],
llm=create_llm(provider="openai", model="gpt-4o"),
max_steps=15,
system_prompt="You are a customer support agent. Look up orders and help customers.",
)
async def main():
result = await agent.run(task="Order #4521 arrived damaged")
print(result.status) # 'completed'
print(result.output)
asyncio.run(main())
Features
- Execution engine with checkpointing and crash recovery
- Pydantic schema validation on tool inputs and outputs
- LLM providers: Anthropic Claude, OpenAI GPT, Ollama (local)
- Token-level streaming via
agent.stream() - State stores: in-memory (dev) and Redis (production)
- Long-term memory: in-memory and PgVector with embedding retrieval
- Budget governor with token/cost limits and model pricing
- Autonomy policy with per-tool allow/deny/escalate rules
- Rollback with compensating actions
- Multi-agent coordination: pipeline, parallel, supervisor, debate patterns
- OpenTelemetry observability — every decision traced
- MockLLM and TestHarness for testing without API calls
LLM Providers
from agentforge import create_llm
llm = create_llm(provider="anthropic", model="claude-sonnet-4-20250514")
llm = create_llm(provider="openai", model="gpt-4o")
llm = create_llm(provider="ollama", model="llama3.1") # local, zero cost
Streaming
async for event in agent.stream(task="Help customer"):
if event.type == "llm_token":
print(event.content, end="", flush=True)
elif event.type == "tool_start":
print(f"\nCalling {event.tool_name}...")
elif event.type == "done":
print(f"\nResult: {event.result.output}")
Multi-Agent Coordination
from agentforge import pipeline, parallel, supervisor, debate
result = await pipeline([researcher, writer, editor], task="Write a report")
result = await supervisor(manager, {"researcher": researcher, "writer": writer}, task="Complete project")
result = await parallel([agent1, agent2], task="Analyze data", merge_fn=merge_results)
result = await debate([optimist, pessimist], task="Evaluate proposal", judge=judge)
Testing
from agentforge import create_mock_llm, create_test_harness
harness = create_test_harness(
agent=my_agent_config,
llm=create_mock_llm(responses=[
{"tool_calls": [{"name": "get_order", "input": {"order_id": "4521"}}]},
{"text": "Order found and ticket created."},
]),
)
result = await harness.run(task="Handle order issue")
assert result.status == "completed"
assert len(result.tool_calls("get_order")) == 1
API Parity with TypeScript
| TypeScript | Python |
|---|---|
defineAgent() |
define_agent() |
defineTool() |
define_tool() |
createLLM() |
create_llm() |
createMockLLM() |
create_mock_llm() |
createTestHarness() |
create_test_harness() |
agent.run() |
agent.run() |
agent.stream() |
agent.stream() |
| Zod schemas | Pydantic models |
camelCase |
snake_case |
Requirements
- Python >= 3.10
- Redis (optional, for persistent state)
- PostgreSQL + pgvector (optional, for long-term memory)
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 ahzan_agentforge-0.1.0.tar.gz.
File metadata
- Download URL: ahzan_agentforge-0.1.0.tar.gz
- Upload date:
- Size: 54.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7f5cc40a04ef233c0ba94d9dacb6205a657ed72ae9a1f6c018057f4d676bd7f
|
|
| MD5 |
923db388f4e35e4d913c1318ad41cb58
|
|
| BLAKE2b-256 |
7bed16d35158f37e14590b3b94751639edd5c918c2df8f340f6078788921cff2
|
File details
Details for the file ahzan_agentforge-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ahzan_agentforge-0.1.0-py3-none-any.whl
- Upload date:
- Size: 57.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d16531a55a3a533d50502075711dbe2413c0d1044fac338b95d97d57111023c
|
|
| MD5 |
56cc0496624ffa8d392a546ff32affbb
|
|
| BLAKE2b-256 |
03ed129c04869bb73bde3f48fa67c274090c231b2816bbec8327bdb6d532d410
|