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.

  1. 01Describe toolsName, description, JSON schema
  2. 02Model emits call{name, arguments}
  3. 03Your code executesValidate, check permissions, run
  4. 04Return resultAppended as a tool message

↺ Return result feeds back into Describe tools

The model sees the result and decides whether to call another tool or answer. This separation is what lets you enforce permissions.

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.

HostThe AI application the user interacts with (a chat app, an IDE, an agent)
ClientA connector inside the host that maintains a 1:1 session with one server
ServerExposes capabilities - a GitHub server, a database server, a filesystem server
Transportstdio for local processes; Streamable HTTP for remote servers
MCP's roles. One host can run many clients, each connected to one server.

Servers expose three kinds of primitives:

Tools

model-controlled

Actions the model can invoke: create_issue, run_query, send_message.

Resources

app-controlled

Read-only data the app can load into context: files, database rows, API responses.

Prompts

user-controlled

Reusable 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 typeWhat it holdsTypical implementation
Working (short-term)The current conversation and tool resultsThe context window; trimmed or summarized as it fills
EpisodicWhat happened in past sessionsStored transcripts or summaries, retrieved by similarity or recency
SemanticFacts about the user, project, or worldA key-value or vector store of extracted facts ("prefers Python")
ProceduralHow to do thingsSystem 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.

1 · ModelsFrontier APIs (Claude, GPT, Gemini) · open weights (Llama, Qwen, Mistral, DeepSeek)
2 · ServingvLLM, SGLang, TGI · Ollama, llama.cpp for local
3 · GatewaysLiteLLM, OpenRouter, Portkey - routing, fallbacks, budgets
4 · Agent frameworksLangGraph, OpenAI Agents SDK, CrewAI, Google ADK, smolagents
5 · RAG frameworksLlamaIndex, Haystack, GraphRAG
6 · EmbeddingsSentence Transformers, provider embedding APIs, rerankers
7 · Vector databasesQdrant, pgvector, Weaviate, Milvus, Chroma
8 · MemoryMem0, Letta, Zep/Graphiti
9 · Tool protocolMCP servers and clients
10 · GuardrailsNeMo Guardrails, Presidio (PII), Lakera and similar prompt-injection filters
11 · EvalsPromptfoo, Ragas, DeepEval, LLM-as-judge
12 · ObservabilityLangfuse, Arize Phoenix, Helicone, OpenTelemetry
13 · Fine-tuningUnsloth, Hugging Face TRL, Axolotl
From the model up to operations. Pick per layer; swap without rewriting the rest.

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:

1

Agent & subagent collections

breadth

Large curated sets of specialized agents across many domains (e.g., wshobson/agents). Great for seeing how experienced builders scope prompts and tool sets.

2

Browser automation

browser-use

Agents that drive a real browser - navigate, click, fill forms, extract. browser-use and Microsoft's Playwright MCP server are the reference points.

3

Lightweight agent frameworks

smolagents

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

4

Agent memory

mem0 · Letta

Memory layers that extract, store, update, and retrieve long-term facts. Mem0 and Letta (from the MemGPT authors) take different, instructive approaches.

5

Code-to-media

Remotion

Generate 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

Further reading

Search Data Science After Dark

Search across prompts, models, papers, guides, and library topics.