Skip to content

pagent你的轻量 Agent 框架

小库 · 全透明 · 你说了算

pagent

同一模型,更好的 harness

JobBench 上,pagentv4 的 inplace harness 在两个 split 上都胜过官方 OpenCode harness——同选手(deepseek-v4-flash)、同裁判,只换 harness。

OpenCode 与 pagentv4 在 JobBench 上的对比——pagentv4 的 micro 分在 Easy 上领先 +4.5,Main 上领先 +1.6JobBench Main split 排行榜——deepseek-v4-flash 在 pagentv4 下 38.2,落在 GPT-5.5 与 Claude Sonnet 4.6 之间

查看完整评测 →

想试试这条 harness? 同一套 pagentv4 内核,挑你顺手的入口:

终端 CLI(uv run pagent)→ · 桌面端 → · VS Code 插件 → · Web UI →

二十多行,就是一个 Agent

选一个模型标签,设置对应 API Key,保存为 demo.py,运行 python demo.py。模型会按需调用 @tool,答案在 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=24,
    )

    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=24,
    )

    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=24,
    )

    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=24,
    )

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


asyncio.run(main())

示例输出:Sunny in Xiamen today.(以模型实际返回为准)。更多见 模型与 API Key

安装 → · 快速开始 →

想用 pagentv4?

仓库还提供较新的类型化 API,围绕 ProviderMessageRunner, 以及可选的 sandbox 执行环境。

pagentv4 概览 → · pagentv4 快速开始 →

Released under the MIT License.