JamJet

A2A 集成

使用 Agent-to-Agent 协议委派给其他代理或为其他代理提供服务。

A2A 集成

JamJet 实现了 Agent-to-Agent (A2A) 协议 —— 一个开放标准,允许代理跨框架和组织相互发现、调用和协作。

什么是 A2A?

A2A 定义了代理如何:

  • 通过 Agent Card(一个 .well-known/agent.json 文件)发布其能力
  • 从其他代理接受任务(结构化的请求/响应格式)
  • 流式传输进度反馈(基于 SSE 的事件流)
  • 交换制品(文件、结构化数据、文本)

JamJet 代理原生支持 A2A —— 每个代理自动获得 Agent Card,并能接受来自其他框架(LangChain、CrewAI、AutoGen 等)的 A2A 任务。

Agent Cards

Agent Card 是代理的机器可读描述:

{
  "id": "research-agent",
  "name": "Research Agent",
  "description": "Searches the web and synthesizes research reports.",
  "version": "0.2.0",
  "url": "https://agents.example.com/research-agent",
  "capabilities": {
    "streaming": true,
    "push_notifications": false
  },
  "input_schema": {
    "type": "object",
    "properties": {
      "query": { "type": "string" }
    },
    "required": ["query"]
  },
  "output_schema": {
    "type": "object",
    "properties": {
      "answer": { "type": "string" },
      "sources": { "type": "array" }
    }
  }
}

JamJet 会根据你的工作流 schema 自动生成此文件。你可以在 jamjet.toml 中自定义:

[agent]
name = "Research Agent"
description = "Searches the web and synthesizes research reports."
url = "https://agents.example.com/research-agent"

调用其他代理

使用 a2a_task 节点将工作委托给另一个代理:

YAML

nodes:
  delegate-research:
    type: a2a_task
    agent_url: "https://agents.example.com/research-agent"
    input:
      query: "{{ state.query }}"
    output_key: research_result
    next: synthesize

Python SDK

@node
async def delegate_research(self, state: State) -> State:
    result = await self.a2a(
        agent_url="https://agents.example.com/research-agent",
        input={"query": state["query"]},
    )
    return {"research_result": result.state}

发现代理

如果代理发布了它们的 URL,你可以通过获取其代理卡片来发现它们:

jamjet agents inspect https://agents.example.com/research-agent
Agent: Research Agent (research-agent v0.2.0)
  URL: https://agents.example.com/research-agent
  Streaming: yes

  Input schema:
    query: string (required)

  Output schema:
    answer: string
    sources: array

将你的代理作为 A2A 服务

任何 JamJet 工作流都可以自动作为 A2A 代理提供服务。启用 A2A 服务器:

[a2a.server]
enabled = true
port = 7702
expose = ["research-agent", "summarizer"]
jamjet dev --with-a2a-server

你的代理卡片将在以下地址可用:

http://localhost:7702/.well-known/agent.json

现在,其他代理(在任何框架中)都可以将你的工作流作为 A2A 任务调用。

流式传输 A2A 响应

JamJet 支持基于 SSE 的 A2A 任务流式传输。在 a2a_task 节点中启用流式传输:

  delegate-research:
    type: a2a_task
    agent_url: "https://agents.example.com/research-agent"
    input:
      query: "{{ state.query }}"
    stream: true              # 实时接收事件
    output_key: research_result
    next: synthesize

# Python SDK

async for event in self.a2a_stream(
    agent_url="https://agents.example.com/research-agent",
    input={"query": state["query"]},
):
    print(event.type, event.data)

跨框架兼容性

JamJet 的 A2A 实现与以下框架兼容:

框架A2A 支持
JamJet原生(客户端 + 服务器)
LangChain通过 langchain-a2a
CrewAI通过 A2A 适配器
AutoGen通过 A2A 适配器
Vertex AI原生
任何 HTTP 客户端直接 REST 调用

注意: A2A 在设计上是框架无关的。JamJet 代理和 LangChain 代理可以直接协作——双方都无需知道对方使用的是什么框架。

安全性

在生产环境中,A2A 任务端点应受到保护。JamJet 支持:

[a2a.server]
enabled = true
auth = "api_key"              # 或 mtls、jwt
api_keys = ["${AGENT_API_KEY}"]

在零信任环境中使用 mTLS:

[a2a.server]
auth = "mtls"
ca_cert = "/path/to/ca.crt"
server_cert = "/path/to/server.crt"
server_key = "/path/to/server.key"

自主模式

JamJet 代理具有可配置的自主级别,用于控制所需的人工监督程度:

模式描述
guided(默认)在关键决策点暂停以获取人工批准
supervised自主运行但记录所有决策供审查
autonomous完全自主 — 无需人工干预
[agent]
autonomy = "guided"    # guided | supervised | autonomous

对于 guided 代理,使用 wait 节点在审批点暂停:

nodes:
  propose-action:
    type: model
    model: claude-sonnet-4-6
    prompt: "为以下任务提出方案:{{ state.task }}"
    output_key: plan
    next: await-approval

  await-approval:
    type: wait
    event: human_approved
    timeout_hours: 24
    on_timeout: escalate
    next: execute

On this page