Skip to content

Commit 46f49d9

Browse files
authored
Merge pull request #3489 from anupras-mohapatra-arm/cross-platform
Visualizing CPU orchestration for local AI agent LP documentation review
2 parents ce96135 + 4656bdf commit 46f49d9

7 files changed

Lines changed: 150 additions & 85 deletions

File tree

content/learning-paths/cross-platform/ai-agent-cpu-orchestration/1-overview.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
2-
title: Understand the agent and the CPU/GPU split
2+
title: Understand the agent and how work is split between CPU and GPU
3+
description: See how a local Ollama AI concierge agent on Arm splits search, web I/O, text processing, and model reasoning between the CPU and GPU.
34
weight: 2
45

56
### FIXED, DO NOT MODIFY
67
layout: learningpathall
78
---
89

9-
## What you'll build
10+
## What you will run
1011

11-
In this Learning Path, you'll build and run a *local concierge agent*: a terminal application that answers research-style questions, such as finding restaurants, comparing products, or summarizing a topic, by searching the web, reading multiple pages, and writing a fact-checked summary.
12-
13-
Everything runs on your own Arm machine. The agent uses an LLM served locally by [Ollama](https://ollama.com/), so your prompts and the pages you browse never leave the device. The same code runs on an Apple silicon MacBook, an Arm Linux laptop, or an NVIDIA DGX Spark.
12+
You'll run a local concierge agent: a terminal application that answers research-style questions, such as finding restaurants, comparing products, or summarizing a topic. The agent answers these questions by searching the web, reading multiple pages, and writing a fact-checked summary.
1413

14+
You'll run everything on your local Arm machine. The agent uses an LLM served locally by [Ollama](https://ollama.com/), so your prompts and the pages you browse never leave the device. The same code runs on an Apple silicon MacBook, an Arm Linux laptop, or an NVIDIA DGX Spark.
1515

1616
The agent is interesting not just because it runs locally, but because of *how the work is divided*. A common assumption is that an AI agent is "just the model." In practice, the model is only one stage in a longer pipeline, and most of the surrounding work runs on the CPU.
1717

@@ -30,7 +30,7 @@ Your question
3030
-> Write a fact-checked summary (GPU: model reasoning)
3131
```
3232

33-
The model is called several times, but between every model call the CPU does a large amount of orchestration: generating query variants, dispatching parallel network requests, merging and deduplicating results, scoring pages for relevance, and extracting structured data.
33+
The model is called several times, but between every model call, the CPU does a large amount of orchestration. The CPU generates query variants, dispatches parallel network requests, merges and deduplicates results, scores pages for relevance, and extracts structured data.
3434

3535
## Why the CPU matters in an agentic workflow
3636

@@ -43,7 +43,8 @@ It's easy to focus only on token generation, because that's the visible "thinkin
4343
| Web I/O | CPU | Calling the search API, downloading and parsing web pages |
4444
| Text processing | CPU | TF-IDF ranking, deduplication, entity extraction, indexing |
4545

46-
This division is a natural fit for Arm platforms. On an Apple silicon MacBook or an Arm Linux machine, the CPU handles all orchestration and I/O while the GPU accelerates the model. On an NVIDIA DGX Spark, the Arm CPU coordinates the workflow while the GPU runs inference. In every case, the model is only as good as the context the CPU prepares for it.
46+
This division is a natural fit for Arm platforms. On an Apple silicon MacBook or an Arm Linux machine, the CPU handles all orchestration and I/O and the GPU accelerates the model.
47+
On an NVIDIA DGX Spark, the Arm CPU coordinates the workflow while the GPU runs inference. In every case, the model is only as good as the context the CPU prepares for it.
4748

4849
## How the agent shows you the split
4950

@@ -56,6 +57,8 @@ The program is instrumented so you can see this division directly. As it runs, i
5657

5758
By the end of this Learning Path, you'll be able to look at a single query and see exactly how much of the work happened on the CPU before and after the model produced its answer.
5859

59-
## What's next
60+
## What you've learned and what's next
61+
62+
You've now learned about the agent you'll build and the role the CPU plays in orchestrating the agent's workflow.
6063

61-
In the next section, you'll set up your environment: create a Python virtual environment, install the required packages, and get a Serper API key for web search.
64+
Next, you'll set up your environment: create a Python virtual environment, install the required packages, and get a Serper API key for web search.

content/learning-paths/cross-platform/ai-agent-cpu-orchestration/2-setup.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
---
2-
title: Set up your environment
2+
title: Set up your environment before running the agent
3+
description: Set up a Python virtual environment, Serper API key, required packages, and the concierge agent script before running the local AI agent on Arm.
34
weight: 3
45

56
### FIXED, DO NOT MODIFY
67
layout: learningpathall
78
---
89

9-
## Set up your environment
10+
## Install and configure prerequisites for the agent
1011

11-
In this section, you'll prepare everything the agent needs before running it: a Serper API key for web search, a Python virtual environment, the required packages, and the agent script itself.
12+
Prepare the following before running the agent: a Serper API key for web search, a Python virtual environment, the required packages, and the agent script.
1213

1314
These steps are identical on an Apple silicon MacBook, an Arm Linux machine, and an NVIDIA DGX Spark.
1415

15-
## Create a project directory and virtual environment
16+
### Create a project directory and virtual environment
1617

1718
A virtual environment keeps the agent's dependencies isolated from your system Python, so you always run against the right package versions.
1819

@@ -30,9 +31,9 @@ python3 -m venv .venv
3031
source .venv/bin/activate
3132
```
3233

33-
Your shell prompt now shows `(.venv)`, which confirms the environment is active.
34+
Your shell prompt will now show `(.venv)`, which confirms the environment is active.
3435

35-
## Install the required packages
36+
### Install the required packages
3637

3738
The agent uses `requests` for HTTP calls and `beautifulsoup4` to parse web pages.
3839

@@ -47,21 +48,21 @@ pip install requests beautifulsoup4
4748
The agent searches the web through [Serper](https://serper.dev/), a Google Search API. The free tier is enough to complete this Learning Path.
4849

4950
1. Go to [serper.dev](https://serper.dev/) and create a free account.
50-
2. Once logged in, you will see the dashboard. On the left, click **API Keys**.
51+
2. After logging in, you'll see the dashboard. On the left, select **API Keys**.
5152
3. Copy the Default key.
5253
4. Export your API key as an environment variable in the same terminal session as your virtual environment:
5354

54-
```bash
55-
export SERPER_API_KEY="your-serper-api-key"
56-
```
55+
```bash
56+
export SERPER_API_KEY="your-serper-api-key"
57+
```
5758

5859
{{% notice Tip %}}
5960
This variable only lasts for the current terminal session. To keep it across sessions, add the same line to your shell profile, for example `~/.zshrc` on macOS or `~/.bashrc` on Linux.
6061
{{% /notice %}}
6162

62-
## Download the agent script
63+
### Download the agent script
6364

64-
Download the complete agent script, <a href="/learning-paths/cross-platform/ai-agent-cpu-orchestration/concierge_agent.py" download>concierge_agent.py</a>, and move it into your `concierge-agent` directory. You'll run it at the end of this Learning Path, and the next sections walk through how the important parts work.
65+
Download the complete agent script <a href="/learning-paths/cross-platform/ai-agent-cpu-orchestration/concierge_agent.py" download>concierge_agent.py</a>, and move it into your `concierge-agent` directory.
6566

6667
Alternatively, download it directly from the command line:
6768

@@ -75,4 +76,8 @@ Confirm the file is in your project directory:
7576
ls concierge_agent.py
7677
```
7778

78-
With the environment ready and the script in place, the next step is to serve a model locally with Ollama.
79+
## What you've accomplished and what's next
80+
81+
You've now obtained and set a Serper API key, created a virtual environment, and downloaded the agent script.
82+
83+
Next, you'll serve the model locally with Ollama.

content/learning-paths/cross-platform/ai-agent-cpu-orchestration/3-ollama.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
title: Serve a model locally with Ollama
3+
description: Install Ollama, pull Gemma 3, and verify the local model endpoint before connecting it to the Arm-based concierge agent.
34
weight: 4
45

56
### FIXED, DO NOT MODIFY
@@ -8,15 +9,15 @@ layout: learningpathall
89

910
## Run AI models locally with Ollama
1011

11-
The agent's reasoning steps, such as choosing search terms, selecting URLs, and writing the final summary, are handled by an LLM. Instead of calling a cloud API, this Learning Path serves the model locally with [Ollama](https://ollama.com/).
12+
The agent's reasoning steps, such as choosing search terms, selecting URLs, and writing the final summary, are handled by an LLM. Instead of calling a cloud API, you'll serve the model locally with [Ollama](https://ollama.com/).
1213

13-
Ollama is a lightweight runtime that downloads open models, loads them into memory, and exposes a local HTTP API at `http://localhost:11434`. When the agent calls that endpoint, the model runs directly on your machine: the CPU and GPU on your MacBook, Arm Linux laptop, or NVIDIA DGX Spark. Nothing is sent to an external service or cloud.
14+
Ollama is a lightweight runtime that downloads open models, loads them into memory, and exposes a local HTTP API at `http://localhost:11434`. When the agent calls that endpoint, the model runs directly on your machine: the CPU and GPU on your MacBook, Arm Linux laptop, or NVIDIA DGX Spark.
1415

1516
Running locally has three benefits that matter for an agent:
1617

17-
- **Privacy**: your prompts and the web content the agent reads stay on the device.
18-
- **Cost**: there are no per-token API charges, so you can run many queries freely.
19-
- **Control**: you choose the exact model and keep it resident in memory for fast repeated calls.
18+
- Privacy: your prompts and the web content the agent reads stay on the device.
19+
- Cost: there are no per-token API charges, so you can run many queries freely.
20+
- Control: you choose the exact model and keep it resident in memory for fast repeated calls.
2021

2122
## Install and start Ollama
2223

@@ -50,7 +51,7 @@ With the install script, `ollama serve` runs in the foreground. Keep that termin
5051

5152
## Pull the Gemma model
5253

53-
This Learning Path uses [Gemma 3](https://ai.google.dev/gemma), Google's family of open models, in its 4-billion-parameter size (`gemma3:4b`). This size is a good default: it's capable enough for the agent's reasoning steps and small enough to run on a laptop.
54+
You'll use [Gemma 3](https://ai.google.dev/gemma), Google's family of open models. The 4-billion-parameter size (`gemma3:4b`) is a good default: it's capable enough for the agent's reasoning steps and small enough to run on a laptop.
5455

5556
Download the model:
5657

@@ -66,7 +67,7 @@ ollama list
6667

6768
You'll see `gemma3:4b` in the list of installed models.
6869

69-
## Choose a different model (optional)
70+
## (Optional) Choose a different model
7071

7172
The agent reads the model name from the `OLLAMA_MODEL` environment variable, so you can switch models without editing the code. The default in the script is `gemma3:4b`.
7273

@@ -75,7 +76,9 @@ The agent reads the model name from the `OLLAMA_MODEL` environment variable, so
7576
| `gemma3:4b` | 4B | Laptops and modest hardware; the default |
7677
| `gemma3:27b` | 27B | High-memory systems such as DGX Spark, for stronger reasoning |
7778

78-
To use a larger model on a DGX Spark, pull it and set the environment variable before running the agent:
79+
To use a larger model on a DGX Spark, pull it and set the environment variable before running the agent.
80+
81+
For example, to use a model with 27 billion parameters:
7982

8083
```bash
8184
ollama pull gemma3:27b
@@ -102,4 +105,8 @@ Summarize what a local AI agent does in one sentence.
102105

103106
Type `/bye` to exit the model session.
104107

105-
With Ollama serving `gemma3:4b`, you're ready to look at how the agent code uses it.
108+
## What you've accomplished and what's next
109+
110+
You've now set up Ollama, served a Google `gemma3:4b` model locally, and tested the model.
111+
112+
Next, you'll look at how the agent code uses the model.

content/learning-paths/cross-platform/ai-agent-cpu-orchestration/4-code-walkthrough.md

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
2-
title: Walk through the agent code
2+
title: Understand the concierge agent code
3+
description: Review the concierge agent code to see where web search, page scraping, Ollama model calls, and CPU orchestration happen in the workflow.
34
weight: 5
45

56
### FIXED, DO NOT MODIFY
@@ -8,18 +9,18 @@ layout: learningpathall
89

910
## How the code is organized
1011

11-
The `concierge_agent.py` script you downloaded earlier is organized into four parts. This section walks through the important pieces so you understand what runs on the CPU, what runs on the GPU, and how the agent chains them together.
12+
The `concierge_agent.py` script you downloaded earlier is organized into four parts. You'll understand what runs on the CPU, what runs on the GPU, and how the agent chains them together.
1213

1314
| Part | Responsibility | Runs on |
1415
|---|---|---|
15-
| Part 1: Tools | Web search, page scraping, optional email | CPU |
16-
| Part 2: The brain | Calls the local Gemma model through Ollama | GPU |
17-
| Part 3: Orchestration pipeline | Query expansion, parallelism, ranking, deduplication, extraction | CPU |
18-
| Part 4: The agentic chain | Ties everything together into one query workflow | CPU + GPU |
16+
| Tools | Web search, page scraping, optional email | CPU |
17+
| The brain | Calls the local Gemma model through Ollama | GPU |
18+
| Orchestration pipeline | Query expansion, parallelism, ranking, deduplication, extraction | CPU |
19+
| The agentic chain | Ties everything together into one query workflow | CPU + GPU |
1920

20-
## Part 1: The tools
21+
### The tools
2122

22-
The tools are the agent's connection to the outside world. `search_web()` calls the Serper API and returns the top five results; `browse_website()` downloads a page and strips it down to clean text. Both run entirely on the CPU and both log their activity with `log_cpu()`:
23+
The tools are the agent's connection to the outside world. `search_web()` calls the Serper API and returns the top five results. `browse_website()` downloads a page and strips it down to clean text. Both run entirely on the CPU and both log their activity with `log_cpu()`:
2324

2425
```python
2526
def search_web(query: str) -> str:
@@ -36,7 +37,7 @@ def browse_website(url: str) -> str:
3637

3738
`browse_website()` uses BeautifulSoup to remove `<script>` and `<style>` tags, collapse whitespace, and cap the result at 8,000 characters so a single large page can't dominate the pipeline.
3839

39-
## Part 2: The brain
40+
### The brain
4041

4142
A single function, `call_gemma_ollama()`, is the only place the model is used. It sends a prompt to the local Ollama API and streams the response back token by token:
4243

@@ -53,16 +54,16 @@ def call_gemma_ollama(prompt, output_format="json", timing=None,
5354
...
5455
```
5556

56-
Two details are worth highlighting:
57+
Two details are worth noting:
5758

5859
- `keep_alive: -1` tells Ollama to keep the model resident in memory between calls. The agent calls the model several times per query, so this avoids reloading the weights each time.
5960
- The function records timing as it streams. The time until the *first* token arrives is the model's input-token processing (prefill); the time spent streaming the rest is token generation. Separating these two values is what lets the agent show you the GPU breakdown later.
6061

6162
Because every model call goes through this one function, the agent only ever uses the GPU in clearly marked places.
6263

63-
## Part 3: The CPU orchestration pipeline
64+
### The CPU orchestration pipeline
6465

65-
Between the model calls, the CPU prepares the context. Each stage below runs entirely on the CPU:
66+
Between the model calls, the CPU prepares the context. Each of the following stages runs entirely on the CPU:
6667

6768
| Stage | Function | What it does |
6869
|---|---|---|
@@ -74,14 +75,18 @@ Between the model calls, the CPU prepares the context. Each stage below runs ent
7475
| Extract data | `extract_entities()` | Pulls out phone numbers, hours, and prices |
7576
| Build index | `build_keyword_index()` | Indexes the most frequent terms |
7677

77-
## Part 4: The agentic chain
78+
### The agentic chain
7879

79-
`run_concierge_agent()` ties the pipeline together. Reading it top to bottom shows how CPU and GPU steps alternate:
80+
`run_concierge_agent()` ties the pipeline together. When you read the function from top to bottom, you can see how CPU and GPU steps alternate:
8081

81-
1. **GPU**`call_gemma_ollama()` turns your question into a search query.
82-
2. **CPU**`generate_search_queries()` and `parallel_search()` expand and run the searches.
83-
3. **GPU** – the model selects which URLs to open.
84-
4. **CPU**`parallel_browse()`, `rank_and_filter_content()`, `deduplicate_sentences()`, `extract_entities()`, and the indexing stages prepare the context.
85-
5. **GPU** – the model writes the final, fact-checked summary.
82+
1. GPU – `call_gemma_ollama()` turns your question into a search query.
83+
2. CPU – `generate_search_queries()` and `parallel_search()` expand and run the searches.
84+
3. GPU – the model selects which URLs to open.
85+
4. CPU – `parallel_browse()`, `rank_and_filter_content()`, `deduplicate_sentences()`, `extract_entities()`, and the indexing stages prepare the context.
86+
5. GPU – the model writes the final, fact-checked summary.
8687

87-
Now that you understand the structure, you'll run the agent and watch the CPU and GPU work in real time.
88+
## What you've learned and what's next
89+
90+
You've now learned about the structure of the agent code and what functions work on the CPU and the GPU respectively.
91+
92+
Next, you'll run the agent and watch the CPU and GPU work in real time.

content/learning-paths/cross-platform/ai-agent-cpu-orchestration/5-run-and-examples.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
---
22
title: Run the agent and read the timeline
3+
description: Run the local concierge agent, ask research questions, and interpret the CPU and GPU timing breakdown produced for each query.
34
weight: 6
45

56
### FIXED, DO NOT MODIFY
67
layout: learningpathall
78
---
89

9-
## Run the agent
10+
## Start the agent
1011

11-
Make sure both pieces are in place before you start:
12+
Make sure the following are in place before you start:
1213

13-
- Ollama is running and serving `gemma3:4b` (from the previous section).
14+
- Ollama is running and serving `gemma3:4b`.
1415
- Your virtual environment is active and `SERPER_API_KEY` is set in the current terminal.
1516

1617
From your project directory, start the agent:
@@ -39,7 +40,7 @@ Type a question that benefits from searching and reading several pages. For exam
3940
Find three highly rated ramen restaurants in San Francisco that are open late
4041
```
4142

42-
As the agent works, watch the log lines. Cyan `[CPU]` lines show orchestration and web I/O; yellow `[GPU]` lines show each model call:
43+
As the agent works, watch the log lines. Cyan <code style="color:#00aaaa"><strong>[CPU]</strong></code> lines show orchestration and web I/O; yellow <code style="color:#aaaa00"><strong>[GPU]</strong></code> lines show each model call:
4344

4445
```output
4546
[GPU] Thinking with local Gemma model...
@@ -71,17 +72,17 @@ GPU total: 4.991s
7172

7273
These numbers separate the three kinds of work:
7374

74-
- **CPU operations** – every orchestration and text-processing stage combined.
75-
- **GPU input token processing** – the time the model spends reading each prompt before producing output (prefill).
76-
- **GPU token generation** – the time spent writing the answers.
75+
- `CPU operations` – every orchestration and text-processing stage combined.
76+
- `GPU input token processing` – the time the model spends reading each prompt before producing output (prefill).
77+
- `GPU token generation` – the time spent writing the answers.
7778

7879
{{% notice Note %}}
7980
Your exact numbers depend on your hardware, the model size, and how many pages the agent reads. The point isn't the absolute values, but the fact that CPU work is a substantial share of every query.
8081
{{% /notice %}}
8182

8283
## Read the timeline
8384

84-
Below the breakdown, the agent prints a text-based timeline. Each character is a slice of wall-clock time, color-coded by what was active:
85+
The agent also prints a text-based timeline. Each character is a slice of wall-clock time, color-coded by what was active:
8586

8687
```output
8788
CCCCCCCPGGGGCCCCCCCCCCCCCCPGGGGGGGGCCCCCCCCCCCCCCCCCCCPGGGGGGGGGGGG
@@ -111,4 +112,8 @@ The screenshot shows example queries and the answers the agent returns:
111112

112113
Type `quit` or `exit` to end the session.
113114

114-
In the next section, you'll look more closely at why the CPU does so much of the work in an agentic workflow.
115+
## What you've accomplished and what's next
116+
117+
You've now started the agent and asked questions to see how query response steps are split between the CPU and the GPU.
118+
119+
Next, you'll learn why the CPU does so much of the work in an agentic workflow.

0 commit comments

Comments
 (0)