Skip to content

Commit 9c995ec

Browse files
authored
Merge pull request #1740 from madeline-underwood/agentic
Agentic_Andy to review
2 parents 63be7d4 + 32629ba commit 9c995ec

File tree

5 files changed

+78
-62
lines changed

5 files changed

+78
-62
lines changed

content/learning-paths/servers-and-cloud-computing/ai-agent-on-cpu/_index.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
---
2-
title: Run an AI Agent Application with llama.cpp and llama-cpp-agent using KleidiAI on Arm servers.
3-
4-
draft: true
5-
cascade:
6-
draft: true
2+
title: Deploy an AI Agent on Arm with llama.cpp and llama-cpp-agent using KleidiAI
73

84
minutes_to_complete: 45
95

10-
who_is_this_for: This is an introductory topic for software developers and ML engineers looking to run an AI Agent Application.
6+
who_is_this_for: This is an introductory topic for software developers and ML engineers looking to deploy an optimized AI agent application.
117

128
learning_objectives:
13-
- Set up llama-cpp-python optimised for Arm servers.
14-
- Learn how to run optimized LLM models.
15-
- Learn how to create custom functions for LLMs.
16-
- Learn how to use AI Agents for applications.
9+
- Set up llama-cpp-python optimized for Arm servers.
10+
- Run optimized Large Language Models (LLMs).
11+
- Create custom functions for LLMs.
12+
- Deploy optimized AI agents for applications.
1713

1814
prerequisites:
1915
- An [Arm-based instance](/learning-paths/servers-and-cloud-computing/csp/) from a cloud service provider or an on-premise Arm server.
20-
- Basic understanding of Python and Prompt Engineering
16+
- Basic understanding of Python and Prompt Engineering.
2117
- Understanding of LLM fundamentals.
2218

2319
author: Andrew Choi
@@ -30,6 +26,7 @@ armips:
3026
tools_software_languages:
3127
- Python
3228
- AWS Graviton
29+
- AI
3330
operatingsystems:
3431
- Linux
3532

content/learning-paths/servers-and-cloud-computing/ai-agent-on-cpu/agent-output.md

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Understand and test the AI Agent
2+
title: Explore and Test Your AI Agent
33
weight: 5
44

55
### FIXED, DO NOT MODIFY
@@ -8,11 +8,13 @@ layout: learningpathall
88

99
## AI Agent Function Calls
1010

11-
An AI agent, powered by a Large Language Model (LLM), decides which function to use by analyzing the prompt or input it receives, identifying the relevant intent or task, and then matching that intent to the most appropriate function from a pre-defined set of available functions based on its understanding of the language and context.
11+
An AI agent, powered by an LLM, selects the most appropriate function by analyzing the input, identifying the relevant intent, and matching it to predefined functions based on its understanding of the language and context.
1212

13-
Lets look at how this is implemented in the python script `agent.py`.
13+
You will now walk through how this is implemented in the excerpt from a Python script called `agent.py`.
1414

15-
- This code section of `agent.py` shown below creates an instance of the quantized `llama3.1 8B` model for more efficient inference on Arm-based systems.
15+
#### Initialize the Quantized Model
16+
17+
This code section of `agent.py` shown below creates an instance of the quantized `llama3.1 8B` model for more efficient inference on Arm-based systems:
1618
```output
1719
llama_model = Llama(
1820
model_path="./models/dolphin-2.9.4-llama3.1-8b-Q4_0.gguf",
@@ -22,13 +24,17 @@ llama_model = Llama(
2224
n_threads_batch=64,
2325
)
2426
```
27+
#### Define a Provider
2528

26-
- Next, you define a provider that leverages the `llama.cpp` Python bindings.
29+
Now define a provider that leverages the `llama.cpp` Python bindings:
2730
```output
2831
provider = LlamaCppPythonProvider(llama_model)
2932
```
33+
#### Define Functions
34+
35+
The LLM has access to certain tools or functions and can take a general user input and decide which functions to call. The function’s docstring guides the LLM on when and how to invoke it.
3036

