session_state variables directly into the agent’s instructions using add_state_in_messages.
Code
cookbook/agent_concepts/state/state_in_prompt.py
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
You are viewing v1 docs. For the latest documentation, visit docs.agno.com
session_state variables directly into the agent’s instructions using add_state_in_messages.
from agno.agent import Agent
from agno.models.openai import OpenAIChat
agent = Agent(
model=OpenAIChat(id="gpt-4o-mini"),
# Initialize the session state with a variable
session_state={"user_name": "John"},
# You can use variables from the session state in the instructions
instructions="Users name is {user_name}",
show_tool_calls=True,
add_state_in_messages=True,
markdown=True,
)
agent.print_response("What is my name?", stream=True)
Was this page helpful?