Step 4 of 4
Tool Use, MCP & Memory
How agents call tools, what the Model Context Protocol standardizes, how agent memory works, and the full GenAI engineering tool stack.
16 min read
An agent is only as capable as what it can reach. This guide covers the three things that extend a model beyond its training data: tools (actions), the Model Context Protocol (a standard way to plug tools in), and memory (what persists between steps and sessions). Then it maps the full tool stack a GenAI engineer works with, layer by layer.
How tool calling works#
The model never executes anything itself. It requests a call; your code runs it and returns the result.
- 01Describe toolsName, description, JSON schema
- 02Model emits call{name, arguments}
- 03Your code executesValidate, check permissions, run
- 04Return resultAppended as a tool message
↺ Return result feeds back into Describe tools
Tool design matters more than prompt tweaking. Good tools:
- Have precise names and descriptions - the description is the model's only documentation. Say when to use it and when not to.
- Take few, well-typed arguments with enums where possible, so there's less to get wrong.
- Return compact, relevant output - not a 5,000-line JSON dump that floods the context window.
- Fail informatively - return "no customer with id 123; ids look like C-12345" rather than a stack trace, so the model can recover.
- Are safe by default - read-only unless writes are essential; destructive actions require confirmation.
The Model Context Protocol (MCP)#
Before MCP, every app wired every tool with custom glue code. MCP is an open protocol that standardizes the connection: build a tool server once, and any MCP-capable app - Claude, IDEs, agent frameworks - can use it.
Servers expose three kinds of primitives:
Tools
model-controlledActions the model can invoke: create_issue, run_query, send_message.
Resources
app-controlledRead-only data the app can load into context: files, database rows, API responses.
Prompts
user-controlledReusable templates a user can pick, like 'summarize this PR'.
- stdio
- Standard input/output - a way for two programs on the same machine to communicate by reading and writing each other's text streams. MCP uses it for local servers.
- JSON Schema
- A standard for describing the expected shape of JSON data - which fields exist, their types, and which are required. Used to define tool parameters.
- OAuth
- An authorization protocol that lets an app access a user's data on another service without seeing their password - the 'Sign in with Google' flow.
Agent memory#
A model's context window is its only working memory, and it's wiped between sessions. Agent memory systems decide what to keep, where, and when to bring it back.
| Memory type | What it holds | Typical implementation |
|---|---|---|
| Working (short-term) | The current conversation and tool results | The context window; trimmed or summarized as it fills |
| Episodic | What happened in past sessions | Stored transcripts or summaries, retrieved by similarity or recency |
| Semantic | Facts about the user, project, or world | A key-value or vector store of extracted facts ("prefers Python") |
| Procedural | How to do things | System prompts, skills, and learned instructions |
The central design question is what to write (extracting durable facts rather than saving everything), when to read (retrieve relevant memories into context at the right moment), and how to forget (resolve contradictions, expire stale facts). Research like MemGPT frames this like an operating system: a small, fast context window "paged" against larger external storage, with the model itself deciding what to move in and out.
- Vector database
- A database optimized for storing and searching high-dimensional vectors (embeddings) by similarity - finds the most relevant past memories or documents.
- MemGPT / Letta
- An approach that gives an LLM OS-like memory management - paging facts in and out of its context window from external storage so it can work with more data than fits at once.
The GenAI engineer's tool stack#
Thirteen layers, with well-known open-source or widely used options for each. You won't need all of them in one project - this is the map.
5 open-source agent repos#
Five categories of open-source agent projects worth studying - reading good code teaches more than any tutorial. One well-known example for each:
Agent & subagent collections
breadthLarge curated sets of specialized agents across many domains (e.g., wshobson/agents). Great for seeing how experienced builders scope prompts and tool sets.
Browser automation
browser-useAgents that drive a real browser - navigate, click, fill forms, extract. browser-use and Microsoft's Playwright MCP server are the reference points.
Lightweight agent frameworks
smolagentsMinimal libraries you can read end to end. Hugging Face's smolagents shows the whole loop, including agents that write and run code as their actions.
Agent memory
mem0 · LettaMemory layers that extract, store, update, and retrieve long-term facts. Mem0 and Letta (from the MemGPT authors) take different, instructive approaches.
Code-to-media
RemotionGenerate video by writing code. Remotion turns React components into video, which makes it a natural target for coding agents that edit and render media.
Browse the official modelcontextprotocol/servers repository too - it's the fastest way to see how real tools are exposed over MCP.
Papers behind this guide
Toolformer
Language models can teach themselves when and how to call external tools.
Meta AI, 2023
ReAct: Reasoning + Acting
The foundation of modern AI agents - interleaving reasoning traces with tool use actions.
Google Brain, 2022
MemGPT: LLMs as Operating Systems
Tiered memory for agents - page information in and out of the context window like an OS.
UC Berkeley, 2023
RAG: Retrieval-Augmented Generation
Combining retrieval systems with generative models - the architecture behind most enterprise AI apps today.
Meta AI, 2020