> ## Documentation Index
> Fetch the complete documentation index at: https://docs.monolex.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Bidirectional AI Communication

> AI agents that talk to each other — not just sequential handoff, but real-time dialogue between different LLMs.

# Bidirectional AI Communication

Most multi-agent systems are one-directional: leader delegates, worker reports back.
connector.json supports **bidirectional** communication — agents that genuinely converse.

## The Difference

```
Unidirectional (everyone else):
  Leader → "do this" → Worker → "done, here's result" → Leader
  Worker never initiates. Worker never asks questions.

Bidirectional (connector.json):
  Agent A → "what do you think about X?" → Agent B
  Agent B → "I think Y, but what about Z?" → Agent A
  Agent A → "good point, let me revise" → Agent B
  ...continues until convergence
```

## How It Works

Two PTY sessions. Each running a different AI.
The mailbox system routes messages between them.

```
┌──────────────────┐         mailbox          ┌──────────────────┐
│  PTY Session 1   │ ←──────────────────────→ │  PTY Session 2   │
│  Claude Opus     │    niia get-answer →     │  Codex           │
│                  │    ← niia write          │                  │
│  "I think the    │                          │  "Actually the   │
│   auth flow      │                          │   bottleneck is  │
│   has a gap in   │                          │   in the token   │
│   session mgmt"  │                          │   refresh, not   │
│                  │                          │   session mgmt"  │
└──────────────────┘                          └──────────────────┘
```

The orchestrator reads one agent's response, feeds it to the other, and repeats.
Each agent sees the full conversation history — they're having a real dialogue.

## Debate Pattern

Two AI agents argue opposing positions. A third judges.

```json theme={null}
{
  "connector": "2.0",
  "name": "architecture-debate",
  "models": {
    "advocate": "claude",
    "challenger": "codex",
    "judge": "gemini"
  },
  "pipeline": {
    "phases": [
      {
        "name": "debate",
        "type": "dialogue",
        "participants": [
          { "model": "advocate",   "role": "Argue FOR microservices architecture." },
          { "model": "challenger", "role": "Argue AGAINST microservices. Propose monolith." }
        ],
        "rounds": 3,
        "scratchpad": true
      },
      {
        "name": "verdict",
        "model": "judge",
        "prompt": "Read the debate transcript. Which architecture is better for this specific codebase? Decide with evidence."
      }
    ]
  }
}
```

Round 1: Claude argues for microservices. Codex argues against.
Round 2: Each reads the other's argument and responds.
Round 3: Final rebuttals.
Verdict: Gemini reads the full transcript and decides.

Three different AI models. Three different perspectives. One decision.

## Peer Review Pattern

Two agents review each other's work, not just a leader's delegation.

```json theme={null}
{
  "pipeline": {
    "phases": [
      {
        "name": "implement",
        "parallel": true,
        "workers": [
          { "id": "alice", "model": "claude", "prompt": "Implement the auth module." },
          { "id": "bob",   "model": "codex",  "prompt": "Implement the auth module." }
        ],
        "session": { "worktree": "impl-{id}" }
      },
      {
        "name": "cross-review",
        "type": "dialogue",
        "pairs": [
          { "reviewer": "alice", "author": "bob" },
          { "reviewer": "bob",   "author": "alice" }
        ],
        "prompt_template": "Review {author}'s implementation. Compare with yours. Suggest improvements.",
        "rounds": 2
      },
      {
        "name": "merge",
        "model": "claude",
        "prompt": "Read both implementations and both reviews. Merge the best parts into final implementation."
      }
    ],
    "scratchpad": true
  }
}
```

Both implement independently → Each reviews the other's code → Best parts merged.

Neither agent is "senior". Both contribute. Both critique. The result is better than either could produce alone.

## Socratic Teaching Pattern

One agent asks questions. The other explains. Together they find gaps.

```json theme={null}
{
  "pipeline": {
    "phases": [
      {
        "name": "exploration",
        "type": "dialogue",
        "participants": [
          { "model": "opus",  "role": "You are investigating a bug. Ask questions to understand the codebase." },
          { "model": "haiku", "role": "You know this codebase well. Answer questions concisely. If you're not sure, say so." }
        ],
        "rounds": 5,
        "scratchpad": true
      },
      {
        "name": "hypothesis",
        "model": "opus",
        "prompt": "Based on the Q&A session, form a hypothesis about the bug's root cause."
      }
    ]
  }
}
```

Opus asks probing questions. Haiku answers from codebase knowledge (cheap, fast). After 5 rounds, Opus has enough context to hypothesize — without reading every file itself.

Cost: 5 rounds of Haiku responses (\$) + 1 Opus synthesis (\$\$\$) vs Opus reading everything (\$\$\$\$\$\$).

## Red Team / Blue Team

One agent attacks. The other defends.

```json theme={null}
{
  "pipeline": {
    "phases": [
      {
        "name": "secure",
        "model": "claude",
        "prompt": "Review the auth implementation. Declare it secure."
      },
      {
        "name": "attack",
        "type": "dialogue",
        "participants": [
          { "model": "codex", "role": "RED TEAM: Find exploits in the auth code. Try to break it." },
          { "model": "claude", "role": "BLUE TEAM: Defend against each attack. Patch if needed." }
        ],
        "rounds": 3
      },
      {
        "name": "report",
        "model": "gemini",
        "prompt": "Read the red/blue team transcript. Rate security 1-10. List unresolved vulnerabilities."
      }
    ]
  }
}
```

Codex attacks. Claude defends and patches. Gemini judges.
Three AI models, three roles, one security audit.

## Why Bidirectional Matters

Unidirectional multi-agent is **delegation**: one AI telling others what to do.
Bidirectional multi-agent is **collaboration**: multiple AI reasoning together.

```
Delegation:    Manager → Worker → Result
               One perspective. One approach.

Collaboration: Agent A ↔ Agent B → Synthesis
               Multiple perspectives. Challenged assumptions.
               Better results through disagreement.
```

When two different LLMs debate, they catch each other's blind spots.
Claude's reasoning depth + Codex's speed + Gemini's breadth = stronger than any one alone.

## Implementation

Bidirectional communication uses the same PTY infrastructure:

```
1. Agent A writes response to PTY
2. niia get-answer reads Agent A's response
3. niia write sends it to Agent B's PTY
4. Agent B writes response
5. niia get-answer reads Agent B's response
6. niia write sends it back to Agent A
7. Repeat for N rounds
```

The mailbox (get-answer + DB) persists the full conversation.
Both agents see the entire dialogue history.
The orchestrator just routes messages between PTY sessions.

No special protocol needed. No JSON-RPC. No structured I/O.
Just reading terminal output and typing into another terminal.
The simplest possible implementation of AI-to-AI communication.

## Related

Dialogue is one step on the topology spectrum. For all-at-once multi-agent conferences, see [Meeting Protocol](/openclis/specs/connector-json/meeting-protocol). For any-agent-to-any-agent communication without a leader, see [N-to-N Topology](/openclis/specs/connector-json/n2n-topology). For the full topology spectrum, see [Dimensional Growth](/openclis/specs/connector-json/dimensional-growth).
