logologo
  • AI Interviewer
  • Features
  • Jobs
  • AI Tools
  • FAQs
logologo

Transform your hiring process with AI-powered interviews. Screen candidates faster and make better hiring decisions.

Useful Links

  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Refund & Cancellation
  • About Us

Resources

  • Certifications
  • Topics
  • Collections
  • Articles
  • Services

AI Tools

  • AI Interviewer
  • Xperto AI
  • AI Pre-Screening

Procodebase © 2025. All rights reserved.

Level Up Your Skills with Xperto-AI

A multi-AI agent platform that helps you level up your development skills and ace your interview preparation to secure your dream job.

Launch Xperto-AI

Building Your First Basic Agent Using Phidata Framework

author
Generated by
ProCodebase AI

12/01/2025

generative-ai

Sign in to read full article

Introduction

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.

Prerequisites

Before we dive in, make sure you have:

  1. Python 3.7 or later installed
  2. An OpenAI API key
  3. Basic familiarity with Python programming

Setting Up Your Environment

First, let's set up our project environment:

  1. Create a new directory for your project:

    mkdir my_first_agent cd my_first_agent
  2. Create a virtual environment and activate it:

    python -m venv venv source venv/bin/activate

On Windows, use venv\Scripts\activate


3. Install Phidata:
```bash
pip install phidata

Creating Your First Agent

Now that we have our environment set up, let's create our first agent:

  1. Create a new Python file named my_agent.py:
    from phi.llm.openai import OpenAIChat from phi.agent import Agent

Initialize the OpenAI chat model

llm = OpenAIChat(model="gpt-3.5-turbo")

Define our agent

my_agent = Agent( name="MyFirstAgent", description="A helpful assistant that can answer questions and provide information.", llm=llm, tools=[],

We'll leave this empty for now

)

Run the agent

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
  1. Run your agent:
    python my_agent.py

Congratulations! You've just created and run your first AI agent using Phidata.

Understanding the Code

Let's break down what's happening in our my_agent.py file:

  1. We import the necessary components from Phidata.
  2. We initialize an OpenAIChat instance, which will be our language model.
  3. We create an Agent instance, giving it a name, description, and the language model to use.
  4. We call the run method on our agent with a simple question.

Enhancing Your Agent

Now that we have a basic agent, let's add some capabilities:

  1. 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], )
  2. 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!

Experimenting Further

Here are some ideas to expand your agent's capabilities:

  1. Add more tools, such as a calculator or a weather API.
  2. Implement memory to allow your agent to remember previous interactions.
  3. Create a simple chat interface to interact with your agent.

Conclusion

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!

Popular Tags

generative-aiphidataai-agents

Share now!

Like & Bookmark!

Related Collections

  • CrewAI Multi-Agent Platform

    27/11/2024 | Generative AI

  • Generative AI: Unlocking Creative Potential

    31/08/2024 | Generative AI

  • Mastering Vector Databases and Embeddings for AI-Powered Apps

    08/11/2024 | Generative AI

  • Advanced Prompt Engineering

    28/09/2024 | Generative AI

  • Intelligent AI Agents Development

    25/11/2024 | Generative AI

Related Articles

  • Best Practices for Text Preprocessing in Embedding Generation

    08/11/2024 | Generative AI

  • Unleashing the Power of Retrieval Augmented Generation in AI Agents

    25/11/2024 | Generative AI

  • Navigating the Frontiers of Advanced Reasoning in Generative AI

    25/11/2024 | Generative AI

  • Mastering the Art of Testing and Debugging Multi-Agent Systems in CrewAI

    27/11/2024 | Generative AI

  • Building an AI Agent from Scratch

    09/05/2025 | Generative AI

  • Understanding Text Embeddings and Vector Representations in AI

    08/11/2024 | Generative AI

  • Real-world Applications of Generative AI

    27/11/2024 | Generative AI

Popular Category

  • Python
  • Generative AI
  • Machine Learning
  • ReactJS
  • System Design