Skip to main content

common-agent

企业级智能体基础框架:AgentScope 官方平台之上的配置化交付层。

业务团队引入开发包、编写一份配置文件与自己的业务工具函数,即可在半天内给自己的系统加上智能体能力,无需理解大模型编排、会话管理、事件推送、渠道接入等底层机制。

完整的目的、背景、定位辨析、演进路线与架构设计见 docs/specs/2026-12-01-framework-design.md。

安装

uv tool install common-agent          # 全局 CLI:common-agent init / validate / run

或作为库引入业务项目:

uv pip install common-agent

开发模式(本仓库内贡献时使用):

uv venv .venv && uv pip install --python .venv/bin/python -e ".[dev]"

要求 Python 3.11+;依赖 agentscope==2.0.12(锁定版本,升级走调研回归流程)。

最小接入三样东西

东西 说明
application.yml 唯一声明面:存储、总线、工作区、安全基线与智能体清单
tools/*.py 业务工具函数:函数名 + docstring + 类型注解即完整契约
skills/ 智能体技能目录(MVP 已声明字段,装配透传留给后续版本)

application.yml 示例

仓库根的 application.yml 即最小示例:

name: customer-service
owner_user_id: system
storage: {type: sqlite, url: "sqlite+aiosqlite:///./data/agents.db"}
message_bus: {type: in-memory}
workspace: {backend: local, basedir: ./workspaces, ttl: 3600}
channels: []
security: {auth: none}
agents:
  assistant:
    model: {provider: dashscope, name: qwen-max, api_key_ref: DASHSCOPE_API_KEY}
    system_prompt: |
      你是售后客服助手,负责查询订单与创建工单。
    permission_mode: DEFAULT
    tools: [tools/*]

要点:

  • 密钥一律 ${VAR} 环境变量引用,缺失时启动 fail-fast 并列出全部问题;
  • owner_user_id 名下的智能体与凭据自动种子写入 storage,确定性 id 保证重复启动幂等更新;
  • channels 是飞书/钉钉/Discord 渠道白名单,留空不影响内置 HTTP API。

CLI:init 脚手架

common-agent init my-project          # 当前目录生成 my-project/
common-agent init my-project --dir /some/where

生成以 test-project 为蓝本的完整项目(业务 API + 工具样例 + Vue 对话页 + 冒烟测试), 编辑 .env 填入 API_KEY 后即可 common-agent run --config application.yml。 目标目录已存在时报错退出,不覆盖任何文件。

CLI:validate 与 run

# 静态校验:不起进程不调外部服务,输出基线警告、错误清单与工具数量
common-agent validate --config application.yml

# 起服务:基线检查通过后以 uvicorn 启动,默认 127.0.0.1:8000
export DASHSCOPE_API_KEY=sk-xxx
common-agent run --config application.yml

Tool 契约

一个业务函数就是一座工具桥,无需写任何注册代码:

业务侧 工具侧
函数名 query_order 工具名 query_order
docstring(含 Args 段) 工具描述与参数说明
参数类型注解 order_id: str 输入 schema 类型
返回值(建议 JSON 字符串) 回传模型的结果文本
def query_order(order_id: str) -> str:
    """按订单号查询订单状态。

    Args:
        order_id: 订单号,形如 SO-2026-0001。
    """
    return json.dumps({"order_id": order_id, "status": "shipped"}, ensure_ascii=False)

约束:所有参数必须带类型注解,缺失时校验显式报错;下划线开头函数不注册;复杂嵌套 schema 请显式声明 Pydantic 模型。

内置 SOP 工具组

common-agent 在 Toolkit 装配阶段通过通用 tool_groups 扩展点,把 AgentScope 官方 SOP service 能力包装成 sop_tools 工具组注入每个 assistant。 模型可先调用 reset_tools(sop_tools=true) 激活,再使用以下工具:

  • 查询:list_sops / get_sop / list_sop_runs / get_sop_run
  • 管理:create_sop / update_sop / delete_sop
  • 运行:start_sop_run / delete_sop_run / submit_sop_verdict

查询类工具使用 is_read_only=true。管理、启动、删除和审批类工具显式交还权限引擎(PASSTHROUGH), 由 PermissionContext 规则与 permission_mode 裁决;未声明规则时,DEFAULT 下兜底询问, DONT_ASK / EXPLORE 下拒绝,BYPASS 下放行。可通过 tool_permissions 显式声明:

tool_permissions:
  create_sop: ask
  delete_sop: deny
  start_sop_run: allow

调用闭环

服务启动后按官方端点调用(身份经鉴权中间件统一注入 X-User-ID):

# 建会话(agent_id 来自 GET /agent/,credential_id 来自 GET /credential/)
curl -X POST http://127.0.0.1:8000/sessions/ \
  -H "Content-Type: application/json" \
  -d '{"agent_id": "...", "chat_model_config": {"type": "dashscope_chat", "credential_id": "...", "model": "qwen-max", "parameters": {}}}'

# 触发对话(fire-and-forget,返回 queued;input 必须是完整 Msg 对象)
curl -X POST http://127.0.0.1:8000/chat/ \
  -H "Content-Type: application/json" \
  -d '{"agent_id": "...", "session_id": "...", "input": {"name": "customer", "role": "user", "content": [{"type": "text", "text": "在吗"}]}}'

# 订阅事件流(SSE)/ 回读会话历史(分页)
curl "http://127.0.0.1:8000/sessions/{session_id}/stream?agent_id=..."
curl "http://127.0.0.1:8000/sessions/{session_id}/messages?agent_id=..."

注意:input 是官方 Msg 模型,name/role 必填且 content 是块列表,直接传纯字符串会被 422 拒绝。

开放 API:可插拔组件,接入方自由消费

mount 之后,官方平台全部端点在 /agents/* 前缀下自动暴露:模型凭据 CRUD(含厂商 schema 与内置模型清单)、会话与对话(HTTP + SSE 事件流)、智能体、渠道、工作区等。common-agent 只提供后端能力与数据面,不绑定前端形态——业务方可做管理页、走自家后台、或纯脚本调用。

完整端点清单、身份隔离规则与三种接入模式见 docs/guides/open-api.md。

嵌入接入方 FastAPI

Starlette Mount 不向子应用转发 lifespan scope,直接 mount 会得到连接池从未打开的死服务(已实测对照)。因此嵌入模式必须做 lifespan 组合:

from contextlib import asynccontextmanager
from fastapi import FastAPI

from common_agent.app import AgentRuntime, build_agent_app
from common_agent.config.loader import load_config

runtime = AgentRuntime(load_config("application.yml"))

@asynccontextmanager
async def lifespan(app):
    async with runtime:  # 官方组件连接池在此打开/关闭,并完成种子写入
        yield

main_app = FastAPI(lifespan=lifespan)
main_app.mount("/agents", build_agent_app(runtime.config, runtime.components))

docker-compose 示例(独立部署形态)

services:
  agent:
    image: python:3.12-slim
    working_dir: /app
    command: sh -c "pip install common-agent && common-agent run --config application.yml"
    environment:
      DASHSCOPE_API_KEY: ${DASHSCOPE_API_KEY}
    volumes:
      - ./application.yml:/app/application.yml
      - ./tools:/app/tools
      - ./data:/app/data
    ports:
      - "8000:8000"

已知边界

  • 多副本部署必须显式设置 security.download_secret:未设置时当前为启动警告,负载均衡后工作区文件下载会随机失败;
  • 多进程/多副本部署必须 Redis 消息总线:in-memory 仅限单机开发(锁与回放依赖共享总线);
  • 复杂业务流程(受理查重、检查点、回执核验等)属平台 BusinessAdapter 领域,common-agent 不重复建设,请对接平台能力;
  • 多副本需 download_secret、渠道 HITL 审批部门化 UI 等边界同设计文档 3.6/3.6a。

Metadata

Release files for common-agent 0.1.2

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

Source distribution (sdist)

Source distribution for common-agent 0.1.2
File Size Uploaded Provenance Actions
common_agent-0.1.2.tar.gz 496.1 kB Without provenance Details for common_agent-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for common-agent 0.1.2
File Interpreter ABI Platform Actions
common_agent-0.1.2-py3-none-any.whl Python 3 none any Details for common_agent-0.1.2-py3-none-any.whl

Total release size: 699.8 kB

Release files / common_agent-0.1.2.tar.gz

Download URL common_agent-0.1.2.tar.gz
Size 496.1 kB
Tags Source
SHA-256 checksum
How to use checksums
206524342b2e5d95f2488030798c7520816d6f2c1d3bff72518d6e534a78b092
BLAKE2b-256 checksum
How to use checksums
91a9a689f0507dcdc2db614df9153e3636b57466b59bcb9d3d049c497ecc75b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / common_agent-0.1.2-py3-none-any.whl

Download URL common_agent-0.1.2-py3-none-any.whl
Size 203.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
141259d2292857303da48e1b1f9b5eef51a2c3760f77d60f85809e1515c215e8
BLAKE2b-256 checksum
How to use checksums
7fa68315aa8eee72550598b4d9757ab0a7d7be89960eda74d9a33159240c9c5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for common-agent 0.1.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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