Skip to content

开发者文档

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

面向贡献者与需要改库内部的人。使用者请从 文档首页快速开始 看起。

仓库结构

text
src/pagent/     v1 库
src/pagentv4/   v4 库(core、runtime、sandbox、skills)
src/app/        应用层(REPL 等,基于 pagentv4)
examples/       按分类放置的可运行示例(v4 见 examples/pagentv4/)
tests/          pytest
docs/           文档

核心模块:agent.py(循环)、session.py(对话与滑动窗口/压缩)、llm.py(Provider)、tool.pytokens.pyevents.py

能力清单

模块说明
SessionAPI 形状消息;SlidingWindowSession(按 token 裁剪);CompactingSession(LLM 压缩)
LLMinvoke / invoke_streamRunEnd 为单次模型结果
Agentrun / arun / arun_events
tokenscount_tokenscount_tokens_detailformat_context
eventsRunBeginTextDeltaStepEndRunEnd 等 — 见 事件流

刻意不实现

  • 并行工具、RAG、MCP、内置文件/Shell、多模态、检查点等 — 见历史 README 讨论;需在业务层自建。
  • run() 非流式;流式用 arun() / arun_events()

与 LangChain / Claude Code

pagentLangChainClaude Code
定位可嵌入小库大框架终端/IDE 产品
工具自写 Python集成生态内置为主
适合实验、要透明循环要全家桶集成日常写代码

本地开发

开发环境推荐 uv;不了解 uv 请看 官方文档

bash
cd pagent
uv sync --group dev --extra search
pip install -e ".[search]"
uv run pre-commit install
uv run pytest -q

文档站

使用 VitePress,配置在 docs/.vitepress/config.mts,正文在 docs/

bash
cd docs
npm install
npm run dev            # http://localhost:5173/pagent/
npm run build          # 输出到 docs/.vitepress/dist/

Node 依赖放在 docs/package.jsonpackage-lock.json),仓库根目录保持纯 Python。

不要docs/.vitepress/dist/site/ 提交进仓库(已在 .gitignore);main 上只保留 docs/ 里的 Markdown 源文件。

推送到 main 后,docs.yml 会在 docs/ 下执行 npm run build,把 docs/.vitepress/dist/ 发布到 gh-pages 分支。在仓库 Settings → Pages 中选择 Deploy from branch → gh-pages / root

发布

.github/workflows/publish.yml 在 GitHub Release 发布时推 PyPI;配置 Trusted Publishing(OIDC):https://docs.pypi.org/trusted-publishers/

更多设计说明

Released under the MIT License.