Any python function can be used as a tool by an Assistant. We highly recommend creating functions specific to your workflow and adding them to your Assistants.

For example, here’s how to add a get_top_hackernews_stories tool:
import json
import httpx

from phi.assistant import Assistant

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

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

        str: JSON string of top stories.

    # Fetch top story IDs
    response = httpx.get('')
    story_ids = response.json()

    # Fetch story details
    stories = []
    for story_id in story_ids[:num_stories]:
        story_response = httpx.get(f'{story_id}.json')
        story = story_response.json()
        if "text" in story:
            story.pop("text", None)
    return json.dumps(stories)

assistant = Assistant(tools=[get_top_hackernews_stories], show_tool_calls=True)
assistant.print_response("Summarize the top stories on hackernews?")