PTENES
← Track 5 | Module 5.2
Module 5.2

Multi-Agents with TinyClaw

Orchestration of specialized agents, asynchronous communication, and intelligent division of responsibilities.

1

What Is Multi-Agent Orchestration?

Multi-agent orchestration is the architectural pattern where a orchestrator agent decomposes complex tasks and distributes subtasks to specialized agents.

# Multi-Agent Task Flow
User: "Create a report on AI trends"
[Orchestrator]
  ├─ ResearchAgent: find articles and data
  ├─ AnalysisAgent: identify patterns
  ├─ WriteAgent: write sections
  └─ ReviewAgent: review and format
[Result]
  └─ Consolidated report → User
2

Why TinyClaw for Multi-Agent Systems?

TinyClaw was designed for local orchestration without cloud infrastructure. All agents run in the same Python process and share memory via SQLite.

Advantages
  • · Minimum latency (in-process communication)
  • · No network cost between agents
  • · Simplified debugging (everything in the same log)
Limitations
  • · Limited by one machine's CPU/RAM
  • · Does not scale horizontally
  • · For scale: use Celery or Ray
3

Hub-and-Spoke Architecture

TinyClaw’s main pattern: a central orchestrator (Hub) that knows all available agents (Spokes) and decides which one to use for each subtask.

# orchestrator.py
class
Orchestrator:
  def __init__(self):
    self.agents = {}
    self.queue = asyncio.Queue()
  def register(self, name, agent):
    self.agents[name] = agent
  async def dispatch(self, task):
    agent_name = self.route(task)
    return await self.agents[agent_name].run(task)
4

Asynchronous Communication Between Agents

Agents communicate via typed messages in asyncio queues. Each message has a type, payload, and correlation_id for context tracking.

# message.py
from
dataclasses import dataclass
@dataclass
class
AgentMessage:
  type: str       # "research", "write", "review"
  payload: Any
  correlation_id: str
  priority: int = 5  # 1=high, 10=low
5

Specialization and Task Division

Each specialized agent has its own SOUL.md, specific tools, and an AI model suited to its role.

Typical Agents in a TinyClaw System
ResearchAgentWeb search, document reading, data extraction. Uses Claude 3.5 Sonnet.
CodeAgentWrites and runs Python code. Uses Claude 3.5 Sonnet.
WriteAgentWrites long, structured text. Uses GPT-4o.
ReviewAgentCritiques, reviews, and scores quality. Uses local Llama to keep costs low.
6

Multi-Agent Monitoring and Debugging

Debugging multi-agent systems is challenging without the right tools. TinyClaw implements trace_id propagation and a real-time monitoring dashboard.

# monitor.py
class
AgentMonitor:
  metrics = defaultdict(list)
  def record(self, agent, duration, tokens, success):
    self.metrics[agent].append({
      "ts": time.time(), "dur": duration,
      "tokens": tokens, "ok": success
    })
Essential metrics per agent
· Average latency per task
· Success/failure rate
· Total token cost
· Queue size (backlog)
← Back to Track 5