31-
- The LLM has access to certain tools or functions and can take a general user input and decide which functions to call. The function’s docstring guides the LLM on when and how to invoke it. In `agent.py` three such tools or functions are defined `open_webpage`, `get_current_time` and `calculator`
37+
In `agent.py` three such tools or functions are defined; `open_webpage`, `get_current_time`, and `calculator`:
3238

3339
```output
3440
def open_webpage():
@@ -86,16 +92,19 @@ def calculator(
8692
else:
8793
raise ValueError("Unknown operation.")
8894
```
95+
#### Create Output Settings to Enable Function Calls
8996

90-
- `from_functions` creates an instance of `LlmStructuredOutputSettings` by passing in a list of callable Python functions. The LLM can then decide if and when to use these functions based on user queries.
97+
`from_functions` creates an instance of `LlmStructuredOutputSettings` by passing in a list of callable Python functions. The LLM can then decide if and when to use these functions based on user queries:
9198

9299
```output
93100
output_settings = LlmStructuredOutputSettings.from_functions(
94101
[get_current_time, open_webpage, calculator], allow_parallel_function_calling=True
95102
)
96103
97104
```
98-
- The user's prompt is then collected and processed through `LlamaCppAgent`. The agent decides whether to call any defined functions based on the request.
105+
#### Collect and Process User Input
106+
107+
The user's prompt is then collected and processed through `LlamaCppAgent`. The agent decides whether to call any defined functions based on the request:
99108
```
100109
user = input("Please write your prompt here: ")
101110
@@ -111,15 +120,15 @@ result = llama_cpp_agent.get_chat_response(
111120
)
112121
```
113122

114-
## Test the AI Agent
123+
## Test and Run the AI Agent
115124

116-
You are now ready to test and execute the AI Agent python script. Start the application:
125+
You're now ready to test and run the AI agent Python script. Start the application:
117126

118127
```bash
119128
python3 agent.py
120129
```
121130

122-
You will see lots of interesting statistics being printed from `llama.cpp` about the model and the system, followed by the prompt as shown:
131+
You will see lots of interesting statistics being printed from `llama.cpp` about the model and the system, followed by the prompt for input, as shown:
123132

