Skip to content

refactor: Hub-only gateway architecture + agent collaboration overhaul#36

Merged
yishuiliunian merged 1 commit intomainfrom
refactor/hub-gateway-agent-collaboration
Mar 28, 2026
Merged

refactor: Hub-only gateway architecture + agent collaboration overhaul#36
yishuiliunian merged 1 commit intomainfrom
refactor/hub-gateway-agent-collaboration

Conversation

@yishuiliunian
Copy link
Copy Markdown
Contributor

Summary

  • Migrate from "every agent is a TCP server" to "Hub is the sole gateway, agents are pure stdio workers"
  • Redesign agent collaboration tools: self-contained Agent tool (spawn/result/status), simplified SendMessage, Bash with integrated background management
  • Remove all legacy point-to-point communication (Channel, MessageRouter, TaskOutput/TaskStop as separate tools)

Changes

Hub Architecture (loopal-agent-hub):

  • Agent topology table with parent/child tracking and lifecycle state machine
  • Explicit agent/completed protocol (primary signal, EOF as fallback)
  • hub/wait_agent runs as background task (no IO loop blocking)
  • Race-safe completion: emit before unregister + finished_outputs cache
  • Cascade shutdown via IPC interrupt to orphaned children
  • TUI relay with 30s timeout
  • New: hub/agent_info, hub/topology query methods

Agent Tools (loopal-agent):

  • tools/collaboration/agent.rs: Agent tool with action=spawn/result/status
  • tools/collaboration/send_message.rs: Point-to-point only (no broadcast/shutdown)
  • Deleted: Channel tool, hub_ipc.rs, old agent.rs/send_message.rs

Process Tools (tools/process):

  • Bash tool integrates background process management (process_id param for output/stop)
  • Deleted: TaskOutputTool, TaskStopTool (merged into Bash)

Completion Chain Fixes:

  • Non-interactive server auto-exits after session
  • Loop detector warning appended after ToolResult (not before)
  • normalize_messages: ToolResult blocks sorted before Text blocks

104 files changed, +4378/-2844

Test plan

  • cargo clippy --workspace --tests — zero warnings
  • cargo test --workspace — 1632 tests pass
  • Manual e2e: spawn 3 background agents → all complete with real output → no stuck/timeout
  • CI passes

…overhaul

Migrate from "every agent is a TCP server" to "Hub is the sole gateway,
agents are pure stdio workers". This restructures the entire multi-agent
communication, lifecycle management, and tool system.

Hub Architecture:
- Hub owns all agent connections (stdio for agents, TCP for external clients)
- Agent processes no longer open TCP ports (tcp_accept.rs deleted)
- Hub manages agent spawn, completion detection, and cascade shutdown
- Explicit agent/completed protocol (not relying on EOF alone)
- Agent topology table tracking parent/child relationships and lifecycle
- Permission/question relay through Hub with 30s timeout

Completion Chain (was completely broken, now reliable):
- Non-interactive agent server auto-exits after session completes
- Hub captures real agent output (from ToolResult/Stream events)
- hub/wait_agent spawned as background task (doesn't block IO loop)
- Race-safe: emit_agent_finished before unregister + finished_outputs cache
- 10-minute timeout on wait_agent to prevent infinite hangs

Agent Collaboration Tools (redesigned):
- Agent tool: self-contained with action=spawn/result/status
- SendMessage: simplified to point-to-point Hub routing only
- Removed: Channel tool (unreliable pull model), TaskOutput/TaskStop tools
- Bash tool: integrated background process management (process_id param)
- Tools reorganized: collaboration/ subdirectory for multi-agent tools

Deleted (legacy point-to-point):
- MessageRouter, AgentRegistry, Channel/ChannelStore
- tcp_accept.rs, bridge event forwarding
- 5 hub/channel protocol methods, hub/broadcast
- TaskOutputTool, TaskStopTool (merged into Bash)

Bug Fixes:
- Loop detector warning no longer breaks tool_use/tool_result pairing
- normalize_messages ensures ToolResult blocks before Text blocks
- Spawn failure cleanup (kills orphan processes)
- Parent validation on agent registration
@yishuiliunian yishuiliunian force-pushed the refactor/hub-gateway-agent-collaboration branch from 768c70c to 4d798fd Compare March 28, 2026 13:02
@yishuiliunian yishuiliunian merged commit db57d9c into main Mar 28, 2026
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant