Skip to content

pagentYour minimal agent framework

Small · transparent · you extend it

pagent

A full agent in ~25 lines

Pick a provider tab, set the API key, save as demo.py, run python demo.py. The model can call your @tool and you read the answer from result.content.

python
import asyncio
import os

from pagent import LLM, Agent, Session, tool


@tool()
def get_weather(city: str) -> str:
    """Return weather for the city."""
    return f"Sunny in {city} today."


async def main():
    if not os.getenv("OPENAI_API_KEY"):
        raise SystemExit("Set OPENAI_API_KEY first.")

    agent = Agent(
        llm=LLM("gpt-4o-mini"),
        session=Session("You are helpful. Use tools when needed."),
        tools=[get_weather],
        max_turns=8,
    )

    result = await agent.run("What's the weather in Xiamen?")
    print(result.content)


asyncio.run(main())
python
import asyncio
import os

from pagent import Agent, DeepSeek, Session, tool


@tool()
def get_weather(city: str) -> str:
    """Return weather for the city."""
    return f"Sunny in {city} today."


async def main():
    if not os.getenv("DEEPSEEK_API_KEY"):
        raise SystemExit("Set DEEPSEEK_API_KEY first.")

    agent = Agent(
        llm=DeepSeek("deepseek-chat"),
        session=Session("You are helpful. Use tools when needed."),
        tools=[get_weather],
        max_turns=8,
    )

    result = await agent.run("What's the weather in Xiamen?")
    print(result.content)


asyncio.run(main())
python
import asyncio
import os

from pagent import LLM, Agent, Session, tool


@tool()
def get_weather(city: str) -> str:
    """Return weather for the city."""
    return f"Sunny in {city} today."


async def main():
    if not os.getenv("ANTHROPIC_API_KEY"):
        raise SystemExit("Set ANTHROPIC_API_KEY first.")

    agent = Agent(
        llm=LLM(
            "claude-sonnet-4-20250514",
            base_url="https://api.anthropic.com/v1",
            apikey=os.getenv("ANTHROPIC_API_KEY"),
        ),
        session=Session("You are helpful. Use tools when needed."),
        tools=[get_weather],
        max_turns=8,
    )

    result = await agent.run("What's the weather in Xiamen?")
    print(result.content)


asyncio.run(main())
python
import asyncio
import os

from pagent import LLM, Agent, Session, tool


@tool()
def get_weather(city: str) -> str:
    """Return weather for the city."""
    return f"Sunny in {city} today."


async def main():
    if not os.getenv("MOONSHOT_API_KEY"):
        raise SystemExit("Set MOONSHOT_API_KEY first.")

    agent = Agent(
        llm=LLM(
            "kimi-k2.5",
            base_url="https://api.moonshot.cn/v1",
            apikey=os.getenv("MOONSHOT_API_KEY"),
        ),
        session=Session("You are helpful. Use tools when needed."),
        tools=[get_weather],
        max_turns=8,
    )

    result = await agent.run("What's the weather in Xiamen?")
    print(result.content)


asyncio.run(main())

Example output: Sunny in Xiamen today. (actual text depends on the model). More providers: Providers & API keys.

Install → · Quick start →

Looking for pagentv4?

The repo also contains a newer typed API built around Provider, Message, Runner, and optional sandbox execution.

pagentv4 overview → · pagentv4 quick start →

Released under the MIT License.