In the rapidly evolving world of generative AI, creating intelligent agents has become more accessible than ever. The Phidata framework offers a streamlined approach to building AI agents, making it an excellent choice for beginners and experienced developers alike. In this tutorial, we'll walk through the process of creating your first basic agent using Phidata.
Before we dive in, make sure you have:
First, let's set up our project environment:
Create a new directory for your project:
mkdir my_first_agent cd my_first_agent
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate
venv\Scripts\activate
3. Install Phidata:
```bash
pip install phidata
Now that we have our environment set up, let's create our first agent:
my_agent.py
:
from phi.llm.openai import OpenAIChat from phi.agent import Agent
llm = OpenAIChat(model="gpt-3.5-turbo")
my_agent = Agent( name="MyFirstAgent", description="A helpful assistant that can answer questions and provide information.", llm=llm, tools=[],
)
my_agent.run("Hello! Can you tell me what day it is?")
2. Set your OpenAI API key as an environment variable:
```bash
export OPENAI_API_KEY=your_api_key_here
python my_agent.py
Congratulations! You've just created and run your first AI agent using Phidata.
Let's break down what's happening in our my_agent.py
file:
OpenAIChat
instance, which will be our language model.Agent
instance, giving it a name, description, and the language model to use.run
method on our agent with a simple question.Now that we have a basic agent, let's add some capabilities:
Add a tool to get the current date:
from datetime import datetime def get_current_date(): return datetime.now().strftime("%Y-%m-%d") my_agent = Agent( name="MyFirstAgent", description="A helpful assistant that can answer questions and provide the current date.", llm=llm, tools=[get_current_date], )
Run the agent with a more specific question:
my_agent.run("What is today's date?")
Now your agent can provide the current date when asked!
Here are some ideas to expand your agent's capabilities:
Building your first AI agent with Phidata is just the beginning. As you become more familiar with the framework, you'll be able to create increasingly complex and capable agents. Remember to always consider ethical implications and potential biases when developing AI systems.
Happy coding, and enjoy your journey into the world of AI agents!
12/01/2025 | Generative AI
06/10/2024 | Generative AI
24/12/2024 | Generative AI
27/11/2024 | Generative AI
28/09/2024 | Generative AI
27/11/2024 | Generative AI
08/11/2024 | Generative AI
24/12/2024 | Generative AI
25/11/2024 | Generative AI
27/11/2024 | Generative AI
12/01/2025 | Generative AI
25/11/2024 | Generative AI