Learn
AI Agent Gateway
10 patterns every production AI agent must implement — from the basic loop to concurrency. Built from real systems, not tutorials.
Adapted from claw0 by shareAI-lab — rewritten in Go.
The Agent Loop
An agent is just while True + stop_reason. Understanding this loop is the foundation for everything else.
Tool Use
Tools are data (schema) + a handler map. The model picks a name, you look it up and run it.
Sessions & Context Guard
Sessions are JSONL files. Append on write, replay on read. When too big, summarize.
Channels
Every platform is different, but they all produce the same InboundMessage. Normalize at the edge.
Gateway & Routing
A binding table maps (channel, peer) to agent_id. Most specific wins.
Intelligence
The system prompt is assembled from files on disk. Swap files, change personality.
Autonomy
Not just reactive — proactive. Heartbeat and Cron let agents run on their own schedule.
Delivery
Write to disk first, then try to send. If the process crashes mid-send, the message survives.
Resilience
When one API call fails, rotate and retry. A 3-step retry chain handles rate limits, context overflow, and tool errors.
Concurrency
Named lanes replace a single lock. Each concern gets its own queue — user, heartbeat, and cron no longer compete.