Examples
- Introduction
- Agents
- Web Search Agent
- AI Recipe Creator Agent
- Finance Agent
- Books Recommendation Agent
- Shopping Agent
- Weekend Planner Agent
- Agent Team
- Reasoning Agent
- Python Agent
- Data Analyst
- Structured Output
- Python Function Agent
- Image Agent
- Generate Image Agent
- Cal.com Agent
- Image to Text Agent
- Research Agent
- ModelsLabs Agent
- Slack Agent
- Discord Agent
- Firecrawl Agent
- Github Agent
- RAG Agent
- Popcorn Pal
- Globe Hopper Agent
- Baidu Search Agent
- Youtube Timestamp Agent
- Study Scout Agent
- Models
- Integrations
- Agent Teams
- Use Cases
How To
Agents
Python Agent
Create a file python_agent.py
with the following code:
python_agent.py
from pathlib import Path
from phi.agent.python import PythonAgent
from phi.model.openai import OpenAIChat
from phi.file.local.csv import CsvFile
cwd = Path(__file__).parent.resolve()
tmp = cwd.joinpath("tmp")
if not tmp.exists():
tmp.mkdir(exist_ok=True, parents=True)
python_agent = PythonAgent(
model=OpenAIChat(id="gpt-4o"),
base_dir=tmp,
files=[
CsvFile(
path="https://phidata-public.s3.amazonaws.com/demo_data/IMDB-Movie-Data.csv",
description="Contains information about movies from IMDB.",
)
],
markdown=True,
pip_install=True,
show_tool_calls=True,
)
python_agent.print_response("What is the average rating of movies?")
Usage
1
Create a virtual environment
Open the Terminal
and create a python virtual environment.
python3 -m venv ~/.venvs/aienv
source ~/.venvs/aienv/bin/activate
2
Install libraries
pip install openai phidata
3
Run the agent
python python_agent.py
Was this page helpful?
On this page