Skip to content

pagent丁丁儿 智能体 架架儿,你国人捏拢

么得花架子 · 眯起眼睛都看的清白 · 随在你整嘛

pagent

二十几行就整一个 Agent

点一个模型标签,钥匙设好,存成 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=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())

示例输出:Sunny in Xiamen today.(示例哈,实际看模型咋个回喃)。模型跟 Key

安装 → · 赶紧上手 →

协作向四川话(文档里会冒)

搞起/架势 开干 · 过一道 检查 · 归一 搞定 · 经佑/看到起 照看模块 · 落教/稳当 办得牢靠 · 攒劲 继续冲

Released under the MIT License.