Skip to main content

Wuwei

一个面向工具调用、多轮会话与可恢复审批的 Python Agent 框架。

Wuwei 将普通运行、流式事件、结构化输出和委派接入同一执行生命周期。工具、权限、预算、审批和检查点可组合;应用仍需为真实副作用提供幂等或对账机制。

安装

需要 Python 3.11 或更高版本。

pip install wuwei
pip install 'wuwei[anthropic,mcp]'  # 按需接入 Claude 与 MCP

图、中间件、内存存储和本地执行驱动随核心提供。graph、middleware、memory、sandbox 是保留的兼容 extra 名,不代表额外依赖。all 安装所有可选 Python 扩展;Docker、数据库服务和供应商账号仍需自行配置。

开始一次对话

设置 OPENAI_API_KEY,然后运行:

import asyncio
from wuwei import Agent, LLMGateway, ToolRegistry

registry = ToolRegistry()

@registry.tool()
def greet(name: str) -> str:
    """按姓名生成问候。"""
    return f"你好,{name}"

async def main():
    async with LLMGateway.from_env(provider="openai") as llm:
        agent = Agent(llm=llm, tools=registry, load_builtins="minimal")
        session = agent.create_session()
        result = await agent.run("向小明问好", session=session)
        print(result.status, result.content)
        async for event in agent.stream_events("改成更简短的问候", session=session):
            if event.type == "text_delta":
                print(event.data.get("content", ""), end="", flush=True)

asyncio.run(main())

minimal 只加载 calc/time/json/text。文件、网络、Git、npm 和脚本执行需按名选择;load_builtins="all" 会扩大可用能力,不应作为生产默认值。权限中间件、人工审批与 OS 沙箱是不同边界。

能力地图

需求 入口 使用要点
模型接入 LLMGateway OpenAI Chat Completions、Responses、Anthropic;兼容端点用 base_url;client/factory 可注入
会话与事件 Agent、AgentSession run/stream 共享显式或默认会话;同会话并发需遵循执行锁
工具 ToolRegistry、ToolExecutor 类型 schema、执行前参数验证、并发分组、超时与副作用状态
审批与恢复 HitlMiddleware、checkpointer、Agent.resume 持久完整批次;重复恢复不能重复领取;结果 unknown 需对账
结构化输出 Agent.run_structured 返回 (typed_output, AgentRunResult);挂起时 output 为 None
任务规划 Planner、PlanExecutor DAG 验证、拓扑调度、PlanExecutor.resume;保留非完成状态
多 Agent SubAgent、AsyncSubAgent、MultiAgentGraph 继承治理与统计;后台句柄在进程内,子检查点可持久化
图编排 StateGraph、reducers、END invoke/stream 共用状态归并;Memory/SQLite 检查点
权限与预算 Permission/Budget middleware 本地能力授权、路径边界、跨步骤配额与累计预算
上下文 Context、压缩、Ledger、Memory、RAG 摘要不替代原文;持久账本支持召回与 pin
存储与检索 FileStorage、CuratedMemoryStore、vectorstore 内存后端与 Chroma/Qdrant/pgvector/Milvus 可选后端
插件与技能 PluginManager、SkillManager setup 注册工具/中间件;文件系统技能与 allowed-tools
文件与代码 LocalFS/InMemoryFS、sandbox、Code Mode Code Mode 是可信进程内 Python,不是沙箱;sandbox(Docker/E2B 驱动)为实验性模块,未接入默认工具执行链
协议 MCP、A2A、AG-UI MCP stdio/HTTP/旧 SSE;A2A 0.3 message/send;AG-UI SSE/NDJSON
集成 gateway、DecisionClient 飞书/钉钉/Telegram/微信/Webhook 适配与决策模型客户端
运维与评估 EventBus、ActionLog、evals、debug 事件、动作记录、评估 CLI;fork 默认模拟副作用
配置与解析 YAML、output parsers、Runnable 配置错误启动失败;JSON/Pydantic 输出解析与管道组合

内置插件

基础插件:calc、time、json、text。按需插件:file、git、npm、python、http、decision、skill、rag、mcp、vfs。实际工具名与参数以 agent.tool_registry.list_tools() / tool.to_schema() 为准,避免把插件名当工具名。

结果不是只有成功或异常

检查 result.status:completed、interrupted、incomplete、unknown、error、cancelled。达到步数上限是 incomplete;动作可能已经发生却没有确定结果时是 unknown。两者不能作为成功交给下游,也不能盲目重试。

文档与测试

pytest                 # 默认离线测试
pytest --live          # 显式启用在线测试;需要对应账号、密钥与服务
pytest tests/test_documentation_hardening.py -q

离线通过证明本地契约,不代表所有供应商、远程 MCP、设备或部署环境已经互操作验收。

许可证

Apache-2.0。

Metadata

Release files for wuwei 3.4.1

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

Source distribution (sdist)

Source distribution for wuwei 3.4.1
File Size Uploaded Provenance Actions
wuwei-3.4.1.tar.gz 404.1 kB With provenance Details for wuwei-3.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wuwei 3.4.1
File Interpreter ABI Platform Actions
wuwei-3.4.1-py3-none-any.whl Python 3 none any Details for wuwei-3.4.1-py3-none-any.whl

Total release size: 710.7 kB

Release files / wuwei-3.4.1.tar.gz

Download URL wuwei-3.4.1.tar.gz
Size 404.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e5d39128e15d9a003e600b564f0338430a572b45c2e63de5504ffc64a6fffdbe
BLAKE2b-256 checksum
How to use checksums
f7749bcb61579c0d48b71219118f46c8541416e16f1c03265f1fa3f187594066
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 11, 2026.

Transparency log

Release files / wuwei-3.4.1-py3-none-any.whl

Download URL wuwei-3.4.1-py3-none-any.whl
Size 306.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
934e34c0114b792d881a3c9d0476292e49bbcfece72d119b8458fc5b5c2559c3
BLAKE2b-256 checksum
How to use checksums
38b16f04a88a9738eaf0e3295343ed4807df5d3383dcd981ae3aca12e40d484b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 11, 2026.

Transparency log

Security for wuwei 3.4.1

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for wuwei-3.4.1.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 Nov 11, 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

3.4.1 This release

2 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