logologo
  • AI Tools

    DB Query GeneratorMock InterviewResume BuilderLearning Path GeneratorCheatsheet GeneratorAgentic Prompt GeneratorCompany ResearchCover Letter Generator
  • XpertoAI
  • MVP Ready
  • Resources

    CertificationsTopicsExpertsCollectionsArticlesQuestionsVideosJobs
logologo

Elevate Your Coding with our comprehensive articles and niche collections.

Useful Links

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

Resources

  • Xperto-AI
  • Certifications
  • Python
  • GenAI
  • Machine Learning

Interviews

  • DSA
  • System Design
  • Design Patterns
  • Frontend System Design
  • ReactJS

Procodebase © 2024. 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

  • Mastering Multi-Agent Systems with Phidata

    12/01/2025 | Generative AI

  • Intelligent AI Agents Development

    25/11/2024 | Generative AI

  • Mastering Vector Databases and Embeddings for AI-Powered Apps

    08/11/2024 | Generative AI

  • LLM Frameworks and Toolkits

    03/12/2024 | Generative AI

  • Building AI Agents: From Basics to Advanced

    24/12/2024 | Generative AI

Related Articles

  • Unlocking Semantic Search

    08/11/2024 | Generative AI

  • Building Your First AI Agent

    24/12/2024 | Generative AI

  • Advancing AI Agent Testing and Validation

    25/11/2024 | Generative AI

  • Enhancing AI Capabilities

    12/01/2025 | Generative AI

  • Developing Robust Agent Testing and Validation Frameworks for Generative AI

    12/01/2025 | Generative AI

  • Basic Agent Types in AutoGen

    27/11/2024 | Generative AI

  • Advanced Agent Types in AutoGen

    27/11/2024 | Generative AI

Popular Category

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