Dependencies
Inject variables into agent and team context with dependencies.
Dependencies are a way to inject variables into your Agent or Team context. The dependencies parameter accepts a dictionary containing functions or static variables that are automatically resolved before the agent or team runs.
Note
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.
1from kern.agent import Agent2from kern.models.openai import OpenAIResponses34agent = Agent(5 model=OpenAIResponses(id="gpt-5.2"),6 dependencies={"name": "John Doe"},7 instructions="You are a story writer. The current user is {name}."8)910agent.print_response("Write a 5 second short story about {name}")Tip
You can set dependencies on Agent/Team initialization, or pass it to the run() and arun() methods.
How dependencies work
Dependencies are resolved at runtime, just before your agent or team executes. Here's the flow:
- Define dependencies: Provide a dictionary of key-value pairs where values can be static data or callable functions
- Resolution: When the agent/team runs, Kern calls all callable dependencies and replaces them with their return values
- Template substitution: Resolved dependencies are available in your instructions using
{dependency_name}syntax - Context injection: When
add_dependencies_to_context=True, dependencies are automatically added to the user message