> ## Documentation Index
> Fetch the complete documentation index at: https://spacesail.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Dependencies

> Learn how to use dependencies to add context to your agents.

**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.

<Note>
  You can use dependencies to inject memories, dynamic few-shot examples, "retrieved" documents, etc.
</Note>

## Basic usage

You can reference the dependencies in your agent instructions or user message.

```python dependencies.py theme={null}
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}")
```

<Tip>
  You can set `dependencies` on `Agent` initialization, or pass it to the `run()` and `arun()` methods.
</Tip>

## Using functions as dependencies

You can specify a callable function as a dependency. The dependency will be automatically resolved by the agent at runtime.

```python dependencies.py theme={null}
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,
)
```

<Check>
  Dependencies are automatically resolved when the agent is run.
</Check>

## 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.

```python dependencies_instructions.py theme={null}
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,
# )
```

<Note>
  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> 
  ```
</Note>

<Tip>
  You can pass `dependencies` and `add_dependencies_to_context` to the `run`, `arun`, `print_response` and `aprint_response` methods.
</Tip>

## Access dependencies in tool calls and hooks

You can access the dependencies in tool calls and hooks by using the `RunContext` object.

```python theme={null}
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIChat
from agno.run import RunContext

def get_user_profile(run_context: RunContext) -> str:
    """Get the user profile."""
    return run_context.dependencies["user_profiles"][run_context.user_id]

agent = Agent(
    model=OpenAIChat(id="gpt-5-mini"),
    db=SqliteDb(db_file="tmp/agents.db"),
    tools=[get_user_profile],
    dependencies={"user_profiles": {"user_1001": {"name": "John Doe", "experience_level": "senior"}, "user_1002": {"name": "Jane Doe", "experience_level": "junior"}}},
)

agent.print_response("Get the user profile for the current user and tell me about their experience level.", user_id="user_1001", stream=True)
```

See the [RunContext schema](/reference/run/run_context) for more information.

## Developer Resources

* View the [Agent schema](/reference/agents/agent)
* View [Cookbook](https://github.com/agno-agi/agno/tree/main/cookbook/agents/dependencies/)
