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.
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.
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.
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
}
}
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.
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.