Skip to content

クイックスタート

言語: 日本語 | English | 简体中文 | 四川话

前提: インストール(Python 3.11+、pip / uv / conda)。

最小の 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("OPENAI_API_KEY を設定してください。")

    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()RunEnd を返します。回答は .content を使います。

ストリーミング API

API戻り値用途
agent.run()RunEndストリーム不要
agent.arun()str チャンクテキストのみのタイプ表示
agent.arun_events()Event オブジェクトPython UI、テスト
agent.arun_wire()NDJSON 行ブラウザ、VS Code 拡張など

次へ: プロバイダと API Key · イベント · Wire プロトコル

サンプル(リポジトリの clone が必要)

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

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
サンプル説明
examples/README.md分類済みサンプル索引
examples/pagentv4/thread_basedChatRunner / CodeRunner examples
examples/pagentv4/runnerRunner.create examples
wire_browserFastAPI + ブラウザ UI

Released under the MIT License.