智能体
dev.to ·
@Albert zhang
构建结构化 Agent 间通信:实用指南
文章指出多数多 Agent 教程只演示“Agent A 与 Agent B 对话”,在输出超 token 限制、关键参数被摘要掉或解析不一致时会失效。作者提出在 AgentForge 中为每个 Agent 声明输入 schema,由编排器在执行前校验,若上游输出不匹配下游输入 schema 则中止流水线并报错。
AI推荐理由 面向多 Agent 通信的实践指南,指出字符串式 Agent 对话在 token 超限、上下文丢失、解析歧义下的失效,并提出用带 schema 的 JSON 契约在编排层校验输入输出。对构建多 Agent 系统有具体工程参考价值;但为个人博客,未提供基准测试或生产验证数据。
70
正文
Every multi-agent tutorial shows "Agent A talks to Agent B." None show how to keep that conversation reliable at scale.
The Problem with String-Based Agent Chat
# What most frameworks do:
result = agent_a.run("Analyze this and tell agent_b what to do")
agent_b.run(result) # What if result is 2000 tokens? What if it omits context?
Enter fullscreen mode
Exit fullscreen mode
This breaks when:
Output exceeds token limits
Critical parameters get "summarized" away
Agent B parses instructions differently than intended
Our Solution: Typed JSON Contracts
Every agent in AgentForge declares its input schema:
{
"agent": "risk_analyzer",
"input": {
"portfolio": ["AAPL", "TSLA"],
"timeframe": "1d",
"risk_threshold": 0.05
},
"expected_output": {
"max_drawdown": "float",
"sharpe_ratio": "float",
"flags": ["string"]
}
}
Enter fullscreen mode
Exit fullscreen mode
The orchestrator validates before execution. If agent A's output doesn't match agent B's input schema, the pipeline halts with a clear error — instead of agent B making a wrong inference.
Schema Enforcement at Runtime
from agentforge.core import Orchestrator, AgentContract
contract = AgentContract(
input_schema={"query": str, "max_results": int},
output_schema={"results": list, "confidence": float}
)
orch = Orchestrator()
orch.register("search_agent", search_fn, contract)
Enter fullscreen mode
Exit fullscreen mode
If search_fn returns "confidence": "high" instead of 0.92, the orchestrator flags it immediately.
Why This Matters
In production, you don't want agents to "kind of work." You want deterministic, debuggable, testable behavior. Typed contracts give you that.
Built with AgentForge. Open source. Production-tested.
https://github.com/agentforge-cyber/agentforge-mvp
Do you enforce schemas in your agent pipelines? Or do you trust the LLM to "figure it out"?
Posted on 2026-09-10 by the AgentForge team.