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/servers-and-cloud-computing/ai-agent-on-cpu/agent-output.md
+27-16Lines changed: 27 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: Understand and test the AI Agent
2
+
title: Explore and Test Your AI Agent
3
3
weight: 5
4
4
5
5
### FIXED, DO NOT MODIFY
@@ -8,11 +8,13 @@ layout: learningpathall
8
8
9
9
## AI Agent Function Calls
10
10
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.
12
12
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`.
14
14
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:
- Next, you define a provider that leverages the `llama.cpp` Python bindings.
29
+
Now define a provider that leverages the `llama.cpp` Python bindings:
27
30
```output
28
31
provider = LlamaCppPythonProvider(llama_model)
29
32
```
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.
30
36
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`:
32
38
33
39
```output
34
40
def open_webpage():
@@ -86,16 +92,19 @@ def calculator(
86
92
else:
87
93
raise ValueError("Unknown operation.")
88
94
```
95
+
#### Create Output Settings to Enable Function Calls
89
96
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:
- 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:
99
108
```
100
109
user = input("Please write your prompt here: ")
101
110
@@ -111,15 +120,15 @@ result = llama_cpp_agent.get_chat_response(
111
120
)
112
121
```
113
122
114
-
## Test the AI Agent
123
+
## Test and Run the AI Agent
115
124
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:
117
126
118
127
```bash
119
128
python3 agent.py
120
129
```
121
130
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:
123
132
124
133
```output
125
134
llama_kv_cache_init: CPU KV buffer size = 1252.00 MiB
@@ -142,9 +151,11 @@ Please write your prompt here:
142
151
143
152
## Test the AI agent
144
153
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?`
146
157
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:
148
159
149
160
```output
150
161
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
181
192
- "arguments": Put the arguments to pass to the function here.
182
193
```
183
194
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:
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.
201
212
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.
Copy file name to clipboardExpand all lines: content/learning-paths/servers-and-cloud-computing/ai-agent-on-cpu/ai-agent-backend.md
+2-3Lines changed: 2 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ layout: learningpathall
7
7
---
8
8
9
9
## 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:
11
11
12
12
Create a Python file named `agent.py` with the content shown below:
13
13
```bash
@@ -19,7 +19,6 @@ from llama_cpp_agent.chat_history.messages import Roles
19
19
from llama_cpp_agent.llm_output_settings import LlmStructuredOutputSettings
20
20
from llama_cpp_agent import LlamaCppFunctionTool
21
21
from llama_cpp_agent import FunctionCallingAgent
22
-
from llama_cpp_agent import MessagesFormatterType
23
22
from llama_cpp_agent import LlamaCppAgent
24
23
from llama_cpp_agent.providers import LlamaCppPythonProvider
25
24
from llama_cpp import Llama
@@ -156,5 +155,5 @@ def run_web_search_agent():
156
155
if __name__ == '__main__':
157
156
run_web_search_agent()
158
157
```
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.
Copy file name to clipboardExpand all lines: content/learning-paths/servers-and-cloud-computing/ai-agent-on-cpu/ai-agent.md
+20-18Lines changed: 20 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,39 +8,41 @@ layout: learningpathall
8
8
9
9
## Overview of AI Agents
10
10
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.
12
12
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:
17
14
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.
22
24
23
25
24
26
25
27
## Types of AI Agents
26
28
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:
28
30
29
-
|**Agent Category**|**Key Characteristics**|**Example usage in a Travel system**|
31
+
|**Agent Category**|**Key Characteristics**|**Example Usage in a Travel Booking System**|
|**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. |
32
34
|**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. |
34
36
|**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. |
35
37
|**Learning Agents**| Adapt over time by integrating lessons from previous feedback or experiences. | Adjusts future booking suggestions based on traveler satisfaction surveys. |
36
38
|**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. |
38
40
39
41
40
42
## Ideal Applications for AI Agents
41
43
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:
43
45
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