AWS Builder Center
Building a private agent with students using Strands Agent and Ollama

Building a private agent with students using Strands Agent and Ollama

This covers configuring a local AI agent course curriculum for a Windows environment using Ollama and Strands Agent, and utilizing Strands Agent's built-in tools.

Recently, I received a request from an acquaintance to give a special lecture on 'AI Agents' at a university course.
While considering what to teach the students, I recalled Strands Agent, which I had previously worked on at an AWS workshop. Since the content was intended for students, I had the following restrictions in mind:
  • Not affiliated with any specific company or brand.
  • To avoid incurring any costs.
  • Since the students include non-computer or programming majors, the course is designed to be understandable even to beginners.
  • Use the computer in the lab (Windows)
Since Strands Agent is an open-source project developed by AWS, I judged it to be a safe choice and received approval that it was suitable for the lecture. To satisfy the above requirements, we decided to use ollama to download and use the models, as using the cloud for LLM could incur costs.
The following content was written to inform students about the lecture and to add details. Therefore, some content and screenshots may be included in Korean.
For more information about Strands Agent, please refer to the following link.
Next, for the Python development environment, we decided to install Anaconda, which comes with basic packages installed, and configure a virtual environment.
Download Anaconda, perform a basic installation, and configure the virtual environment as follows.
1
2
3
4
5
6
7
8
9
conda env list
conda create -n agent python=3.12
conda activate agent
conda install jupyter
#After moving the drive or folder
jupyter notebook
#Deactivate and remove virtual environment
conda deactivate
conda remove -n agent --all
Now, download and install Olama, and also download the models to be used. We will use the gemma4, which supports multimodal functions.
After installing Olama, search for the model in the console window as shown below and download the desired model.
*** Since the programs and model sizes to be installed are too large, we guided you to download them in advance before the lecture.
1
ollama pull gemma4:e2b
Once the model download is complete, try using the commands below.
1
2
3
4
5
6
7
8
# Check version
ollama --version

# Run the model, chat enabled
ollama run gemma4:e2b

# Model list
ollama list
I installed the package and created the simplest example using the Ollama Agents Gemma 4 model with Python.
1
2
3
4
5
#pip install ollama

import ollama
resp = ollama.generate(model="gemma4:e2b", prompt="AWS?")
print(resp["response"])
The following response came back. It works well!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
It is the world's most comprehensive and broadly adopted cloud platform, providing a massive suite of on-demand computing, storage, database, networking, analytics, machine learning, and IoT services.

In simple terms, AWS allows individuals and businesses to rent IT infrastructure and services over the internet instead of owning and maintaining their own physical servers and data centers.

Here is a breakdown of what AWS is and why it's important:

### 1. Cloud Computing
AWS is the primary example of **cloud computing**. Instead of making large upfront capital expenditures (buying servers, cooling systems, data centers), users can access computing resources as a utility—paying only for what they use.

### 2. Core Services
AWS offers hundreds of services, but some of the most fundamental categories include:

*   **Compute:** Services like **EC2 (Elastic Compute Cloud)**, which allows users to rent virtual servers (instances) to run applications.
*   **Storage:** Services like **S3 (Simple Storage Service)**, which offers highly durable and scalable object storage for files, backups, and data.
*   **Databases:** Managed database services like **RDS (Relational Database Service)** and **DynamoDB**.
...
Now, let's install the strands-agents package and develop the simplest agent.
1
pip install strands-agents strands-agents[ollama] strands-agents-tools
Enter the prompt "Hello! Who are you? Introduce yourself."
1
2
3
4
5
6
7
8
from strands import Agent

agent = Agent(
system_prompt="You are a helpful AI assistant."
)

response = agent("Hello! 너는 누구냐? 자기 소개 해봐.")
print(response)
If you look at the code above, the model is not specified. When executed like this, the Amazon Bedrock model provider and the Claude Sonnet model are assigned by default. On my computer, the result is as shown below, but students will encounter an error.
This time, I modified it so that students could run it as well and tested it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from strands.models.ollama import OllamaModel
from strands import Agent

ollama_model = OllamaModel(
model_id="gemma4:e2b",
host="http://localhost:11434",
max_tokens=2048,
temperature=0.7,
top_p=0.9,
)

system_prompt="You are a helpful AI assistant."

local_agent = Agent(
system_prompt=system_prompt,
model=ollama_model,
)

response = local_agent("Hello! Who are you?")
print(response)
The Strands agent has various built-in tools. Let's practice using a few of them. First, let's try using the calculator.
1
2
3
4
5
6
7
8
9
10
from strands import Agent, tool
from strands_tools import calculator

local_agent = Agent(
system_prompt=system_prompt,
model=ollama_model,
tools=[calculator],
)

local_agent.tool.calculator(expression="sin(x)", mode="derive", wrt="x", order=2)
*** Unfortunately, tools such as 'shell', 'cron', and 'python_repl' cannot be used on Windows. This is likely because their process and console I/O methods are implemented based on Linux. If you need to use these tools, please use Linux or macOS.
This time, we will try using the 'generate_image' and 'image_reader' tools. The students will find it very interesting, won't they?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from strands import Agent, tool
from strands_tools import generate_image, image_reader

image_agent = Agent(
model=ollama_model,
tools=[generate_image,image_reader],
system_prompt='''
You are an assistant with image generation and analysis capabilities.
Use image_reader when a user asks about an image.
Use generate_image for image generation.
'''

)

response = image_agent("Please generate a rainbow-colored puppy image.")
print(response)
After running the code block above, the image below was created in the output folder a short while later. It's so cute!
This time, let's analyze the image file generated in reverse.
No image analysis results appeared, and I only received responses such as "the image cannot be read." What could be the problem? I spent a very long~ time modifying the prompt and editing the Python code... and finally, I found a solution!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
with open("output/a_rainbow_colored_puppy.png", "rb") as fp:
image_bytes = fp.read()

response = image_agent([
{"text": "Analyze the image file."},
{
"image": {
"format": "png",
"source": {
"bytes": image_bytes,
},
},
},
])

print(response)
The analysis results for the puppy image file came out well as shown below.
Later in the course, we will explore more built-in tools and even include examples of creating and using custom tools. However, due to time constraints, I will stop here for today.
I need to take a break before heading off to teach the students this fun agent development course. I will post again next time~.
*** The cover image is an image generated by Gemini.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article