Skip to content

Commit a941609

Browse files
guides: add agentic guide
Signed-off-by: Craig <craig.osterhout@docker.com>
1 parent a30fb9e commit a941609

File tree

3 files changed

+318
-0
lines changed

3 files changed

+318
-0
lines changed

content/guides/agentic-ai.md

Lines changed: 318 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,318 @@
1+
---
2+
title: Build and run agentic AI applications with Docker
3+
linktitle: Agentic AI applications
4+
keywords: AI, Docker, Model Runner, MCP Toolkit, Docker Cloud, AI agents, application development
5+
summary: |
6+
Learn how to create AI agent applications using Docker Model Runner, MCP Toolkit, and Docker Cloud.
7+
params:
8+
tags: [AI]
9+
time: 30 minutes
10+
---
11+
12+
## Introduction
13+
14+
Agentic applications are transforming how software gets built. These apps don't
15+
just respond, they decide, plan, and act. They're powered by models,
16+
orchestrated by agents, and integrated with APIs, tools, and services in real
17+
time.
18+
19+
All these new agentic applications, no matter what they do, share a common
20+
architecture. It's a new kind of stack, built from three core components:
21+
22+
- Models: These are your GPTs, CodeLlamas, Mistrals. They're doing the
23+
reasoning, writing, and planning. They're the engine behind the intelligence.
24+
25+
- Agent: This is where the logic lives. Agents take a goal, break it down, and
26+
figure out how to get it done. They orchestrate everything. They talk to the
27+
UI, the tools, the model, and the gateway.
28+
29+
- MCP gateway: This is what links your agents to the outside world, including
30+
APIs, tools, and services. It provides a standard way for agents to call
31+
capabilities via the Model Context Protocol (MCP).
32+
33+
Docker makes this AI-powered stack simpler, faster, and more secure by unifying
34+
models, tool gateways, and cloud infrastructure into a developer-friendly
35+
workflow that uses Docker Compose.
36+
37+
![A diagram of the agentic stack](./images/agentic-ai-diagram.webp)
38+
39+
This guide walks you through the core components of agentic development and
40+
shows how Docker ties them all together with the following tools:
41+
42+
- [Docker Model Runner](../manuals/ai/model-runner/_index.md) lets you run LLMs
43+
locally with simple command and OpenAI-compatible APIs.
44+
- [Docker MCP Catalog and
45+
Toolkit](../manuals/ai/mcp-catalog-and-toolkit/_index.md) helps you discover
46+
and securely run external tools, like APIs and databases, using the Model
47+
Context Protocol (MCP).
48+
- [Docker MCP Gateway](/ai/mcp-gateway/) lets you orchestrate and manage MCP servers.
49+
- [Docker Cloud](/cloud/) provides a powerful, GPU-accelerated
50+
environment to run your AI applications with the same Compose-based
51+
workflow you use locally.
52+
- [Docker Compose](../manuals/compose/_index.md) is the tool that ties it all
53+
together, letting you define and run multi-container applications with a
54+
single file.
55+
56+
For this guide, you'll start by running the app in Docker Cloud, using the same
57+
Compose workflow you're already familiar with. Then, if your machine hardware
58+
supports it, you'll run the same app locally using the same workflow. Finally,
59+
you'll dig into the Compose file and app to see how it all works together.
60+
61+
## Prerequisites
62+
63+
To follow this guide, you need:
64+
65+
- [Docker Desktop 4.43 or later installed](../get-started/get-docker.md)
66+
- [Docker Model Runner enabled](/ai/model-runner/#enable-dmr-in-docker-desktop)
67+
- [Docker Cloud Beta joined](/cloud/get-started/)
68+
69+
## Step 1: Clone the sample application
70+
71+
You'll use an existing sample application that demonstrates how to connect a
72+
model to an external tool using Docker's AI features. This app is designed to
73+
run locally using Docker Compose, and it can also be run in Docker Cloud using
74+
the same workflow.
75+
76+
```console
77+
$ git clone https://github.com/docker/compose-agents-demo.git
78+
$ cd compose-agents-demo/adk/
79+
```
80+
81+
## Step 2: Run the application in Docker Cloud
82+
83+
If your local machine doesn't meet the hardware requirements to run the model,
84+
or if you prefer to leverage cloud resources, Docker Cloud provides a fully
85+
managed environment to build and run containers using the Docker tools you're
86+
already familiar with. This includes support for GPU-accelerated instances,
87+
making it ideal for compute-intensive workloads like AI model inference.
88+
89+
To run the application in Docker Cloud, follow these steps:
90+
91+
1. Sign in to the Docker Desktop Dashboard.
92+
2. In a terminal, start Docker Cloud by running the following command:
93+
```console
94+
$ docker cloud start
95+
```
96+
97+
When prompted, choose the account you want to use for Docker Cloud and select
98+
**Yes** when prompted **Do you need GPU support?**.
99+
100+
3. In the `adk/` directory of the cloned repository, run the following command
101+
in a terminal to build and run the application:
102+
103+
```console
104+
$ docker compose up
105+
```
106+
107+
The model is very large. The first time you run this command,
108+
Docker pulls the model from Docker Hub, which may take some time.
109+
110+
The application is now running in Docker Cloud. Note that the Compose workflow
111+
is the same when using Docker Cloud as it is locally. You define your
112+
application in a `compose.yaml` file, and then use `docker compose up` to build
113+
and run it.
114+
115+
4. Visit [http://localhost:8080](http://localhost:8080). Enter something in the
116+
prompt and hit enter. An agent searches DuckDuckGo and another agent revises
117+
the output.
118+
119+
![Screenshot of the application](./images/agentic-ai-app.png)
120+
121+
5. Press ctrl-c in the terminal to stop the application when you're done.
122+
123+
6. Run the following command to stop Docker Cloud:
124+
125+
```console
126+
$ docker cloud stop
127+
```
128+
129+
## Step 3: Optional. Run the application locally
130+
131+
If your machine meets the necessary hardware requirements, you can run the
132+
entire application stack locally using Docker Compose. This lets you test the
133+
application end-to-end, including the model and MCP gateway, without needing to
134+
run in the cloud. This particular example uses the 27B parameter Gemma 3 model,
135+
which is designed to run on high-end hardware.
136+
137+
Hardware requirements:
138+
- VRAM: 18.78GiB
139+
- Storage: 16.04GB
140+
141+
If your machine does not meet these requirements, you may still be able to run
142+
the application, but you will need update your `compose.yaml` file to use a
143+
smaller model which won't perform as well, such as `ai/gemma3-qat:4B-Q4_K_M`.
144+
145+
To run the application locally, follow these steps:
146+
147+
1. In the `adk/` directory of the cloned repository, run the following command in a
148+
terminal to build and run the application:
149+
150+
```console
151+
$ docker compose up
152+
```
153+
154+
The model is very large. The first time you run this command, Docker pulls the
155+
model from Docker Hub, which may take some time.
156+
157+
2. Visit [http://localhost:8080](http://localhost:8080). Enter something in the
158+
prompt and hit enter. An agent searches DuckDuckGo and another agent revises the
159+
output.
160+
161+
3. Press ctrl-c in the terminal to stop the application when you're done.
162+
163+
## Step 4: Review the application environment
164+
165+
The app is defined using Docker Compose, with three services:
166+
167+
- An `adk` web app service that talks to the MCP gateway and the local model
168+
- A `docker-model-runner` service that runs the model
169+
- An `mcp-gateway` service that manages tool execution via MCP
170+
171+
You can find the `compose.yaml` file in the `adk/` directory. Open it in a text
172+
editor to see how the services are defined. Comments have been added to the
173+
instructions below to help you understand each line.
174+
175+
```yaml
176+
services:
177+
adk:
178+
build:
179+
context: .
180+
ports:
181+
# expose port for web interface
182+
- "8080:8080"
183+
environment:
184+
# point adk at the MCP gateway
185+
- MCPGATEWAY_ENDPOINT=http://mcp-gateway:8811/sse
186+
depends_on:
187+
# model_runner provider starts first then injects environment variables
188+
# MODEL_RUNNER_MODEL name
189+
# MODEL_RUNNER_URL OpenAI compatible API endpoint
190+
- model_runner
191+
192+
model_runner:
193+
provider:
194+
type: model
195+
options:
196+
# pre-pull the model when starting Docker Model Runner
197+
model: ai/gemma3-qat:27B-Q4_K_M
198+
# increase context size to handle search results
199+
context-size: 20000
200+
201+
mcp-gateway:
202+
# agents_gateway secures your MCP servers
203+
image: docker/agents_gateway:v2
204+
ports:
205+
- "8811:8811"
206+
command:
207+
- --transport=sse
208+
# add any MCP servers you want to use
209+
- --servers=duckduckgo
210+
volumes:
211+
# mount docker socket to run MCP containers
212+
- /var/run/docker.sock:/var/run/docker.sock
213+
```
214+
215+
The first notable element here is the `provider` section that specifies `type:
216+
model`, which lets Docker Compose know to use the Docker Model Runner component.
217+
The `options` section defines the specific model to run, in this case,
218+
[`ai/gemma3-qat:27B-Q4_K_M`](https://hub.docker.com/r/ai/gemma3-qat).
219+
220+
> [!TIP]
221+
>
222+
> Looking for more models to use? Check out the [Docker AI Model
223+
> Catalog](https://hub.docker.com/catalogs/models/).
224+
225+
The second notable element is `image: docker/agents_gateway:v2`, which indicates
226+
that the MCP gateway service will use the [docker/agents_gateway:v2
227+
image](https://hub.docker.com/r/docker/agents_gateway). This image is Docker's
228+
open source [MCP Gateway](https://github.com/docker/docker-mcp/) that enables
229+
your application to connect to MCP servers, which expose tools that models can
230+
call. In this example, it uses the [`duckduckgo` MCP
231+
server](https://hub.docker.com/mcp/server/duckduckgo/overview) to perform web
232+
searches.
233+
234+
> [!TIP]
235+
>
236+
> Looking for more MCP servers to use? Check out the [Docker MCP
237+
> Catalog](https://hub.docker.com/catalogs/mcp/).
238+
239+
Those two components, the Docker Model Runner and the MCP gateway, are the
240+
core of the agentic stack. They let you run models locally and connect them to
241+
external tools and services using the Model Context Protocol.
242+
243+
## Step 5: Review the application
244+
245+
The `adk` web application is an agent implementation that connects to the MCP
246+
gateway and a local model through environment variables and API calls. It uses
247+
the [ADK (Agent Development Kit)](https://github.com/google/adk-python) to
248+
define a root agent named Auditor, which coordinates two sub-agents, Critic and
249+
Reviser, to verify and refine model-generated answers.
250+
251+
The three agents are:
252+
253+
- Critic: Verifies factual claims using the toolset, such as DuckDuckGo.
254+
- Reviser: Edits answers based on the verification verdicts provided by the Critic.
255+
- Auditor: A higher-level agent that sequences the
256+
Critic and Reviser. It acts as the entry point, evaluating LLM-generated
257+
answers, verifying them, and refining the final output.
258+
259+
All of the application's behavior is defined in Python under the `agents/`
260+
directory. Here's a breakdown of the notable files:
261+
262+
- `agents/agent.py`: Defines the Auditor, a SequentialAgent that chains together
263+
the Critic and Reviser agents. This agent is the main entry point of the
264+
application and is responsible for auditing LLM-generated content using
265+
real-world verification tools.
266+
267+
- `agents/sub_agents/critic/agent.py`: Defines the Critic agent. It loads the
268+
language model (via Docker Model Runner), sets the agent’s name and behavior,
269+
and connects to MCP tools (like DuckDuckGo).
270+
271+
- `agents/sub_agents/critic/prompt.py`: Contains the Critic prompt, which
272+
instructs the agent to extract and verify claims using external tools.
273+
274+
- `agents/sub_agents/critic/tools.py`: Defines the MCP toolset configuration,
275+
including parsing `mcp/` strings, creating tool connections, and handling MCP
276+
gateway communication.
277+
278+
- `agents/sub_agents/reviser/agent.py`: Defines the Reviser agent, which takes
279+
the Critic’s findings and minimally rewrites the original answer. It also
280+
includes callbacks to clean up the LLM output and ensure it's in the right
281+
format.
282+
283+
- `agents/sub_agents/reviser/prompt.py`: Contains the Reviser prompt, which
284+
instructs the agent to revise the answer text based on the verified claim
285+
verdicts.
286+
287+
The MCP gateway is configured via the `MCPGATEWAY_ENDPOINT` environment
288+
variable. In this case, `http://mcp-gateway:8811/sse`. This allows the app to
289+
use Server-Sent Events (SSE) to communicate with the MCP gateway container,
290+
which itself brokers access to external tool services like DuckDuckGo.
291+
292+
## Summary
293+
294+
Agent-based AI applications are emerging as a powerful new software
295+
architecture. In this guide, you explored a modular, chain-of-thought system
296+
where an Auditor agent coordinates the work of a Critic and a Reviser to
297+
fact-check and refine model-generated answers. This architecture shows how to
298+
combine local model inference with external tool integrations in a structured,
299+
modular way.
300+
301+
You also saw how Docker simplifies this process by providing a suite of tools
302+
that support local and cloud-based agentic AI development:
303+
304+
- [Docker Model Runner](../manuals/ai/model-runner/_index.md): Run and serve
305+
open-source models locally via OpenAI-compatible APIs.
306+
- [Docker MCP Catalog and
307+
Toolkit](../manuals/ai/mcp-catalog-and-toolkit/_index.md): Launch and manage
308+
tool integrations that follow the Model Context Protocol (MCP) standard.
309+
- [Docker MCP Gateway](/ai/mcp-gateway/): Orchestrate and manage
310+
MCP servers to connect agents to external tools and services.
311+
- [Docker Compose](../manuals/compose/_index.md): Define and run multi-container
312+
applications with a single file, using the same workflow locally and in the
313+
cloud.
314+
- [Docker Cloud](/cloud/): Run GPU-intensive AI workloads in a secure, managed
315+
cloud environment using the same Docker Compose workflow you use locally.
316+
317+
With these tools, you can develop and test agentic AI applications efficiently,
318+
locally or in the cloud, using the same consistent workflow throughout.
72.8 KB
Loading
46.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)