This example demonstrates how to use session state variables directly in agent instructions. It shows how to initialize session state and reference those variables in the instruction templates.
1
Create a Python file
session_state_in_instructions.py
Copy
Ask AI
from agno.agent import Agentfrom agno.models.openai import OpenAIResponsesagent = Agent( model=OpenAIResponses(id="gpt-5.2"), session_state={"user_name": "John"}, instructions="Users name is {user_name}", markdown=True,)agent.print_response("What is my name?", stream=True)