Skip to content

Latest commit

 

History

History
252 lines (189 loc) · 5.88 KB

introduction.mdx

File metadata and controls

252 lines (189 loc) · 5.88 KB
title description
Introduction
**Build agents and workflows to automate intelligent work.**

What is Phidata?

Phidata is a framework for building multi-modal agents and workflows.

  • Build agents with memory, knowledge, tools and reasoning.
  • Build teams of agents that can work together to solve problems.
  • Interact with your agents and workflows using a beautiful Agent UI.

Key Features

Install

pip install -U phidata

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.

from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.tools.duckduckgo import DuckDuckGo

web_agent = Agent(
    name="Web 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)

Setup

<CodeGroup>
```bash Mac
python3 -m venv ~/.venvs/aienv
source ~/.venvs/aienv/bin/activate
```

```bash Windows
python3 -m venv aienv
aienv/scripts/activate
```
</CodeGroup>
<CodeGroup>
```bash Mac
pip install -U phidata openai duckduckgo-search
```

```bash Windows
pip install -U phidata openai duckduckgo-search
```
</CodeGroup>
Phidata works with most model providers but for these examples let's use OpenAI.

<CodeGroup>
```bash Mac
export OPENAI_API_KEY=sk-***
```

```bash Windows
setx OPENAI_API_KEY sk-***
```
</CodeGroup>

<Tip>
You can get an API key from [here](https://platform.openai.com/account/api-keys).
</Tip>
```shell
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.

```python 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

```shell
pip install yfinance
```

Run the agent

```shell
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

```python 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,
)
```
```shell
python image_agent.py
```

Multi-Agent orchestration

Phidata agents can work together as a team to achieve complex tasks.

```python 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],
    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

```shell
python agent_team.py
```

Continue reading