Skip to main content

AgentCore Collaboration for Python

为 AgentCore Agent 添加 Worker 任务协作能力,包括任务执行、进度反馈和成果提交。

这是基础 SDK 的可选扩展包,可以独立安装和升级。

安装

公开发行版的安装方式(可用版本以正式发布为准):

pip install "alibabacloud-agentcore-sdk[collaboration]"

协作包 0.1.x 适用于基础 SDK >=0.1.0,<0.2.0。

本页使用 LangChain,完整服务示例还需要 Server 支持。请额外安装:

pip install "alibabacloud-agentcore-sdk[langchain,server]"

使用其他框架时,按需选择对应的 框架 extra。

使用

先在 AgentCore 中为 Agent 配置团队和 Worker 角色,再将协作指令、工具及 Skill 加入 Agent:

from agentcore import AsyncAgentCore
from agentcore.integrations.langchain import skill_tools, tools

core = AsyncAgentCore.auto()
worker = core.collaboration.worker()

instructions = worker.compose_prompt("完成分配的业务任务。")
agent_tools = [*tools(worker.tools()), *skill_tools(worker.skills())]
# 将 instructions 和 agent_tools 传给 LangChain Agent。
# 应用退出时 await core.aclose()。

完整示例见 LangChain 协作服务。其他框架可使用各自的工具适配器。

建议通过 AgentCoreServer 接收协作任务;自建服务器需要在完整的 Agent 执行范围内使用 worker.request_context(headers),并确保请求来自受信任的调用方。

使用自己的 Server

不使用 AgentCoreServer 时,也可以将协作工具接入已有应用。沿用上面的 core、worker、instructions 和 agent_tools,构建一次 Agent:

from langchain.agents import create_agent
from agentcore.integrations.langchain import model

agent = create_agent(
    model=model("test-mc", model_name="qwen3.8-max"),
    system_prompt=instructions,
    tools=agent_tools,
)

在现有 Server 的请求处理函数中,将请求头和解析后的消息传入以下接入函数。普通调用:

async def invoke_agent(headers, messages):
    with worker.request_context(headers):
        return await agent.ainvoke({"messages": messages})

流式调用:

async def stream_agent(headers, messages):
    # 绑定发生在生成器内部,覆盖完整迭代和工具执行。
    with worker.request_context(headers):
        async for update in agent.astream(
            {"messages": messages}, stream_mode="updates"
        ):
            yield update

这些函数返回 LangChain 的结果或更新,不是 AG-UI / OpenAI 协议响应。自建 Server 负责解析请求、按平台配置的协议编码响应,并在客户端断开时取消执行、关闭生成器。不要只在 Context 内创建生成器、退出 Context 后再消费它。

请求入口应先完成鉴权,并从可信平台入口接收 X-AgentCore-Collaboration-Context 和 X-AgentCore-Session-ID,不能直接信任任意客户端提供的协作 Header。worker.request_context() 只绑定协作上下文,不代替入口鉴权,也不绑定 SDK 的普通请求 Context。

应用退出时调用 await core.aclose()。这些接入函数不需要 server extra;安装协作和 LangChain extra,以及应用自己使用的 Web 框架即可。

升级

pip install -U alibabacloud-agentcore-collaboration

保持基础 SDK 版本兼容,升级后重启应用即可使用新的协作能力。镜像部署时请重新构建镜像。

Metadata

Release files for alibabacloud-agentcore-collaboration 0.1.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 alibabacloud-agentcore-collaboration 0.1.1
File Size Uploaded Provenance
alibabacloud_agentcore_collaboration-0.1.1.tar.gz 29.4 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for alibabacloud-agentcore-collaboration 0.1.1
File Interpreter ABI Platform
alibabacloud_agentcore_collaboration-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 66.1 kB

Release files / alibabacloud_agentcore_collaboration-0.1.1.tar.gz

Download URL alibabacloud_agentcore_collaboration-0.1.1.tar.gz
Size 29.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6ff29bb116135a82938ff5f599fb623c457c7c4d8da8867c498bac895166dcc5
BLAKE2b-256 checksum
How to use checksums
f310b8ebba99a32729066616b451001d09f96c1e644bea25352260bffa3f0f9b
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 Sep 9, 2026.

Transparency log

Release files / alibabacloud_agentcore_collaboration-0.1.1-py3-none-any.whl

Download URL alibabacloud_agentcore_collaboration-0.1.1-py3-none-any.whl
Size 36.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a3a53e4f3c28395e3e256fa0f87de4dcf8f799a047cf0b93af26a65ab52bf1e
BLAKE2b-256 checksum
How to use checksums
63944b19f7f648b0668fa7c6b6052ea53e177f89b634e7244c8223a9120b6378
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 Sep 9, 2026.

Transparency log

Security for alibabacloud-agentcore-collaboration 0.1.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

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

Select from 2 files

Attestation for alibabacloud_agentcore_collaboration-0.1.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 Sep 9, 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.

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