Skip to main content

将 CrewAI Agent 一行命令转为 A2A 服务 — 开源替代 CrewAI AMP 的本地开发方案

Project description

a2a_auto_wrapper

CrewAI Agent 一行命令转为 A2A 服务 — 开源替代 CrewAI AMP 的本地开发方案。

基于 AutoA2A (NapthaAI)Google A2A Protocol

安装

pip install a2a_auto_wrapper

同时需要安装 CrewAI:

pip install crewai

快速开始

服务端 — 一行启动 CrewAI A2A 服务

# crewai_a2a_server.py
from crewai import Agent, LLM
from crewai.a2a import A2AServerConfig
from a2a_auto_wrapper import serve_crewai_agent

analyst = Agent(
    role="数据分析师",
    goal="对数据进行深度分析并生成结构化报告",
    backstory="你是资深数据分析师,擅长数据洞察和趋势预测。",
    llm=LLM(model="deepseek-chat", base_url="https://api.deepseek.com/v1", api_key="..."),
    a2a=A2AServerConfig(url="http://localhost:2025"),
)

if __name__ == "__main__":
    serve_crewai_agent(analyst, port=2025)
python crewai_a2a_server.py
# ✅ 服务运行在 http://localhost:2025

客户端 — 调用 A2A 服务

import asyncio
from a2a_auto_wrapper import A2AClient

async def main():
    client = A2AClient("http://localhost:2025/")
    result = await client.send_message("分析销售数据:1月100万 2月120万 3月90万")
    print(result)

asyncio.run(main())

DeepAgents 调用 CrewAI(A2A 互调)

# deepagent_a2a.py
from a2a_auto_wrapper import A2AClient
from langchain_openai import ChatOpenAI
from langchain_core.tools import tool
from deepagents import create_deep_agent

crewai_client = A2AClient(base_url="http://localhost:2025/")

@tool
async def call_crewai_analyst(query: str) -> str:
    """需要数据分析时调用 CrewAI 分析师。"""
    return await crewai_client.send_message(query)

agent = create_deep_agent(
    model=ChatOpenAI(model="deepseek-chat", ...),
    tools=[call_crewai_analyst],
)
graph = agent  # langgraph dev 加载入口

API 参考

serve_crewai_agent(agent, port=2025)

启动 CrewAI Agent 为 A2A HTTP 服务。

参数 类型 默认值 说明
agent crewai.Agent 必填 已配置 A2AServerConfig 的 CrewAI Agent
port int 2025 监听端口

A2AClient

A2A 客户端,调用远程 A2A 服务。

client = A2AClient(base_url: str, timeout: int = 120)
result = await client.send_message(text: str) -> str
方法 参数 返回值 说明
__init__ base_url, timeout=120 构造客户端
send_message text str 发送消息,返回结果文本

通信流程

用户 → langgraph_sdk → DeepAgents (:2024) → A2A → CrewAI (:2025)

依赖

  • Python >= 3.12
  • crewai (安装本包后需单独安装)
  • httpx, starlette, uvicorn, pydantic

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

a2a_auto_wrapper-1.0.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

a2a_auto_wrapper-1.0.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file a2a_auto_wrapper-1.0.0.tar.gz.

File metadata

  • Download URL: a2a_auto_wrapper-1.0.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for a2a_auto_wrapper-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e4def1ae2316615094138763af11170174da38f7a8183d5a302c00de27b828a2
MD5 624f2a6092c59375a8f5e0c8840fc19c
BLAKE2b-256 8cfe6e64283e86a70f48de9fd18737777fe13f787a756e86da2c4eb48d5b826f

See more details on using hashes here.

File details

Details for the file a2a_auto_wrapper-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for a2a_auto_wrapper-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae686510ebcc651bb9b14ea8072a0f19b8f28928627597060005d1bed1b88323
MD5 4ad6a6b08847a36d663c31c2a08f4da9
BLAKE2b-256 e810bb030962e1c2f4f84443ffe42c4512c5e148dfeff56d19e108e00f787ee9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page