phidata快速开始

文章目录

什么是phidata

github: https://github.com/phidatahq/phidata

官方文档:https://docs.phidata.com/introduction

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

Phidata 是一个用于构建多模式代理和工作流的框架。

  • 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.
    使用美观的 Agent UI 与您的代理和工作流程进行交互。

主要特点

  • Simple & Elegant 简单而优雅
  • Powerful & Flexible 强大且灵活
  • Multi-Modal by default 默认为 Multi-Modal
  • Multi-Agent orchestration
    多代理编排
  • A beautiful Agent UI to chat with your agents
    漂亮的代理 UI,与您的代理聊天
  • Agentic RAG built-in 内置 Agentic RAG
  • Structured outputs 结构化输出
  • Reasoning built-in 内置推理
  • Monitoring & Debugging built-in
    内置监控和调试功能

elegant

美: [ˈelɪɡənt]

英: [ˈelɪɡənt]

adj. (某物)优美的;雅致的;讲究的;(某人)苗条的

网络 优雅的;高雅的;文雅的

安装

bash 复制代码
pip install -U phidata

官方demo

创建一个 Web 搜索代理

Phidata Agents are simple and elegant, resulting in minimal, beautiful code.

Phidata 代理简单而优雅,从而产生最小、美观的代码。

For example, you can create a web search agent in 10 lines of code.

例如,您可以在 10 行代码中创建一个 Web 搜索代理。

bash 复制代码
pip install -U phidata openai duckduckgo-search
python 复制代码
from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.tools.duckduckgo import DuckDuckGo

api_key = "sk-proj-aN_YerJixxx"
web_agent = Agent(
    name="Web Agent",
    model=OpenAIChat(id="gpt-3.5-turbo", api_key=api_key),
    tools=[DuckDuckGo()],
    instructions=["Always include sources"],
    show_tool_calls=True,
    markdown=True,
)
web_agent.print_response("Tell me about OpenAI Sora?", stream=True)

使用国产deepseek模型

python 复制代码
from phi.agent import Agent

from phi.tools.duckduckgo import DuckDuckGo
from phi.model.deepseek import DeepSeekChat

api_key = "sk-xxxxx"

web_agent = Agent(
    name="Web Agent",
    model=DeepSeekChat(api_key=api_key),
    tools=[DuckDuckGo()],
    instructions=["Always include sources"],
    show_tool_calls=True,
    markdown=True,
)
web_agent.print_response("不是deepseek吗?", stream=True)

PhiData开发workflow应用

当前像coze、dify 这样的产品都支持workflow功能,可以可视化的定义workflow来解决一些相对负责的问题,而PhiData提供了通过code编排workflow的功能。

TODO~

Tools

工具是Agent可以运行的功能,如搜索web、运行SQL、发送电子邮件或调用api 。使用工具将agent与外部系统集成。您可以使用任何python函数作为工具或使用预构建的工具包。

python 复制代码
from phi.agent import Agent

agent = Agent(
    # Add functions or Toolkits
    tools=[...],
    # Show tool calls in the Agent response
    show_tool_calls=True
)
  • Available Toolkits

    Toolkit是可以添加到Agent中的函数集合。Toolkit中的函数被设计成协同工作、共享内部状态并提供更好的开发体验。 以下工具包可供使用

  • Using functions as tools
    任何 python 函数都可以被代理用作工具。我们强烈建议创建特定于您的工作流的函数,并将它们添加到您的代理中。

例如,以下是如何使用 get_top_hackernews_stories 函数作为工具:

python 复制代码
import json
import httpx

from phi.agent import Agent


def get_top_hackernews_stories(num_stories: int = 10) -> str:
    """Use this function to get top stories from Hacker News.

    Args:
        num_stories (int): Number of stories to return. Defaults to 10.

    Returns:
        str: JSON string of top stories.
    """

    # Fetch top story IDs
    response = httpx.get('https://hacker-news.firebaseio.com/v0/topstories.json')
    story_ids = response.json()

    # Fetch story details
    stories = []
    for story_id in story_ids[:num_stories]:
        story_response = httpx.get(f'https://hacker-news.firebaseio.com/v0/item/{story_id}.json')
        story = story_response.json()
        if "text" in story:
            story.pop("text", None)
        stories.append(story)
    return json.dumps(stories)

agent = Agent(tools=[get_top_hackernews_stories], show_tool_calls=True, markdown=True)
agent.print_response("Summarize the top 5 stories on hackernews?", stream=True)

在使用 Phidata 的代理功能时,系统会根据您定义的工作流和函数的特定条件来决定何时调用哪个 Python 函数

您需要在 Phidata 中定义您的 Python 函数。这些函数应该是针对您特定工作流的,能够处理特定的任务或数据。

您可以设置触发条件,这些条件可以是基于事件、数据变化或特定的用户输入。例如,您可以定义一个函数在接收到特定类型的数据时被调用,或者在某个时间点自动执行。

Phidata 将能够根据您的设置和工作流自动调用相应的 Python 函数。

Agent UI

官方文档:https://docs.phidata.com/agent-ui

Phidata provides a beautiful Agent UI for interacting with your agents.

没有数据发送到phidata,所有代理会话都本地存储在sqlite数据库中。

相关推荐
catoop1 小时前
Claude Skills 核心概念介绍(中英双语)
ai
小糖豆巴拉巴拉1 小时前
AI应用(3)-基础概念的理解
ai
沛沛老爹2 小时前
Web开发者快速上手AI Agent:基于Function Calling的提示词应用优化实战
java·人工智能·llm·agent·web·企业开发·function
带刺的坐椅2 小时前
灵动如画 —— 初识 Solon Graph Fluent API 编排
java·ai·agent·solon·flow·langgraph
小锋学长生活大爆炸2 小时前
【软件】AI Agent:无需电脑的手机自动化助手AutoGLM
运维·人工智能·智能手机·自动化·手机·agent·autoglm
仙魁XAN2 小时前
如何使用即梦AI,快速实现把建筑图转为线稿图,并且实现建筑线稿图第一人称视觉漫游的效果
ai·即梦ai·线稿图·首尾帧图片
山顶夕景3 小时前
【Agent】基于multi-agent的智能旅行助手
llm·agent·智能体·llm应用
哈哈你是真的厉害4 小时前
Windows系统通过wsl Ubuntu24.04本地安装OpenJiuwen Studio的完整安装教程
人工智能·华为·ai·大模型·agent·智能体·openjiuwen
AI指北4 小时前
每周AI看 | OpenAI押注音频AI、江南布衣引入网易云商客服Agent,推动客户服务从“降本”迈向“增收”、DeepSeek提出大模型训练新架构
人工智能·ai·架构·agent