phidata
Build multi-modal Agents with memory, knowledge, tools and reasoning. Chat with them using a beautiful Agent UI.
Top Related Projects
Prefect is a workflow orchestration framework for building resilient data pipelines in Python.
An orchestration platform for the development, production, and observation of data assets.
Apache Airflow - A platform to programmatically author, schedule, and monitor workflows
Always know what to expect from your data.
Kedro is a toolbox for production-ready data science. It uses software engineering best practices to help you create data engineering and data science pipelines that are reproducible, maintainable, and modular.
Open source platform for the machine learning lifecycle
Quick Overview
Phidata is an open-source AI development framework that simplifies the process of building and deploying AI applications. It provides a streamlined approach to creating AI assistants, chatbots, and other AI-powered tools, with a focus on ease of use and scalability.
Pros
- Simplifies AI application development with pre-built components and workflows
- Supports multiple AI models and integrations, including OpenAI and AWS
- Offers both local development and cloud deployment options
- Provides a structured approach to building AI assistants and chatbots
Cons
- Relatively new project, which may lead to potential instability or lack of extensive community support
- Documentation could be more comprehensive for advanced use cases
- Limited number of pre-built templates compared to some other AI frameworks
- May have a learning curve for developers new to AI application development
Code Examples
- Creating a simple AI assistant:
from phidata.assistant import Assistant
from phidata.conversation import Conversation
assistant = Assistant(name="My Assistant")
conversation = Conversation(assistant=assistant)
response = conversation.chat("Hello, how are you?")
print(response)
- Using a custom AI function:
from phidata.function import Function
def get_weather(location: str) -> str:
# Implement weather lookup logic here
return f"The weather in {location} is sunny."
weather_function = Function(
name="get_weather",
description="Get the current weather for a location",
function=get_weather,
)
assistant = Assistant(name="Weather Assistant", functions=[weather_function])
- Deploying an AI application to AWS:
from phidata.app import App
from phidata.aws import AwsContainer
app = App(
name="my-ai-app",
containers=[
AwsContainer(
name="ai-container",
image="my-ai-image:latest",
cpu=1,
memory=2048,
)
],
)
app.create()
Getting Started
To get started with Phidata, follow these steps:
- Install Phidata:
pip install phidata
- Create a new AI project:
phi create project my-ai-project
cd my-ai-project
- Run the development server:
phi start
- Access your AI application at
http://localhost:8000
For more detailed instructions and advanced usage, refer to the official Phidata documentation.
Competitor Comparisons
Prefect is a workflow orchestration framework for building resilient data pipelines in Python.
Pros of Prefect
- More mature and widely adopted workflow management system
- Extensive documentation and community support
- Flexible scheduling options and advanced monitoring capabilities
Cons of Prefect
- Steeper learning curve for beginners
- Can be overkill for simpler data workflows
- Requires more setup and configuration
Code Comparison
Prefect:
from prefect import task, Flow
@task
def extract():
return [1, 2, 3]
@task
def transform(data):
return [i * 2 for i in data]
with Flow("ETL") as flow:
data = extract()
transform(data)
phidata:
from phidata import Workflow, Task
class Extract(Task):
def run(self):
return [1, 2, 3]
class Transform(Task):
def run(self, data):
return [i * 2 for i in data]
workflow = Workflow(
tasks=[Extract(), Transform()]
)
Both frameworks offer task-based workflow definitions, but Prefect uses decorators and a context manager, while phidata uses class-based tasks and a more declarative approach.
An orchestration platform for the development, production, and observation of data assets.
Pros of Dagster
- More mature and feature-rich data orchestration platform
- Larger community and ecosystem with extensive documentation
- Supports a wider range of data processing frameworks and integrations
Cons of Dagster
- Steeper learning curve due to its comprehensive feature set
- Heavier infrastructure requirements for deployment and scaling
- More complex setup and configuration process
Code Comparison
Dagster:
@op
def hello_world():
return "Hello, World!"
@job
def my_job():
hello_world()
Phidata:
from phidata import Job, Task
def hello_world():
return "Hello, World!"
my_job = Job(
tasks=[Task(function=hello_world)]
)
Both frameworks allow for defining and executing data pipelines, but Dagster uses decorators and a more opinionated structure, while Phidata offers a more flexible, object-oriented approach. Dagster's syntax is more concise, but Phidata's structure may be more intuitive for some users, especially those familiar with object-oriented programming.
Dagster provides a more comprehensive set of features for large-scale data orchestration, while Phidata focuses on simplicity and ease of use for smaller to medium-sized projects. The choice between the two depends on the specific requirements of your data pipeline and the scale of your operations.
Apache Airflow - A platform to programmatically author, schedule, and monitor workflows
Pros of Airflow
- Mature and widely adopted platform with extensive community support
- Rich ecosystem of plugins and integrations
- Comprehensive scheduling and monitoring capabilities
Cons of Airflow
- Steep learning curve and complex setup process
- Resource-intensive, especially for smaller projects
- Requires significant maintenance and operational overhead
Code Comparison
Airflow DAG definition:
from airflow import DAG
from airflow.operators.python_operator import PythonOperator
from datetime import datetime
def hello_world():
print("Hello, World!")
dag = DAG('hello_world', start_date=datetime(2023, 1, 1), schedule_interval='@daily')
task = PythonOperator(
task_id='hello_task',
python_callable=hello_world,
dag=dag
)
Phidata workflow definition:
from phidata import Workflow, Task
def hello_world():
print("Hello, World!")
workflow = Workflow(
name="hello_world",
tasks=[
Task(name="hello_task", function=hello_world)
]
)
The Airflow example demonstrates its more verbose and complex configuration, while Phidata offers a simpler, more concise approach to defining workflows.
Always know what to expect from your data.
Pros of Great Expectations
- Robust data validation and profiling capabilities
- Extensive documentation and community support
- Integration with various data platforms and tools
Cons of Great Expectations
- Steeper learning curve for beginners
- Can be resource-intensive for large datasets
- More complex setup and configuration process
Code Comparison
Great Expectations:
import great_expectations as ge
df = ge.read_csv("data.csv")
expectation_suite = df.profile()
validation_result = df.validate(expectation_suite=expectation_suite)
Phidata:
from phidata import Dataset, Expectation
dataset = Dataset("data.csv")
expectation = Expectation().column("column_name").is_not_null()
result = dataset.validate(expectation)
Great Expectations offers more comprehensive data validation and profiling features, while Phidata provides a simpler, more streamlined approach to data quality checks. Great Expectations has a larger ecosystem and more integrations, but Phidata may be easier to set up and use for smaller projects or teams new to data quality tools.
Kedro is a toolbox for production-ready data science. It uses software engineering best practices to help you create data engineering and data science pipelines that are reproducible, maintainable, and modular.
Pros of Kedro
- More mature and established project with a larger community and ecosystem
- Comprehensive documentation and extensive tutorials
- Built-in support for data catalogs and pipelines
Cons of Kedro
- Steeper learning curve due to its more complex architecture
- Can be overkill for smaller projects or simpler data workflows
- Less focus on AI/ML-specific workflows compared to Phidata
Code Comparison
Kedro pipeline definition:
from kedro.pipeline import Pipeline, node
def create_pipeline(**kwargs):
return Pipeline(
[
node(func=preprocess, inputs="raw_data", outputs="preprocessed_data"),
node(func=train_model, inputs="preprocessed_data", outputs="model"),
]
)
Phidata workflow definition:
from phidata import Workflow, Task
workflow = Workflow(
tasks=[
Task(name="preprocess", func=preprocess, inputs=["raw_data"]),
Task(name="train_model", func=train_model, inputs=["preprocessed_data"]),
]
)
Both frameworks offer ways to define data processing pipelines, but Kedro's approach is more structured and verbose, while Phidata's is more concise and flexible.
Open source platform for the machine learning lifecycle
Pros of MLflow
- More mature and widely adopted in the ML community
- Comprehensive feature set for experiment tracking, model management, and deployment
- Extensive documentation and community support
Cons of MLflow
- Steeper learning curve for beginners
- Can be complex to set up and configure for specific use cases
- Heavier resource requirements for full functionality
Code Comparison
MLflow:
import mlflow
mlflow.start_run()
mlflow.log_param("param1", value1)
mlflow.log_metric("metric1", value2)
mlflow.end_run()
phidata:
from phidata import Workspace
ws = Workspace()
ws.add_experiment("experiment1")
ws.log_param("param1", value1)
ws.log_metric("metric1", value2)
MLflow provides a more comprehensive API for tracking experiments and managing models, while phidata offers a simpler interface for basic experiment tracking. MLflow's code structure is more explicit, requiring start and end run calls, whereas phidata uses a workspace-based approach. Both libraries allow for logging parameters and metrics, but MLflow's ecosystem includes additional features for model management and deployment that are not present in the phidata example.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
phidata
Build multi-modal Agents with memory, knowledge, tools and reasoning.
What is phidata?
Phidata is a framework for building multi-modal agents, use phidata to:
- Build multi-modal agents with memory, knowledge, tools and reasoning.
- Build teams of agents that can work together to solve problems.
- Chat with your agents using a beautiful Agent UI.
Install
pip install -U phidata
Key Features
- Simple & Elegant
- Powerful & Flexible
- Multi-Modal by default
- Multi-Agent orchestration
- A beautiful Agent UI to chat with your agents
- Agentic RAG built-in
- Structured Outputs
- Reasoning Agents
- Monitoring & Debugging built-in
- Demo Agents
Simple & Elegant
Phidata Agents are simple and elegant, resulting in minimal, beautiful code.
For example, you can create a web search agent in 10 lines of code, create a file web_search.py
from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.tools.duckduckgo import DuckDuckGo
web_agent = Agent(
model=OpenAIChat(id="gpt-4o"),
tools=[DuckDuckGo()],
instructions=["Always include sources"],
show_tool_calls=True,
markdown=True,
)
web_agent.print_response("Tell me about OpenAI Sora?", stream=True)
Install libraries, export your OPENAI_API_KEY
and run the Agent:
pip install phidata openai duckduckgo-search
export OPENAI_API_KEY=sk-xxxx
python web_search.py
Powerful & Flexible
Phidata agents can use multiple tools and follow instructions to achieve complex tasks.
For example, you can create a finance agent with tools to query financial data, create a file finance_agent.py
from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.tools.yfinance import YFinanceTools
finance_agent = Agent(
name="Finance Agent",
model=OpenAIChat(id="gpt-4o"),
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True)],
instructions=["Use tables to display data"],
show_tool_calls=True,
markdown=True,
)
finance_agent.print_response("Summarize analyst recommendations for NVDA", stream=True)
Install libraries and run the Agent:
pip install yfinance
python finance_agent.py
Multi-Modal by default
Phidata agents support text, images, audio and video.
For example, you can create an image agent that can understand images and make tool calls as needed, create a file image_agent.py
from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.tools.duckduckgo import DuckDuckGo
agent = Agent(
model=OpenAIChat(id="gpt-4o"),
tools=[DuckDuckGo()],
markdown=True,
)
agent.print_response(
"Tell me about this image and give me the latest news about it.",
images=["https://upload.wikimedia.org/wikipedia/commons/b/bf/Krakow_-_Kosciol_Mariacki.jpg"],
stream=True,
)
Run the Agent:
python image_agent.py
Multi-Agent orchestration
Phidata agents can work together as a team to achieve complex tasks, create a file agent_team.py
from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.tools.duckduckgo import DuckDuckGo
from phi.tools.yfinance import YFinanceTools
web_agent = Agent(
name="Web Agent",
role="Search the web for information",
model=OpenAIChat(id="gpt-4o"),
tools=[DuckDuckGo()],
instructions=["Always include sources"],
show_tool_calls=True,
markdown=True,
)
finance_agent = Agent(
name="Finance Agent",
role="Get financial data",
model=OpenAIChat(id="gpt-4o"),
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True)],
instructions=["Use tables to display data"],
show_tool_calls=True,
markdown=True,
)
agent_team = Agent(
team=[web_agent, finance_agent],
model=OpenAIChat(id="gpt-4o"),
instructions=["Always include sources", "Use tables to display data"],
show_tool_calls=True,
markdown=True,
)
agent_team.print_response("Summarize analyst recommendations and share the latest news for NVDA", stream=True)
Run the Agent team:
python agent_team.py
A beautiful Agent UI to chat with your agents
Phidata provides a beautiful UI for interacting with your agents. Let's take it for a spin, create a file playground.py
[!NOTE] Phidata does not store any data, all agent data is stored locally in a sqlite database.
from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.storage.agent.sqlite import SqlAgentStorage
from phi.tools.duckduckgo import DuckDuckGo
from phi.tools.yfinance import YFinanceTools
from phi.playground import Playground, serve_playground_app
web_agent = Agent(
name="Web Agent",
model=OpenAIChat(id="gpt-4o"),
tools=[DuckDuckGo()],
instructions=["Always include sources"],
storage=SqlAgentStorage(table_name="web_agent", db_file="agents.db"),
add_history_to_messages=True,
markdown=True,
)
finance_agent = Agent(
name="Finance Agent",
model=OpenAIChat(id="gpt-4o"),
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True)],
instructions=["Use tables to display data"],
storage=SqlAgentStorage(table_name="finance_agent", db_file="agents.db"),
add_history_to_messages=True,
markdown=True,
)
app = Playground(agents=[finance_agent, web_agent]).get_app()
if __name__ == "__main__":
serve_playground_app("playground:app", reload=True)
Authenticate with phidata by running the following command:
phi auth
or by exporting the PHI_API_KEY
for your workspace from phidata.app
export PHI_API_KEY=phi-***
Install dependencies and run the Agent Playground:
pip install 'fastapi[standard]' sqlalchemy
python playground.py
- Open the link provided or navigate to
http://phidata.app/playground
- Select the
localhost:7777
endpoint and start chatting with your agents!
Agentic RAG
We were the first to pioneer Agentic RAG using our Auto-RAG paradigm. With Agentic RAG (or auto-rag), the Agent can search its knowledge base (vector db) for the specific information it needs to achieve its task, instead of always inserting the "context" into the prompt.
This saves tokens and improves response quality. Create a file rag_agent.py
from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.embedder.openai import OpenAIEmbedder
from phi.knowledge.pdf import PDFUrlKnowledgeBase
from phi.vectordb.lancedb import LanceDb, SearchType
# Create a knowledge base from a PDF
knowledge_base = PDFUrlKnowledgeBase(
urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
# Use LanceDB as the vector database
vector_db=LanceDb(
table_name="recipes",
uri="tmp/lancedb",
search_type=SearchType.vector,
embedder=OpenAIEmbedder(model="text-embedding-3-small"),
),
)
# Comment out after first run as the knowledge base is loaded
knowledge_base.load()
agent = Agent(
model=OpenAIChat(id="gpt-4o"),
# Add the knowledge base to the agent
knowledge=knowledge_base,
show_tool_calls=True,
markdown=True,
)
agent.print_response("How do I make chicken and galangal in coconut milk soup", stream=True)
Install libraries and run the Agent:
pip install lancedb tantivy pypdf sqlalchemy
python rag_agent.py
Structured Outputs
Agents can return their output in a structured format as a Pydantic model.
Create a file structured_output.py
from typing import List
from pydantic import BaseModel, Field
from phi.agent import Agent
from phi.model.openai import OpenAIChat
# Define a Pydantic model to enforce the structure of the output
class MovieScript(BaseModel):
setting: str = Field(..., description="Provide a nice setting for a blockbuster movie.")
ending: str = Field(..., description="Ending of the movie. If not available, provide a happy ending.")
genre: str = Field(..., description="Genre of the movie. If not available, select action, thriller or romantic comedy.")
name: str = Field(..., description="Give a name to this movie")
characters: List[str] = Field(..., description="Name of characters for this movie.")
storyline: str = Field(..., description="3 sentence storyline for the movie. Make it exciting!")
# Agent that uses JSON mode
json_mode_agent = Agent(
model=OpenAIChat(id="gpt-4o"),
description="You write movie scripts.",
response_model=MovieScript,
)
# Agent that uses structured outputs
structured_output_agent = Agent(
model=OpenAIChat(id="gpt-4o"),
description="You write movie scripts.",
response_model=MovieScript,
structured_outputs=True,
)
json_mode_agent.print_response("New York")
structured_output_agent.print_response("New York")
- Run the
structured_output.py
file
python structured_output.py
- The output is an object of the
MovieScript
class, here's how it looks:
MovieScript(
â setting='A bustling and vibrant New York City',
â ending='The protagonist saves the city and reconciles with their estranged family.',
â genre='action',
â name='City Pulse',
â characters=['Alex Mercer', 'Nina Castillo', 'Detective Mike Johnson'],
â storyline='In the heart of New York City, a former cop turned vigilante, Alex Mercer, teams up with a street-smart activist, Nina Castillo, to take down a corrupt political figure who threatens to destroy the city. As they navigate through the intricate web of power and deception, they uncover shocking truths that push them to the brink of their abilities. With time running out, they must race against the clock to save New York and confront their own demons.'
)
Reasoning Agents (experimental)
Reasoning helps agents work through a problem step-by-step, backtracking and correcting as needed. Create a file reasoning_agent.py
.
from phi.agent import Agent
from phi.model.openai import OpenAIChat
task = (
"Three missionaries and three cannibals need to cross a river. "
"They have a boat that can carry up to two people at a time. "
"If, at any time, the cannibals outnumber the missionaries on either side of the river, the cannibals will eat the missionaries. "
"How can all six people get across the river safely? Provide a step-by-step solution and show the solutions as an ascii diagram"
)
reasoning_agent = Agent(model=OpenAIChat(id="gpt-4o"), reasoning=True, markdown=True, structured_outputs=True)
reasoning_agent.print_response(task, stream=True, show_full_reasoning=True)
Run the Reasoning Agent:
python reasoning_agent.py
[!WARNING] Reasoning is an experimental feature and will break ~20% of the time. It is not a replacement for o1.
It is an experiment fueled by curiosity, combining COT and tool use. Set your expectations very low for this initial release. For example: It will not be able to count ârâs in âstrawberryâ.
Demo Agents
The Agent Playground includes a few demo agents that you can test with. If you have recommendations for other demo agents, please let us know in our community forum.
Monitoring & Debugging
Monitoring
Phidata comes with built-in monitoring. You can set monitoring=True
on any agent to track sessions or set PHI_MONITORING=true
in your environment.
[!NOTE] Run
phi auth
to authenticate your local account or export thePHI_API_KEY
from phi.agent import Agent
agent = Agent(markdown=True, monitoring=True)
agent.print_response("Share a 2 sentence horror story")
Run the agent and monitor the results on phidata.app/sessions
# You can also set the environment variable
# export PHI_MONITORING=true
python monitoring.py
View the agent session on phidata.app/sessions
Debugging
Phidata also includes a built-in debugger that will show debug logs in the terminal. You can set debug_mode=True
on any agent to track sessions or set PHI_DEBUG=true
in your environment.
from phi.agent import Agent
agent = Agent(markdown=True, debug_mode=True)
agent.print_response("Share a 2 sentence horror story")
Getting help
- Read the docs at docs.phidata.com
- Post your questions on the community forum
- Chat with us on discord
More examples
Agent that can write and run python code
Show code
The PythonAgent
can achieve tasks by writing and running python code.
- Create a file
python_agent.py
from phi.agent.python import PythonAgent
from phi.model.openai import OpenAIChat
from phi.file.local.csv import CsvFile
python_agent = PythonAgent(
model=OpenAIChat(id="gpt-4o"),
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?")
- Run the
python_agent.py
python python_agent.py
Agent that can analyze data using SQL
Show code
The DuckDbAgent
can perform data analysis using SQL.
- Create a file
data_analyst.py
import json
from phi.model.openai import OpenAIChat
from phi.agent.duckdb import DuckDbAgent
data_analyst = DuckDbAgent(
model=OpenAIChat(model="gpt-4o"),
markdown=True,
semantic_model=json.dumps(
{
"tables": [
{
"name": "movies",
"description": "Contains information about movies from IMDB.",
"path": "https://phidata-public.s3.amazonaws.com/demo_data/IMDB-Movie-Data.csv",
}
]
},
indent=2,
),
)
data_analyst.print_response(
"Show me a histogram of ratings. "
"Choose an appropriate bucket size but share how you chose it. "
"Show me the result as a pretty ascii diagram",
stream=True,
)
- Install duckdb and run the
data_analyst.py
file
pip install duckdb
python data_analyst.py
Check out the cookbook for more examples.
Contributions
We're an open-source project and welcome contributions, please read the contributing guide for more information.
Request a feature
- If you have a feature request, please open an issue or make a pull request.
- If you have ideas on how we can improve, please create a discussion.
Telemetry
Phidata logs which model an agent used so we can prioritize features for the most popular models.
You can disable this by setting PHI_TELEMETRY=false
in your environment.
Top Related Projects
Prefect is a workflow orchestration framework for building resilient data pipelines in Python.
An orchestration platform for the development, production, and observation of data assets.
Apache Airflow - A platform to programmatically author, schedule, and monitor workflows
Always know what to expect from your data.
Kedro is a toolbox for production-ready data science. It uses software engineering best practices to help you create data engineering and data science pipelines that are reproducible, maintainable, and modular.
Open source platform for the machine learning lifecycle
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot