Getting Started
Documentation
- Agents
- Models
- Tools
- Introduction
- Functions
- Toolkits
- Writing your own Toolkit
- Airflow
- Apify
- Arxiv
- AWS Lambda
- BaiduSearch
- Calculator
- Cal.com
- Composio
- Crawl4AI
- CSV
- Dalle
- DuckDb
- DuckDuckGo
- Email
- Exa
- Fal
- File
- Firecrawl
- Giphy
- Github
- Google Calendar
- Google Search
- Hacker News
- Jina Reader
- Jira
- Linear
- Lumalabs
- MLX Transcribe
- ModelsLabs
- Newspaper
- Newspaper4k
- OpenBB
- Pandas
- Phi
- Postgres
- Pubmed
- Python
- Replicate
- Resend
- Searxng
- Serpapi
- Shell
- Slack
- Sleep
- Spider
- SQL
- Tavily
- Twitter
- Website
- Wikipedia
- Yfinance
- Youtube
- Zendesk
- Zoom
- Knowledge
- Chunking
- VectorDbs
- Storage
- Embeddings
- Workflows
Tools
Functions
Any python function can be used as a tool by an Agent. We highly recommend creating functions specific to your workflow and adding them to your Agents.
For example, here’s how to use a get_top_hackernews_stories
function as a tool:
hn_agent.py
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)
Was this page helpful?