Skip to main content

agentpools Python 客户端指南

基于底层 Rust 高性能调度内核的 Python 异步客户端。

专为需要在 Python / asyncio 环境下高效、稳定管理多个长连接 AI Agent(Codex、Pi、ACP)而设计,提供优雅的原生 async with 上下文管理。


1. 核心特性

  • 极致轻量高效:基于 PyO3 与 Rust 原生线程池,避开 Python GIL 锁限制,多 Worker 并发性能极佳。
  • 上下文管理器完美支持:使用 async with AgentPool(...) 与 async with await pool.acquire(),自动管理获取与安全归还,无句柄泄漏之忧。
  • 多运行时与统一 MCP:完全支持 API v2,可在同一个池中混合调度 Codex app-server、Pi RPC 和 ACP,并统一注入 MCP 工具。

2. 本地开发与构建

环境要求:Python 3.9+,Rust 稳定版,maturin。

# 进入目录并安装 maturin
cd bindings/python
pip install maturin

# 本地快速构建并安装到当前虚拟环境
maturin develop

# 运行自动化测试套件
python -m unittest discover -s test -p "test_*.py"

3. 典型使用示例

① 基础使用与上下文管理

import asyncio
import os
from agentpools import AgentPool

async def main():
    config = {
        "apiVersion": 2,
        "maxQueued": 16,
        "agents": [
            {
                "runtime": "codexAppServer",
                "program": "codex",
                "args": ["app-server"],
                "cwd": os.getcwd(),
                "mcpServers": [
                    {"name": "sqlite", "command": "uvx", "args": ["mcp-server-sqlite"]}
                ]
            }
        ]
    }

    # 1. 启动池
    async with AgentPool(config) as pool:
        # 2. 独占借出一个 Worker
        async with await pool.acquire() as lease:
            reply1 = await lease.ask("帮我写一个二分查找算法。")
            print("第一轮回复:", reply1["text"])

            # 在同一会话与上下文中追问
            reply2 = await lease.ask("请加上详细的注释和复杂度分析。")
            print("追问回复:", reply2["text"])
        # 离开 lease 上下文时,Worker 自动归还池中

asyncio.run(main())

② 多轮校验与循环修复(Code Review 模式)

async with await pool.acquire() as lease:
    res = await lease.ask("设计一个用户登录组件")
    while needs_fix(res["text"]):
        # 依然在原会话中根据反馈调整
        res = await lease.ask("密码校验规则不符合要求,请调整后重新输出。")

4. 详细文档指引

Metadata

Release files for agentpools 0.1.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agentpools 0.1.10
File Size Uploaded Provenance Actions
agentpools-0.1.10.tar.gz 133.3 kB With provenance Details for agentpools-0.1.10.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for agentpools 0.1.10
File Actions
agentpools-0.1.10-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for agentpools-0.1.10-cp39-abi3-win_amd64.whl
agentpools-0.1.10-cp39-abi3-manylinux_2_28_x86_64.whl CPython 3.9 abi3 Linux glibc 2.28+ x86-64 Details for agentpools-0.1.10-cp39-abi3-manylinux_2_28_x86_64.whl
agentpools-0.1.10-cp39-abi3-manylinux_2_28_aarch64.whl CPython 3.9 abi3 Linux glibc 2.28+ ARM64 Details for agentpools-0.1.10-cp39-abi3-manylinux_2_28_aarch64.whl
agentpools-0.1.10-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for agentpools-0.1.10-cp39-abi3-macosx_11_0_arm64.whl
agentpools-0.1.10-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for agentpools-0.1.10-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 3.6 MB

Release files / agentpools-0.1.10.tar.gz

Download URL agentpools-0.1.10.tar.gz
Size 133.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0be61001e8b91984bb6300f3585ed7d200ebe3ecdb3f8eb45bfab584612f3bd0
BLAKE2b-256 checksum
How to use checksums
2a50d69b46039ab631b9b47f0cc7de8cc28fa8f3a5049ca0459dda687ca0e669
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.

Transparency log

Release files / agentpools-0.1.10-cp39-abi3-win_amd64.whl

Download URL agentpools-0.1.10-cp39-abi3-win_amd64.whl
Size 577.3 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
83495e282c871cfb8d5d88babbd80ebbea386974d6b9568d6a57b6f9287c8750
BLAKE2b-256 checksum
How to use checksums
4941e7eeab2576111c30b401e7b18a7cef7a5070b9a1c3e953caac2d78f98298
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.

Transparency log

Release files / agentpools-0.1.10-cp39-abi3-manylinux_2_28_x86_64.whl

Download URL agentpools-0.1.10-cp39-abi3-manylinux_2_28_x86_64.whl
Size 758.1 kB
Tags CPython 3.9 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
c400c56f36b3bf4b1781836515af5505eae1297a3627bb500045097120b937ec
BLAKE2b-256 checksum
How to use checksums
8d40b72638ba90340074f0b44fc8b2fa905617b20ba0677b808ca21f36a48c30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.

Transparency log

Release files / agentpools-0.1.10-cp39-abi3-manylinux_2_28_aarch64.whl

Download URL agentpools-0.1.10-cp39-abi3-manylinux_2_28_aarch64.whl
Size 729.4 kB
Tags CPython 3.9 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
a289bbbaf8fb5dff68a0cef339de699d89c4ff6a4277f4247762a2b587f2b87c
BLAKE2b-256 checksum
How to use checksums
0d852e19609433efd77b88c1f87c9049cb6f10ea42a98b92adc3eb82db3c9a44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.

Transparency log

Release files / agentpools-0.1.10-cp39-abi3-macosx_11_0_arm64.whl

Download URL agentpools-0.1.10-cp39-abi3-macosx_11_0_arm64.whl
Size 667.9 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b7b4b2c59b7891becf440f679c2a16f2d9de21a1dc6c3ec8a29263cf1805cf78
BLAKE2b-256 checksum
How to use checksums
dcc22569f3a12e34ffa6efa441a654b270b0c406b169fd4abdbc2793efea98dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.

Transparency log

Release files / agentpools-0.1.10-cp39-abi3-macosx_10_12_x86_64.whl

Download URL agentpools-0.1.10-cp39-abi3-macosx_10_12_x86_64.whl
Size 695.1 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
f432c3f2357641216dcb36a01ce16a84be019a169420725ea19210bfed44d649
BLAKE2b-256 checksum
How to use checksums
fda60966ef35efc0a67efe49d80c22f9338f3030d219614a8ee92306d757fb7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.

Transparency log

Security for agentpools 0.1.10

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for agentpools-0.1.10.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.10 This release

6 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page