Saturday, March 15, 2025

#1 - Client Agent

Agents Tutorial: Building an AI Agent with Agnos

Introduction

In this tutorial, we will explore how to build an AI agent using Agnos and integrate it with the Llama 3.2 model. We will also use YFinanceTools to fetch stock prices. By the end of this guide, you will have a working AI agent that can generate responses and fetch stock market data.

References

Hands-On Implementation

Step 1: Create a Workspace

First, create a new folder for your project:

mkdir agents && cd agents

Step 2: Create the Python Script

Inside the workspace, create a new file named client.py and add the following code:

from agno.agent import Agent, RunResponse  # noqa
from agno.models.ollama import Ollama
from agno.tools.yfinance import YFinanceTools
from ollama import Client as OllamaClient

agent = Agent(
    model=Ollama(id="llama3.2", client=OllamaClient()),
    tools=[YFinanceTools(stock_price=True)],
    markdown=True,
)

# Print the response in the terminal
agent.print_response("Share a 2 sentence joke on quantum computing")

Step 3: Set Up the Virtual Environment

To keep dependencies organized, create a virtual environment:

python3 -m venv .venv
source .venv/bin/activate  # On Windows, use `.venv\Scripts\activate`

Step 4: Install Dependencies

Install the required libraries using:

pip install -U ollama yfinance agno

Step 5: Download the Llama 3.2 Model

Before running the agent, download the Llama 3.2 model:

ollama pull llama3.2

Step 6: Run the AI Agent

Execute the script to see the agent in action:

python client.py

Expected Response

Response:

I see what happened! It looks like the "tell_joke" function is not available in this context. Let me try again:

Why did the qubit go to therapy? Because it was feeling a little "entangled"!

Conclusion

In this tutorial, we successfully: ✅ Set up an AI agent using Agnos
✅ Integrated the Llama 3.2 model
✅ Added a stock market tool with YFinanceTools
✅ Ran a test command to generate a response

For more details, visit the official Agnos Documentation. 🚀

No comments:

Post a Comment

#5 - Structured-Output

 Example 5: Structured Output  Step 1: Create structured_ouput.py from agno . agent import Agent from pydantic import BaseModel , Fiel...