AgentForge

Python Differences

Key differences between the TypeScript and Python implementations.

Async/Await

Python uses asyncio for async operations:

import asyncio

async def main():
    result = await agent.run(task="Do something")
    print(result.output)

asyncio.run(main())

Streaming

Python uses async for instead of for await:

async for event in agent.stream(task="Do something"):
    if event.type == "llm_token":
        print(event.token, end="")

Schema Validation

Python uses Pydantic instead of Zod:

from pydantic import BaseModel, Field

class MyInput(BaseModel):
    query: str = Field(description="Search query")
    limit: int = Field(default=10, ge=1, le=100)

Dict Config

Python accepts both dict and dataclass configs:

# Dict style
agent = define_agent(
    name="my-agent",
    tools=[my_tool],
    llm=llm,
    system_prompt="...",
    description="...",
    budget={"max_cost_usd": 1.0},
)

Testing Tools

# pytest
import pytest

@pytest.mark.asyncio
async def test_agent():
    mock = create_mock_llm(responses=[{"text": "Hello"}])
    harness = create_test_harness(agent=config, llm=mock)
    result = await harness.run(task="Greet")
    assert result.status == "completed"

Development Tools

# Linting
ruff check .

# Type checking
mypy .

# Testing
pytest

Next Steps