Building AI Agents with Phidata

Last Updated : 11 Jun, 2026

Phidata is a framework for building intelligent AI agents for specific tasks. It lets developers combine multiple specialized agents into one efficient system for structured and scalable problem solving.

  • Multiple agents are created, each with a specific role.
  • One agent can gather information from the internet.
  • Another agent can analyze financial data and provide insights.
  • All agents are combined to work together as one cohesive system.

Implementaion

Step 1: Install required libraries

Run the following command in your command prompt

pip install phidata google-generativeai duckduckgo-search

Step 2: Set API Key

  • To use Gemini model, you’ll need a Gemini API Key.
  • We configure Gemini API using environment variables.
Python
import os
os.environ["GOOGLE_API_KEY"] = "your api key"

Step 3: Import Required Libraries

Python
from phi.agent import Agent
from phi.model.google import Gemini
from phi.tools.duckduckgo import DuckDuckGo
import warnings

warnings.filterwarnings("ignore")  

Step 4: Create AI Agent

Python
agent = Agent(
    model=Gemini(id="gemini-2.5-flash"),   
    tools=[DuckDuckGo()],                 
    instructions=[
        "Provide clear and concise answers",
        "Use web search when needed",
        "Always include sources in the answer",
        "Give final answer properly formatted"
    ],
    markdown=True
)

Step 5: Run a Query

Python
response = agent.run("Give latest news about Tesla with sources")
print(response.content)

Output:

Here's the latest news about Tesla:

* **Elon Musk Says Tesla Is Making Something Cooler Than a Minivan**

Tesla's lineup is undergoing a transition, with the Model S and Model X being phased out, leaving the Model 3, Model Y, and Cybertruck. This is a significant change from previous plans, especially for those seeking more premium options.

Source: Autoblog


* **China's BYD sees first profit drop since 2021, even as the Tesla-rival takes global EV crown**

Chinese automaker BYD reported a record annual revenue of $116 billion last year, surpassing Tesla. However, its profit fell for the first time since 2021 due to intense competition.

Source: Associated Press News...

Download full code from here

Applications

  • Agents enables real time data retrieval and analysis by integrating LLMs with external tools.
  • Supports development of intelligent assistants, research bots and financial or news analysis systems.
  • Improves chatbot performance by delivering context aware and up to date responses.

Limitations

  • Dependence on external APIs and tools can lead to failures or rate limit issues.
  • Output quality may vary based on prompt design and tool responses.
  • Multi step reasoning and tool usage increase latency and resource consumption.
Comment

Explore