Skip to main content

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.

PyPI License: MIT

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

MIT

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

ahzan_agentforge-0.1.1.tar.gz (54.6 kB view details)

Uploaded Source

Built Distribution

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

ahzan_agentforge-0.1.1-py3-none-any.whl (57.2 kB view details)

Uploaded Python 3

File details

Details for the file ahzan_agentforge-0.1.1.tar.gz.

File metadata

  • Download URL: ahzan_agentforge-0.1.1.tar.gz
  • Upload date:
  • Size: 54.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for ahzan_agentforge-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f53b40a9344a5dea76477e8fc57a32791706c526b0bad57a8e6ff21e42966532
MD5 b0d1e3da27076ee477e990ef41f04a2e
BLAKE2b-256 7f8566e3016855acb114aa405610cce6325ad71ab77468b3c4717e62ea456c75

See more details on using hashes here.

File details

Details for the file ahzan_agentforge-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ahzan_agentforge-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a84ab78fc1bd9a84b4587ca3def81c0943400067a82e2f128bd3df83c543bbec
MD5 35fae15d16890eca210cc2e3091f7b67
BLAKE2b-256 e2ee7ae3e712ba85b1befbf18b56339bef77af89e2446cf0f686936d5e5e64d7

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