Skip to content

Commit 2cfe0dc

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

File tree

3 files changed

+314
-0
lines changed

3 files changed

+314
-0
lines changed

content/guides/agentic-ai.md

Lines changed: 314 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,314 @@
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 Cloud](/cloud/) provides a powerful, GPU-accelerated
49+
environment to run your AI applications with the same Compose-based
50+
workflow you use locally.
51+
- [Docker Compose](../manuals/compose/_index.md) is the tool that ties it all
52+
together, letting you define and run multi-container applications with a
53+
single file.
54+
55+
For this guide, you'll start by running the app in Docker Cloud, using the same
56+
Compose workflow you're already familiar with. Then, if your machine hardware
57+
supports it, you'll run the same app locally using the same workflow. Finally,
58+
you'll dig into the Compose file and app to see how it all works together.
59+
60+
## Prerequisites
61+
62+
To follow this guide, you need:
63+
64+
- [Docker Desktop 4.43 or later installed](../get-started/get-docker.md)
65+
- [Docker Model Runner enabled](/ai/model-runner/#enable-dmr-in-docker-desktop)
66+
- [Docker Cloud Beta joined](/cloud/get-started/)
67+
68+
## Step 1: Clone the sample application
69+
70+
You'll use an existing sample application that demonstrates how to connect a
71+
model to an external tool using Docker's AI features. This app is designed to
72+
run locally using Docker Compose, and it can also be run in Docker Cloud using
73+
the same workflow.
74+
75+
```console
76+
$ git clone https://github.com/docker/compose-agents-demo.git
77+
$ cd compose-agents-demo/adk/
78+
```
79+
80+
## Step 2: Run the application in Docker Cloud
81+
82+
If your local machine doesn't meet the hardware requirements to run the model,
83+
or if you prefer to leverage cloud resources, Docker Cloud provides a fully
84+
managed environment to build and run containers using the Docker tools you're
85+
already familiar with. This includes support for GPU-accelerated instances,
86+
making it ideal for compute-intensive workloads like AI model inference.
87+
88+
To run the application in Docker Cloud, follow these steps:
89+
90+
1. Sign in to the Docker Desktop Dashboard.
91+
2. In a terminal, start Docker Cloud by running the following command:
92+
```console
93+
$ docker cloud start
94+
```
95+
96+
When prompted, choose the account you want to use for Docker Cloud and select
97+
**Yes** when prompted **Do you need GPU support?**.
98+
99+
3. In the `adk/` directory of the cloned repository, run the following command
100+
in a terminal to build and run the application:
101+
102+
```console
103+
$ docker compose up
104+
```
105+
106+
The model is very large. The first time you run this command,
107+
Docker pulls the model from Docker Hub, which may take some time.
108+
109+
The application is now running in Docker Cloud. Note that the Compose workflow
110+
is the same when using Docker Cloud as it is locally. You define your
111+
application in a `compose.yaml` file, and then use `docker compose up` to build
112+
and run it.
113+
114+
4. Visit [http://localhost:8080](http://localhost:8080). Enter something in the
115+
prompt and hit enter. An agent searches DuckDuckGo and another agent revises the
116+
output.
117+
118+
![Screenshot of the application](./images/agentic-ai-app.png)
119+
120+
5. Press ctrl-c in the terminal to stop the application when you're done.
121+
122+
6. Run the following command to stop Docker Cloud:
123+
124+
```console
125+
$ docker cloud stop
126+
```
127+
128+
## Step 3: Optional. Run the application locally
129+
130+
If your machine meets the necessary hardware requirements, you can run the
131+
entire application stack locally using Docker Compose. This lets you test the
132+
application end-to-end, including the model and MCP gateway, without needing to
133+
run in the cloud. This particular example uses the 27B parameter Gemma 3 model,
134+
which is designed to run on high-end hardware.
135+
136+
Hardware requirements:
137+
- VRAM: 18.78GiB
138+
- Storage: 16.04GB
139+
140+
If your machine does not meet these requirements, you may still be able to run
141+
the application, but you will need update your `compose.yaml` file to use a
142+
smaller model which won't perform as well, such as `ai/gemma3-qat:4B-Q4_K_M`.
143+
144+
To run the application locally, follow these steps:
145+
146+
1. In the `adk/` directory of the cloned repository, run the following command in a
147+
terminal to build and run the application:
148+
149+
```console
150+
$ docker compose up
151+
```
152+
153+
The model is very large. The first time you run this command, Docker pulls the
154+
model from Docker Hub, which may take some time.
155+
156+
2. Visit [http://localhost:8080](http://localhost:8080). Enter something in the
157+
prompt and hit enter. An agent searches DuckDuckGo and another agent revises the
158+
output.
159+
160+
3. Press ctrl-c in the terminal to stop the application when you're done.
161+
162+
## Step 4: Review the application environment
163+
164+
The app is defined using Docker Compose, with three services:
165+
166+
- An `adk` web app service that talks to the MCP gateway and the local model
167+
- A `docker-model-runner` service that runs the model
168+
- An `mcp-gateway` service that manages tool execution via MCP
169+
170+
You can find the `compose.yaml` file in the `adk/` directory. Open it in a text
171+
editor to see how the services are defined. Comments have been added to the
172+
instructions below to help you understand each line.
173+
174+
```yaml
175+
services:
176+
adk:
177+
build:
178+
context: . # Build from the current directory
179+
dockerfile: Dockerfile # Use the specified Dockerfile
180+
ports:
181+
- "8080:8080" # Map host port 8080 to container port 8080
182+
environment:
183+
- MCPGATEWAY_ENDPOINT=http://mcp-gateway:8811/sse # Tell the app where to find the MCP gateway
184+
command: ["web"] # Start the ADK web interface
185+
extra_hosts:
186+
- host.docker.internal:host-gateway # Allow container to reach the host machine
187+
depends_on:
188+
- docker-model-runner # Ensure model service starts before this
189+
- mcp-gateway # Ensure gateway service starts before this
190+
191+
docker-model-runner:
192+
provider:
193+
type: model # Use Docker Model Runner to serve a model
194+
options:
195+
model: ai/gemma3-qat:27B-Q4_K_M # Specify the model to run (27B Gemma3 QAT)
196+
environment:
197+
- LLAMA_ARGS=--ctx-size 20000 --jinja -ngl 100 # Runtime options for the model engine
198+
199+
mcp-gateway:
200+
image: docker/agents_gateway:v2 # Run Docker's MCP gateway service
201+
ports:
202+
- "8811:8811" # Expose the gateway on port 8811
203+
command:
204+
- --transport=sse # Use SSE (Server-Sent Events) for agent communication
205+
- --servers=duckduckgo # Enable DuckDuckGo tool server for web search
206+
volumes:
207+
- /var/run/docker.sock:/var/run/docker.sock # Allow gateway to interact with Docker on host
208+
209+
```
210+
211+
The first notable element here is the `provider` section that specifies `type:
212+
model`, which lets Docker Compose know to use the Docker Model Runner component.
213+
The `options` section defines the specific model to run, in this case,
214+
[`ai/gemma3-qat:27B-Q4_K_M`](https://hub.docker.com/r/ai/gemma3-qat).
215+
216+
> [!TIP]
217+
>
218+
> Looking for more models to use? Check out the [Docker AI Model
219+
> Catalog](https://hub.docker.com/catalogs/models/).
220+
221+
The second notable element is `image: docker/agents_gateway:v2`, which indicates
222+
that the MCP gateway service will use the [docker/agents_gateway:v2
223+
image](https://hub.docker.com/r/docker/agents_gateway). This image is Docker's
224+
[open source MCP gateway](https://github.com/docker/docker-mcp/) that enables your application to connect to MCP servers,
225+
which expose tools that models can call. In this example, it uses the
226+
[`duckduckgo` MCP server](https://hub.docker.com/mcp/server/duckduckgo/overview)
227+
to perform web searches.
228+
229+
> [!TIP]
230+
>
231+
> Looking for more MCP servers to use? Check out the [Docker MCP
232+
> Catalog](https://hub.docker.com/catalogs/mcp/).
233+
234+
Those two components, the Docker Model Runner and the MCP gateway, are the
235+
core of the agentic stack. They let you run models locally and connect them to
236+
external tools and services using the Model Context Protocol.
237+
238+
## Step 5: Review the application
239+
240+
The `adk` web application is an agent implementation that connects to the MCP
241+
gateway and a local model through environment variables and API calls. It uses
242+
the [ADK (Agent Development Kit)](https://github.com/google/adk-python) to
243+
define two agents that evaluate responses, verify claims, and revise answers.
244+
These agents load a language model (served via Docker Model Runner) and connect
245+
to external tools using the Model Context Protocol (MCP).
246+
247+
The `adk` web application is an agent implementation that connects to the MCP
248+
gateway and a local model through environment variables and API calls. It uses
249+
the [ADK (Agent Development Kit)](https://github.com/google/adk-python) to
250+
define a root agent named Auditor, which coordinates two sub-agents, Critic and
251+
Reviser, to verify and refine model-generated answers.
252+
253+
The three agents are:
254+
255+
- Critic: Verifies factual claims using the toolset, such as DuckDuckGo.
256+
- Reviser: Edits answers based on the verification verdicts provided by the Critic.
257+
- Auditor: A higher-level agent that sequences the
258+
Critic and Reviser. It acts as the entry point, evaluating LLM-generated
259+
answers, verifying them, and refining the final output.
260+
261+
All of the application's behavior is defined in Python under the `agents/`
262+
directory. Here's a breakdown of the notable files:
263+
264+
- `agents/agent.py`: Defines the Auditor, a SequentialAgent that chains together
265+
the Critic and Reviser agents. This agent is the main entry point of the
266+
application and is responsible for auditing LLM-generated content using
267+
real-world verification tools.
268+
269+
- `agents/sub_agents/critic/agent.py`: Defines the Critic agent. It loads the
270+
language model (via Docker Model Runner), sets the agent’s name and behavior,
271+
and connects to MCP tools (like DuckDuckGo).
272+
273+
- `agents/sub_agents/critic/prompt.py`: Contains the Critic prompt, which
274+
instructs the agent to extract and verify claims using external tools.
275+
276+
- `agents/sub_agents/critic/tools.py`: Defines the MCP toolset configuration,
277+
including parsing `mcp/` strings, creating tool connections, and handling MCP
278+
gateway communication.
279+
280+
- `agents/sub_agents/reviser/agent.py`: Defines the Reviser agent, which takes
281+
the Critic’s findings and minimally rewrites the original answer. It also
282+
includes callbacks to clean up the LLM output and ensure it's in the right
283+
format.
284+
285+
- `agents/sub_agents/reviser/prompt.py`: Contains the Reviser prompt, which
286+
instructs the agent to revise the answer text based on the verified claim
287+
verdicts.
288+
289+
The MCP gateway is configured via the `MCPGATEWAY_ENDPOINT` environment
290+
variable. In this case, `http://mcp-gateway:8811/sse`. This allows the app to
291+
use Server-Sent Events (SSE) to communicate with the MCP gateway container,
292+
which itself brokers access to external tool services like DuckDuckGo.
293+
294+
## Summary
295+
296+
This guide demonstrated how to build an agentic AI application using Docker's
297+
suite of tools:
298+
299+
- [Docker Model Runner](../manuals/ai/model-runner/_index.md): Run and serve
300+
open-source models locally via OpenAI-compatible APIs.
301+
- [Docker MCP Catalog and
302+
Toolkit](../manuals/ai/mcp-catalog-and-toolkit/_index.md): Launch and manage
303+
tool integrations that follow the Model Context Protocol (MCP) standard.
304+
- [Docker Cloud](/cloud/): Deploy and scale your application
305+
in a secure, managed cloud environment.
306+
307+
By leveraging these tools, you can develop, build, and test agentic AI applications
308+
efficiently and securely, using the same Docker Compose workflow you already
309+
know.
310+
311+
The ADK-based agent structure used here demonstrates how to build modular,
312+
chain-of-thought style agentic applications. In this case, an Auditor agent
313+
sequences a Critic and Reviser to perform factual verification and revision of
314+
model-generated answers.
72.8 KB
Loading
46.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)