design·lab

System design · application

Design: AI Agent

Turn a stateless, hallucinating LLM into a reliable autonomous agent — by wrapping it in tools, memory, and a durable loop.

✗ The problem

A raw LLM can't act, can't remember, can't be trusted

Ask a plain LLM "what's the weather in Paris, then book a cab" and it either refuses, or invents a plausible-sounding answer. It has no tools, no memory across calls, and no way to check its own work.

🧠 Raw LLM
stateless text-in, text-out
🎲 Guessed answer
"probably 20°C, cab booked!" (fabricated)
To be a useful agent it must: call real tools (APIs), ground answers in real data instead of guessing, remember context across steps, and reliably complete multi-step tasks — not just answer one prompt.
✓ Big picture

The 10,000-ft view — the think → act → observe loop

Before the details: the whole agent in one glance. The middle repeats until the LLM has an answer.

✓ Architecture

The agent runtime: a loop around the LLM

The LLM only reasons. Everything else — acting, remembering, retrying — is engineered around it.

// ReAct loop, one iteration
while (!done) {
  step = llm.plan(ctx, memory);
  if (step.type === 'tool') {
    result = tool.call(step);   // Adapter
    ctx.observe(result);
  } else {
    done = true;      // final answer
  }
}
🧠 LLM
reasoning / planning — think→act→observe
🔧 Tools
each wrapped as an Adapter, picked by Strategy
📚 Memory
short-term context + vector search (RAG)
🗂️ Orchestrator
durable workflow
🛡️ Circuit breaker
🚦 Rate limiter
✓ See it live

Think → Act → Observe, one task, five actors

Task: "What's the weather in Paris, then book a cab?" Watch the agent loop: retrieve memory, ask the LLM to think, call a tool, observe the result — repeat until the LLM emits a final answer.

The loop repeats think→act→observe until the LLM emits a final answer — here that's two tool calls, then done.

✓ How it combines

An agent is the whole site, wired together

  • The reasoning loop is a durable workflow — it survives crashes mid-task.
  • Each tool is an Adapter around a real API, chosen at runtime by Strategy.
  • RAG memory is vector search over a search index, so answers stay grounded in real data.
  • Every tool/LLM call is guarded by a circuit breaker and a rate limiter, so one flaky dependency can't take the agent down.
  • Long-running steps go through a queue so slow tools don't block the loop.
  • Progress and tool results are broadcast via pub-sub so UIs and logs stay in sync without polling — the same idea as Observer.
🎯 Combines the whole site: patterns (Adapter, Strategy, Observer), architecture (queues, pub-sub), distributed (workflow, circuit breaker, rate limiter), data (vector search, indexing) — an AI agent is software design, all at once.