Agent Routing
Automatically pass outputs and context between AI agents with intelligent transformation.
Agent routing is MadoHub's core orchestration engine. When one agent completes a task, MadoHub automatically captures its output, transforms it into a targeted, actionable prompt, and seamlessly dispatches it to downstream agents—enabling autonomous multi-agent pipelines.
How it works
- Trigger — A connected source tile activates routing based on your configured condition (idle detection, completion signal, keyword match, or continuous streaming).
- Extract — MadoHub captures the agent's latest output. For CLI agents like Claude Code, it utilizes native structured session extraction to eliminate terminal artifacts.
- Transform — The captured output is reshaped into an actionable prompt for the downstream agent via AI rewriting, template wrapping, or direct passthrough.
- Deliver — MadoHub delivers the prompt to the target terminal using adaptive pacing and agent-specific execution handshakes.
High-Fidelity Session Capture
In traditional multi-terminal automation, scraping terminal screens is notoriously fragile, often capturing messy ANSI escape sequences, progress spinners, and fragmented line wraps.
MadoHub employs native structured session capture:
- Pure Context Extraction: Directly interfaces with the agent's structured session record to extract genuine assistant reasoning, code diffs, and tool results—completely free of terminal display noise.
- Context-Aware Workspace Alignment: Automatically aligns canvas tiles with their underlying project directories, ensuring relative paths and file contexts remain accurate across handoffs.
- Zero-Invasive Monitoring: Operates without modifying the agent's core source code, preserving native CLI integrity and stability.
Trigger Types
| Type | Behavior & Use Case |
|---|---|
| on-idle | Idle Detection (Recommended): Triggers after the agent finishes its turn and maintains a short period of silence. Most reliable. |
| on-complete | Completion Signal: Triggers as soon as the agent explicitly signals task completion. |
| on-keyword | Pattern Match: Fires immediately when output matches a specified regex or keyword. |
| always | Continuous Stream: Continuously streams new terminal output to the target agent in real time. |
Transform Types
| Type | Description & Applications |
|---|---|
| ai-routing | AI-Powered Synthesis (Core): Uses an AI model to generate a context-aware prompt tailored to the downstream agent. Configure models in Settings. |
| prompt-wrap | Template Wrapping: Wraps output in a custom template. Variables: {output}, {round}, {maxRounds}, {source}. |
| summary | Intelligent Summary: Generates an AI-synthesized summary of key diffs and conclusions. |
| full-output | Full Passthrough: Forwards the last 30 lines of terminal output. |
| raw | Compact Passthrough: Forwards the last 10 lines of terminal output. |
Adaptive Terminal Delivery
To guarantee rock-solid prompt delivery across diverse terminal environments, MadoHub incorporates an adaptive dispatch protocol:
- Intelligent Flow Control: Dynamically paces keystroke injection to match terminal buffer capacity, eliminating dropped characters during rapid handoffs.
- Protocol-Aware Handshakes: Automatically tailors execution protocols for Claude Code, Codex, Amp, OpenCode, and standard shells to ensure deterministic execution.
Loop Safeguards
Routing connections include built-in safeguards to prevent runaway execution and token exhaustion:
| Setting | Default | Range | Description |
|---|---|---|---|
| maxRounds | 5 | 1–20 | Maximum routing cycles before automatic deactivation. |
| cooldownMs | 3s | 1–30s | Minimum mandatory cooldown between successive triggers. |
| stopKeyword | — | Any string | Automatically terminates routing when a stop phrase (e.g. "LGTM", "RESOLVED") is detected. |
Example Workflow
Terminal 1 (Claude Code: Refactoring) Terminal 2 (Claude Code: Code Review)
┌──────────────────────┐ → ┌──────────────────────┐
│ "Refactor auth module"│ │ Receives: │
│ │ │ "Review the refactor │
│ ✓ Done — 3 files │ │ in src/auth/..." │
└──────────────────────┘ └──────────────────────┘Agent 1 completes the refactoring. MadoHub captures the pure code changes, generates a focused review prompt via ai-routing, and delivers it to Agent 2 to start an independent review and testing pass.