Information
Phidata home page ⌘K agno-agi/phidata agno-agi/phidata Search... Navigation Agents Phidata home page from phi.agent import Agent from . import agent = Agent( = ( # Add functions or Toolkits # Add functions or Toolkits tools=[...], = [ . . . ] , # Show tool calls in the Agent response # Show tool calls in the Agent response show_tool_calls=True = True ) ) Using a Toolkit from phi.agent import Agent from . import from phi.tools.duckduckgo import DuckDuckGo from . . import agent = Agent(tools=[DuckDuckGo()], show_tool_calls=True, markdown=True) = ( = [ ( ) ] , = True , = True ) agent.print_response("Whats happening in France?", stream=True) . ( "Whats happening in France?" , = True ) pip install openai duckduckgo-search phidata install python web_search.py Writing your own Tools import json import import httpx import from phi.agent import Agent from . import def get_top_hackernews_stories(num_stories: int = 10) -> str: def get_top_hackernews_stories ( : int = 10 ) - > str : """Use this function to get top stories from Hacker News. "" from . Args: : num_stories (int): Number of stories to return. Defaults to 10. ( int ) : return . 10. Returns: : str: JSON string of top stories. str : . """ "" # Fetch top story IDs # Fetch top story IDs response = httpx.get('https://hacker-news.firebaseio.com/v0/topstories.json') = . ( 'https://hacker-news.firebaseio.com/v0/topstories.json' ) story_ids = response.json() = . ( ) # Fetch story details # Fetch story details stories = [] = [ ] for story_id in story_ids[:num_stories]: for in [ : ] : story_response = httpx.get(f'https://hacker-news.firebaseio.com/v0/item/{story_id}.json') = . ( f'https://hacker-news.firebaseio.com/v0/item/{story_id}.json' f'https://hacker-news.firebaseio.com/v0/item/ {story_id} { } .json' ) story = story_response.json() = . ( ) if "text" in story: if "text" in : story.pop("text", None) . ( "text" , None ) stories.append(story) . ( ) return json.dumps(stories) return . ( ) agent = Agent(tools=[get_top_hackernews_stories], show_tool_calls=True, markdown=True) = ( = [ ] , = True , = True ) agent.print_response("Summarize the top 5 stories on hackernews?", stream=True) . ( "Summarize the top 5 stories on hackernews?" , = True ) Attributes Prompts Knowledge x github discord youtube website On this page Agents use tools to take actions and interact with external systems. Tools are functions that an Agent can run to achieve tasks. For example: searching the web, running SQL, sending an email or calling APIs. You can use any python function as a tool or use a pre-built toolkit. The general syntax is: Phidata provides many pre-built toolkits that you can add to your Agents. For example, let’s use the DuckDuckGo toolkit to search the web. Create Web Search Agent Create a file web_search.py Run the agent Install libraries Run the agent For more control, write your own python functions and add them as tools to an Agent. For example, here’s how to add a get_top_hackernews_stories tool to an Agent. Read more about: The following attributes allow an Agent to use tools Was this page helpful?