You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/learning-paths/cross-platform/ai-agent-cpu-orchestration/4-code-walkthrough.md
+15-78Lines changed: 15 additions & 78 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,9 +13,9 @@ The `concierge_agent.py` script you downloaded earlier is organized into four pa
13
13
| Part | Responsibility | Runs on |
14
14
|---|---|---|
15
15
| Part 1: Tools | Web search, page scraping, optional email | CPU |
16
-
| Part 1.5: Orchestration pipeline | Query expansion, parallelism, ranking, deduplication, extraction | CPU |
17
16
| Part 2: The brain | Calls the local Gemma model through Ollama | GPU |
18
-
| Part 3: The agentic chain | Ties everything together into one query workflow | CPU + 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 |
19
19
20
20
## Part 1: The tools
21
21
@@ -58,67 +58,23 @@ Two details are worth highlighting:
58
58
-`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.
59
59
- 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.
60
60
61
-
Because every model call goes through this one function, the agent only ever uses the GPU in clearly marked places. Everything else is CPU work.
61
+
Because every model call goes through this one function, the agent only ever uses the GPU in clearly marked places.
62
62
63
-
## Part 1.5: The CPU orchestration pipeline
63
+
## Part 3: The CPU orchestration pipeline
64
64
65
-
This is the heart of the Learning Path. Between the model calls, the CPU transforms a single user request into rich, structured context. Each function below is a distinct CPU stage.
65
+
Between the model calls, the CPU prepares the context. Each stage below runs entirely on the CPU:
66
66
67
-
### Expand one query into several
68
-
69
-
A single search query rarely covers a topic well, so the CPU expands it into variants before searching:
Network requests are slow, so the CPU runs them concurrently with a thread pool instead of one at a time. The same pattern is used for searching and for browsing:
with concurrent.futures.ThreadPoolExecutor(max_workers=min(len(urls), 10)) as executor:
85
-
future_to_url = {executor.submit(browse_website, url): url for url in urls}
86
-
...
87
-
```
88
-
89
-
This is a good example of orchestration: the CPU coordinates up to ten simultaneous downloads, then collects the results as each thread finishes.
90
-
91
-
### Rank pages by relevance
92
-
93
-
Not every page the agent opens is useful. The CPU scores each page against the user's goal using TF-IDF (term frequency–inverse document frequency) and sorts them so the most relevant content reaches the model first:
| Extract data |`extract_entities()`| Pulls out phone numbers, hours, and prices |
75
+
| Build index |`build_keyword_index()`| Indexes the most frequent terms |
120
76
121
-
## Part 3: The agentic chain
77
+
## Part 4: The agentic chain
122
78
123
79
`run_concierge_agent()` ties the pipeline together. Reading it top to bottom shows how CPU and GPU steps alternate:
124
80
@@ -128,23 +84,4 @@ aggregated_text = (
128
84
4.**CPU** – `parallel_browse()`, `rank_and_filter_content()`, `deduplicate_sentences()`, `extract_entities()`, and the indexing stages prepare the context.
129
85
5.**GPU** – the model writes the final, fact-checked summary.
130
86
131
-
A small helper, `time_cpu()`, wraps each CPU stage to measure how long it takes and record it on the timeline:
The matching GPU timing is captured inside `call_gemma_ollama()`. Together they produce the timeline and the timing breakdown you'll see when you run the agent in the next section.
145
-
146
-
{{% notice Note %}}
147
-
The script also contains an `send_email()` tool and commented-out email steps. They're disabled by default so the workflow stays focused on research. You can re-enable them later by configuring the `SMTP_*` environment variables and uncommenting the email steps.
148
-
{{% /notice %}}
149
-
150
87
Now that you understand the structure, you'll run the agent and watch the CPU and GPU work in real time.
Reading left to right, you can see the pattern of an agentic query: long stretches of CPU work (`C`) for searching, browsing, and processing, punctuated by short GPU bursts where the model reads a prompt (`P`) and generates text (`G`).
95
+
Reading left to right, you can see the pattern of an agentic query: long stretches of CPU work (<codestyle="color:#00aa00"><strong>C</strong></code>) for searching, browsing, and processing, punctuated by GPU bursts where the model reads a prompt (<codestyle="color:#aa00aa"><strong>P</strong></code>) and generates text (<codestyle="color:#cc0000"><strong>G</strong></code>).
96
96
97
97
<!-- TODO: replace with a real screenshot of the colored timeline output -->
98
98

@@ -109,6 +109,10 @@ Compare the battery life of the three most recommended noise-cancelling headphon
109
109
Summarize the key differences between the latest Raspberry Pi models
110
110
```
111
111
112
+
The screenshot below shows example queries and the answers the agent returns:
113
+
114
+

115
+
112
116
Type `quit` or `exit` to end the session.
113
117
114
118
In the next section, you'll look more closely at why the CPU does so much of the work in an agentic workflow.
Copy file name to clipboardExpand all lines: content/learning-paths/cross-platform/ai-agent-cpu-orchestration/6-cpu-orchestration.md
+14-29Lines changed: 14 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,44 +6,31 @@ weight: 7
6
6
layout: learningpathall
7
7
---
8
8
9
-
## The CPU does most of the work
9
+
## How the CPU and GPU share the work
10
10
11
-
When people picture an AI agent, they usually picture the model generating text. The timeline from the previous section tells a different story: for a typical research query, the CPU is active far longer than the GPU. The model is fast and focused; the CPU does the broad, continuous work of turning one question into a useful answer.
11
+
When people picture an AI agent, they usually picture an AI model generating text using just the GPU. In practice, the model is only one stage of an agentic workflow. The CPU and GPU work in tandem, each handling the part of the workload it does best: the GPU runs the model's reasoning, while the CPU does the broad, continuous work of orchestration that turns a single request into a useful answer.
12
12
13
-
This section steps back from the code to explain *why* that happens and why it matters on Arm platforms.
13
+
This section looks at the CPU's role in agentic workflows, and why it matters on Arm platforms.
14
14
15
-
## Where the CPU time goes
15
+
## What the CPU does in an agentic workflow
16
16
17
-
Every stage between the model calls runs on the CPU. Grouped by purpose, the CPU is responsible for:
17
+
Most agentic systems share the same shape, regardless of the task. Between model calls, the CPU is responsible for the work that surrounds inference:
18
18
19
-
| Category | What the CPU does | Functions involved |
20
-
|---|---|---|
21
-
| Orchestration | Expands one query into variants, schedules parallel tasks, coordinates the workflow |`generate_search_queries`, `parallel_search`, `parallel_browse`|
22
-
| Web I/O | Calls the search API, downloads pages, parses HTML into clean text |`search_web`, `browse_website`|
23
-
| Relevance | Scores and sorts pages so the best content reaches the model |`compute_tfidf_score`, `rank_and_filter_content`|
| Structuring | Extracts entities and builds a keyword index |`extract_entities`, `build_keyword_index`|
19
+
-**Orchestration** – deciding what to do next, scheduling tasks, coordinating tools and services, and routing work between multiple AI agents and subagents.
20
+
-**Tool calls and I/O** – calling APIs, querying databases, reading files, and fetching web pages, often many at once.
21
+
-**Data preparation** – cleaning, filtering, ranking, deduplicating, and structuring raw data before it reaches the model.
22
+
-**Memory and state** – tracking conversation history, caching results, and managing context across steps.
26
23
27
-
Only after all of this does the model receive a compact, deduplicated, fact-rich prompt. The quality of the final answer depends heavily on this preparation.
28
-
29
-
## Why this matters: garbage in, garbage out
30
-
31
-
A model can only reason about the context it's given. If the agent fed every raw page directly to the model, three problems would follow:
32
-
33
-
-**Cost and latency** – long, repetitive prompts take much longer for the model to read (the input-token processing time you saw in the breakdown).
34
-
-**Lower quality** – boilerplate and duplicated text crowd out the facts that actually answer the question.
35
-
-**Hallucination risk** – without extracted, verified entities, the model is more likely to guess.
36
-
37
-
The CPU pipeline addresses all three. Parallel I/O keeps latency down, deduplication and ranking keep the prompt focused, and entity extraction gives the model concrete facts to ground its answer.
24
+
These stages are mostly classical computing: concurrency, networking, parsing, and text processing. They run continuously throughout a query, while the GPU is used in focused bursts only when the model reasons. As agents call more tools and handle more data, this CPU-side work grows.
38
25
39
26
## Why this is a good fit for Arm
40
27
41
-
The CPU work in this agent, coordinating parallel tasks, handling network I/O, and running classical text processing, is exactly the kind of broad, concurrent workload that Arm CPUs handle efficiently.
28
+
This kind of broad, concurrent orchestration and I/Ois exactly the workload Arm CPUs handle efficiently. The same pattern scales across Arm platforms:
42
29
43
-
- On an **Apple silicon MacBook** or an **Arm Linux laptop**, the same Arm CPU runs all orchestration and I/O while the integrated GPU accelerates the model. The whole agent runs on one device with no cloud dependency.
44
-
- On an **NVIDIA DGX Spark**, the Arm Grace CPU coordinates the agentic workflow while the Blackwell GPU runs inference. The division of labor in this small agent mirrors how larger AI systems are built: CPUs orchestrate, GPUs accelerate.
30
+
- On an **Apple silicon MacBook** or an **Arm Linux laptop**, the Arm CPU runs orchestration and I/O while the integrated GPU accelerates the model, so the whole agent runs on one device with no cloud dependency.
31
+
- On an **NVIDIA DGX Spark**, the Arm Grace CPU coordinates the agentic workflow while the Blackwell GPU runs inference, mirroring how larger AI systems are built: CPUs orchestrate, GPUs accelerate.
45
32
46
-
The key takeaway is that an agent is an *orchestration system*, not just an inference system. The model is one important stage, but the CPU is what turns a single question into searches, reading, ranking, and structured facts, and that orchestration is where most of the work happens.
33
+
The key takeaway is that an agent is an *orchestration system*, not just an inference system. The model is one important stage, but the CPU is what turns a single request into tool calls, data, and structured context, and that orchestration is a large part of the work.
47
34
48
35
## Experiment
49
36
@@ -63,5 +50,3 @@ You've built and run a local AI concierge agent end to end on Arm hardware, and
63
50
- Run an agentic workflow that searches, browses, ranks, deduplicates, and extracts data before each model call
64
51
- Read the timing breakdown and timeline to measure how much of each query runs on the CPU
65
52
- Connected the CPU's orchestration role to why Arm platforms suit agentic workloads
66
-
67
-
The main idea to carry forward is that an AI agent is an orchestration system: the model reasons in short bursts, while the CPU does the broad, continuous work that turns one question into a grounded answer.
0 commit comments