Skip to content

Quick start

Language: 中文 | 日本語 | 四川话 | English

Prerequisites: Install (Python 3.11+, pip / uv / conda).

Minimal agent

python
import asyncio
import os

from pagent import Agent, LLM, 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())

run() returns RunEnd — use .content for the answer.

Streaming APIs

APIReturnsUse when
agent.run()RunEndNo streaming
agent.arun()str chunksTyping effect, text only
agent.arun_events()Event objectsPython UI, tests
agent.arun_wire()NDJSON linesBrowser, VS Code plugin, any JSON consumer

Next: Providers & API keys · Events · Wire protocol

Examples (clone repo)

bash
git clone https://github.com/SyncLionPaw/pagent.git
cd pagent
export DEEPSEEK_API_KEY="your-key"   # for DeepSeek examples

uv run pagent
uv run python -m examples.pagentv4.thread_based.conversation_only
uv run python -m examples.pagentv4.thread_based.code_runner
uv run --with fastapi --with uvicorn python examples/wire_browser/server.py
ExampleDescription
examples/README.mdClassified examples index
examples/pagentv4/thread_basedChatRunner / CodeRunner examples
examples/pagentv4/runnerRunner.create examples
wire_browserFastAPI + browser UI

Released under the MIT License.