Skip to main content
Dependencies is a way to inject variables into your Agent Context. dependencies is a dictionary that contains a set of functions (or static variables) that are resolved before the agent runs.
You can use dependencies to inject memories, dynamic few-shot examples, “retrieved” documents, etc.

Basic usage

You can reference the dependencies in your agent instructions or user message.
dependencies.py
from agno.agent import Agent
from agno.models.openai import OpenAIChat

agent = Agent(
    model=OpenAIChat(id="gpt-5-mini"),
    dependencies={"name": "John Doe"},
    instructions="You are a story writer. The current user is {name}."
)

agent.print_response("Write a 5 second short story about {name}")
You can set dependencies on Agent initialization, or pass it to the run() and arun() methods.

Using functions as dependencies

You can specify a callable function as a dependency. The dependency will be automatically resolved by the agent at runtime.
dependencies.py
import json
from textwrap import dedent

import httpx
from agno.agent import Agent
from agno.models.openai import OpenAIChat


def get_top_hackernews_stories() -> str:
    """Fetch and return the top stories from HackerNews.

    Args:
        num_stories: Number of top stories to retrieve (default: 5)
    Returns:
        JSON string containing story details (title, url, score, etc.)
    """
    # Get top stories
    stories = [
        {
            k: v
            for k, v in httpx.get(
                f"https://hacker-news.firebaseio.com/v0/item/{id}.json"
            )
            .json()
            .items()
            if k != "kids"  # Exclude discussion threads
        }
        for id in httpx.get(
            "https://hacker-news.firebaseio.com/v0/topstories.json"
        ).json()[:num_stories]
    ]
    return json.dumps(stories, indent=4)


agent = Agent(
    model=OpenAIChat(id="gpt-5-mini"),
    # Each function in the dependencies is evaluated when the agent is run,
    # think of it as dependency injection for Agents
    dependencies={"top_hackernews_stories": get_top_hackernews_stories},
    # Alternatively, you can manually add the context to the instructions
    instructions=dedent("""\
        You are an insightful tech trend observer! 📰

        Here are the top stories on HackerNews:
        {top_hackernews_stories}\
    """),
    markdown=True,
)

# Example usage
agent.print_response(
    "Summarize the top stories on HackerNews and identify any interesting trends.",
    stream=True,
)
Dependencies are automatically resolved when the agent is run.

Adding dependencies to context

Set add_dependencies_to_context=True to add the entire list of dependencies to the user message. This way you don’t have to manually add the dependencies to the instructions.
dependencies_instructions.py
import json
from textwrap import dedent

import httpx
from agno.agent import Agent
from agno.models.openai import OpenAIChat


def get_user_profile() -> str:
    """Fetch and return the user profile for a given user ID.

    Args:
        user_id: The ID of the user to retrieve the profile for
    """

    # Get the user profile from the database (this is a placeholder)
    user_profile = {
      "name": "John Doe",
      "experience_level": "senior",
    }

    return json.dumps(user_profile, indent=4)

agent = Agent(
    model=OpenAIChat(id="gpt-5-mini"),
    dependencies={"user_profile": get_user_profile},
    # We can add the entire dependencies dictionary to the user message
    add_dependencies_to_context=True,
    markdown=True,
)

agent.print_response(
    "Get the user profile for the user with ID 123 and tell me about their experience level.",
    stream=True,
)
# Optionally pass the dependencies to the print_response method
# agent.print_response(
#     "Get the user profile for the user with ID 123 and tell me about their experience level.",
#     dependencies={"user_profile": get_user_profile},
#     stream=True,
# )
This adds the entire dependencies dictionary to the user message between <additional context> tags. The new user message looks like this:
Get the user profile for the user with ID 123 and tell me about their experience level.                                                       
                                                                                                                                               
<additional context>                                                                                                                     
{                                                                                                                                        
"user_profile": "{\n    \"name\": \"John Doe\",\n    \"experience_level\": \"senior\"\n}"                                              
}                                                                                                                                        
</additional context> 
You can pass dependencies and add_dependencies_to_context to the run, arun, print_response and aprint_response methods.

Developer Resources

I