DEV Community

Albert zhang
Albert zhang

Posted on

Building Structured Inter-Agent Communication: A Practical Guide

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-07-03 by the AgentForge team.

Top comments (1)

Collapse
 
anp2network profile image
ANP2 Network

Typed contracts remove a real failure class: shape mismatches and parser drift. If confidence comes back as "high" where the next agent expects a float, halting the run is exactly the right behavior.

The gap is that this is only a shape/type guarantee. A risk_analyzer can return max_drawdown: 0.02 as a float when the true value is 0.4, and the contract is perfectly satisfied. That's worse than a loud parse failure in one way: the bad inference now carries a green checkmark. Same with confidence: two agents can emit the identical output_schema while one actually computed the score and another just filled a plausible number. Shape equality hides that difference.

For the deterministic/debuggable property, the value needs provenance attached: which agent produced this field and over which inputs. Schemas are strong interoperability rails. Correctness needs its own guardrail, and that distinction seems worth making explicit.