跪拜 Guibai
← All articles
Agent

The Anatomy of an AI Agent: Memory, Tools, and the Engineering That Makes LLMs Act

By 凌涘 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Most Western developers interact with agents as black-box products. Understanding the exact composition — memory, tool schemas, parallel execution — is what separates a brittle demo from a production system that can run unattended multi-step jobs without hallucinating or timing out.

Summary

Bare LLMs are stateless, cannot act, and know nothing past their training cutoff. An agent fixes all four gaps by bolting on a memory module for persistent context, tool-calling for real-world execution, RAG for private knowledge retrieval, and a skills layer for domain depth. The formula is Agent = LLM + Memory + Tool + RAG + MCP + Skills.

A walkthrough using LangChain.js shows the concrete wiring: binding a model like DeepSeek via an OpenAI-compatible endpoint, defining tools with Zod schemas so the LLM generates structured `tool_calls` instead of hallucinating, and orchestrating multi-step workflows where each tool result feeds the next decision. When tool calls are independent, Promise.all cuts latency from the sum of operations down to the slowest one.

The real difficulty is not the concepts but harness engineering — stable interfaces, error handling, concurrency scheduling, and debuggability. A React + Vite TodoList generator is just LLM + filesystem tools + CLI tools, the same primitive that powers simplified versions of Claude Code.

Takeaways
An agent is an LLM plus memory, tool use, RAG, MCP, and skills — not a new model architecture.
LLMs are stateless; a memory module stores conversation history in a database or Redis and injects relevant context into each request.
Tool calling works by having the LLM emit structured `tool_calls` arrays with IDs and parameters, pausing text generation until results return.
LangChain's `bindTools` method registers tools with a model, and Zod schemas enforce correct parameter types on every call.
Logging every tool execution step is essential — users will assume the agent is stuck if they see no feedback during long-running tasks.
Promise.all parallelizes independent tool calls, reducing total wait time from the sum of operations to the duration of the slowest one.
Building a code-generating agent like a simplified Claude Code requires only an LLM, filesystem tools, and CLI tools orchestrated in a planning loop.
Multi-agent systems using LangGraph split work across specialized agents — architect, coder, reviewer — that collaborate via message passing.
The hard part is harness engineering: stable tool interfaces, exception handling, concurrency scheduling, and making agent behavior debuggable.
Conclusions

LangChain's value is often misunderstood as an orchestration layer, but its real utility is vendor abstraction — swapping DeepSeek for OpenAI with a baseURL change avoids lock-in.

The `tool_calls` mechanism reveals that LLMs have a form of meta-cognition: the model knows when it lacks information and requests external input rather than confabulating.

Parallel tool execution with Promise.all is an under-discussed performance lever; many agent demos serialize calls unnecessarily and feel sluggish as a result.

The article's framing of agent complexity as 'each piece is simple, the integration is hard' matches the experience of most teams shipping LLM features — the concepts are trivial, the error modes are not.

Concepts & terms
Agent
An LLM extended with memory, tool-calling, RAG, MCP, and domain-specific skills, enabling it to plan, retrieve knowledge, and execute multi-step tasks rather than just generate text.
Tool Use / Function Calling
A mechanism where an LLM emits structured `tool_calls` with function names and parameters instead of generating text, allowing external code to execute the requested operation and return results to the model.
RAG (Retrieval-Augmented Generation)
A pattern that retrieves relevant documents from a vector database and injects them into the LLM's prompt context, giving the model access to knowledge beyond its training cutoff.
MCP (Model Context Protocol)
A standardized protocol for connecting LLMs to third-party tools and data sources, analogous to a USB-C standard for AI integrations.
LangChain
An open-source framework that provides a unified abstraction layer for calling different LLM providers and orchestrating tools, memory, and retrieval components.
Promise.all
A JavaScript method that runs multiple asynchronous operations in parallel and returns all results once every operation completes, reducing total wait time to the duration of the slowest task.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