124133
```output
125134
llama_kv_cache_init: CPU KV buffer size = 1252.00 MiB
@@ -142,9 +151,11 @@ Please write your prompt here:
142151

143152
## Test the AI agent
144153

145-
When you are presented with "Please write your prompt here:" test it with an input prompt. Enter "What is the current time?"
154+
When you are presented with `Please write your prompt here:` test it with an input prompt.
155+
156+
Enter `What is the current time?`
146157

147-
- As part of the prompt, a list of executable functions is sent to the LLM, allowing the agent to select the appropriate function:
158+
As part of the prompt, a list of executable functions is sent to the LLM, allowing the agent to select the appropriate function:
148159

149160
```output
150161
Read and follow the instructions below:
@@ -181,7 +192,7 @@ To call a function, respond with a JSON object (to call one function) or a list
181192
- "arguments": Put the arguments to pass to the function here.
182193
```
183194

184-
The AI Agent then decides to invoke the appropriate function and return the result as shown:
195+
The AI agent then decides to invoke the appropriate function and returns the result as shown:
185196

186197
```output
187198
[
@@ -197,9 +208,9 @@ Response from AI Agent:
197208
----------------------------------------------------------------
198209
```
199210

200-
You have now tested when you enter, "What is the current time?", the AI Agent will choose to call the `get_current_time()` function, and return a result in **H:MM AM/PM** format.
211+
You have now tested the `What is the current time?` question. The AI agent evaluates the query and calls the `get_current_time()` function, and returns a result in **H:MM AM/PM** format.
201212

202-
You have successfully run an AI agent. You can ask different questions to trigger and execute other functions. You can extend your AI agent by defining custom functions so it can handle specific tasks.
213+
You have successfully run and tested your AI agent. Experiment with different prompts or define custom functions to expand your AI agent's capabilities.
203214

204215

205216

content/learning-paths/servers-and-cloud-computing/ai-agent-on-cpu/ai-agent-backend.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ layout: learningpathall
77
---
88

99
## Python Script for executing an AI Agent application
10-
With `llama.cpp` built and the Llama3.1 8B model downloaded, you are now ready to create a Python script to execute an AI Agent Application:
10+
With `llama.cpp` built and the Llama3.1 8B model downloaded, you are now ready to create a Python script to execute an AI agent application:
1111

1212
Create a Python file named `agent.py` with the content shown below:
1313
```bash
@@ -19,7 +19,6 @@ from llama_cpp_agent.chat_history.messages import Roles
1919
from llama_cpp_agent.llm_output_settings import LlmStructuredOutputSettings
2020
from llama_cpp_agent import LlamaCppFunctionTool
2121
from llama_cpp_agent import FunctionCallingAgent
22-
from llama_cpp_agent import MessagesFormatterType
2322
from llama_cpp_agent import LlamaCppAgent
2423
from llama_cpp_agent.providers import LlamaCppPythonProvider
2524
from llama_cpp import Llama
@@ -156,5 +155,5 @@ def run_web_search_agent():
156155
if __name__ == '__main__':
157156
run_web_search_agent()
158157
```
159-
In the next section, you will inspect this script to understand how the LLM is configured and used to execute Agent tasks using this script. You will then proceed to executing and testing the AI Agent.
158+
In the next section, you will inspect this script to understand how the LLM is configured and used to execute agent tasks. You will then proceed to executing and testing the AI agent.
160159

content/learning-paths/servers-and-cloud-computing/ai-agent-on-cpu/ai-agent.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,41 @@ layout: learningpathall
88

99
## Overview of AI Agents
1010

11-
An AI Agent is best understood as an integrated system that goes beyond standard text generation by equipping Large Language Models (LLMs) with tools and domain knowledge. Here’s a closer look at the underlying elements:
11+
An AI agent is an integrated system that extends beyond basic text generation by augmenting Large Language Models (LLMs) with tools and domain knowledge.
1212

13-
- **System**: Each AI Agent functions as an interconnected ecosystem of components.
14-
- **Environment**: The domain in which the AI Agent operates. For instance, in a system that books travel itineraries, the relevant environment might include airline reservation systems and hotel booking tools.
15-
- **Sensors**: Methods the AI Agent uses to observe its surroundings. For a travel agent, these could be APIs that inform the agent about seat availability on flights or room occupancy in hotels.
16-
- **Actuators**: Ways the AI Agent exerts influence within that environment. In the example of a travel agent, placing a booking or modifying an existing reservation serves as the agent’s “actuators.”
13+
Here’s a closer look at the underlying elements:
1714

18-
- **Large Language Models**: While the notion of agents is not new, LLMs bring powerful language comprehension and data-processing capabilities to agent setups.
19-
- **Performing Actions**: Rather than just produce text, LLMs within an agent context interpret user instructions and interact with tools to achieve specific objectives.
20-
- **Tools**: The agent’s available toolkit depends on the software environment and developer-defined boundaries. In the travel agent example, these tools might be limited to flight and hotel reservation APIs.
21-
- **Knowledge**: Beyond immediate data sources, the agent can fetch additional details—perhaps from databases or web services—to enhance decision making.
15+
- **System**: Each AI agent functions as an interconnected ecosystem of components. Below is a list of key factors and components that affect system performance:
16+
- **Environment**: The domain in which the AI agent operates. For instance, in a system that books travel itineraries, this might include airline reservation systems and hotel booking tools.
17+
- **Sensors**: The methods the AI agent uses to observe its environment. For a travel agent, these might be APIs that inform the agent about seat availability on flights or room occupancy in hotels.
18+
- **Actuators**: Ways the AI agent exerts influence within the environment. In the example of a travel agent, placing a booking or modifying an existing reservation illustrates how actuators function to enact changes within the environment.
19+
20+
- **Large Language Models**: While agents have long existed, LLMs enhance these systems with powerful language comprehension and data-processing capabilities.
21+
- **Action Execution**: Rather than just produce text, LLMs within an agent context interpret user instructions and interact with tools to achieve specific objectives.
22+
- **Tools**: The agent’s available toolkit depends on the software environment and developer-defined boundaries. In the travel agent example in this Learning Path, these tools might be limited to flight and hotel reservation APIs.
23+
- **Knowledge**: Beyond immediate data sources, the agent can fetch additional details - perhaps from databases or web services - for enhanced decision-making.
2224

2325

2426

2527
## Types of AI Agents
2628

27-
AI Agents come in multiple forms. The table below provides an overview of some agent types and examples illustrating their roles in a travel booking system:
29+
AI agents come in multiple forms. The table below provides an overview of some agent types and examples of their roles in a travel booking system:
2830

29-
| **Agent Category** | **Key Characteristics** | **Example usage in a Travel system** |
31+
| **Agent Category** | **Key Characteristics** | **Example Usage in a Travel Booking System** |
3032
|--------------------------|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
31-
| **Simple Reflex Agents** | Act directly based on set rules or conditions. | Filters incoming messages and forwards travel-related emails to a service center. |
33+
| **Simple Reflex Agents** | Act directly based on predefined rules or conditions. | Filters incoming messages and forwards travel-related emails to a service center. |
3234
| **Model-Based Agents** | Maintain an internal representation of the world and update it based on new inputs. | Monitors flight prices and flags dramatic fluctuations, guided by historical data. |
33-
| **Goal-Based Agents** | Execute actions with the aim of meeting designated objectives. | Figures out the necessary route (flights, transfers) to get from your current location to your target destination. |
35+
| **Goal-Based Agents** | Execute actions with the aim of meeting designated objectives. | Determines the necessary route (flights, transfers) to get from your current location to your target destination. |
3436
| **Utility-Based Agents** | Use scoring or numerical metrics to compare and select actions that fulfill a goal. | Balances cost versus convenience when determining which flights or hotels to book. |
3537
| **Learning Agents** | Adapt over time by integrating lessons from previous feedback or experiences. | Adjusts future booking suggestions based on traveler satisfaction surveys. |
3638
| **Hierarchical Agents** | Split tasks into sub-tasks and delegate smaller pieces of work to subordinate agents.| Cancels a trip by breaking down the process into individual steps, such as canceling a flight, a hotel, and a car rental. |
37-
| **Multi-Agent Systems** | Involve multiple agents that may cooperate or compete to complete tasks. | Cooperative: Different agents each manage flights, accommodations, and excursions. Competitive: Several agents vie for limited rooms. |
39+
| **Multi-Agent Systems** | Involve multiple agents that might cooperate or compete to complete tasks. | Cooperative: Different agents each manage flights, accommodations, and excursions. Competitive: Several agents vie for limited rooms. |
3840

3941

4042
## Ideal Applications for AI Agents
4143

42-
While the travel scenario illustrates different categories of AI Agents, there are broader circumstances where agents truly excel:
44+
AI agents come in multiple forms. They can be grouped into various categories and excel in a wide range of applications:
4345

44-
- **Open-Ended Challenges**: Complex tasks with no predetermined procedure, requiring the agent to determine the necessary steps.
45-
- **Procedural or Multi-Step Tasks**: Endeavors requiring numerous phases or tool integrations, allowing the agent to switch between resources.
46-
- **Continual Improvement**: Contexts where feedback loops enable the agent to refine its behaviors for better outcomes in the future.
46+
- **Open-Ended Challenges**: Complex tasks with no predetermined procedure, requiring the agent to determine its own steps.
47+
- **Procedural or Multi-Step Tasks**: Tasks involving multiple phases or tool integrations that enable the agent to switch between resources.
48+
- **Continual Improvement**: Contexts where feedback loops enable the agent to refine its behavior for better outcomes.

0 commit comments

Comments
 (0)