User State
User state stores information about a specific user that persists across sessions. It allows agents to personalise behaviour and remember user preferences.
6 min•By Priygop Team•Updated 2026
User State Contents
- Preferences: preferred language, communication style, output format
- History: previous tasks the user has run, common requests
- Permissions: what actions the agent is allowed to take on behalf of this user
- Profile: role, team, timezone, notification preferences
- Feedback: how the user rated previous agent outputs — used to improve future responses
User State Example
User State Example
# User state that persists across sessions
user_state = {
"user_id": "U-001",
"name": "Alice Johnson",
"email": "alice@example.com",
"role": "product_manager",
"timezone": "Europe/London",
"preferences": {
"output_format": "bullet_points",
"report_frequency": "weekly",
"notification_channel": "email",
"language": "en-GB",
},
"permissions": {
"can_approve_refunds": True,
"can_send_external_email": True,
"max_refund_amount": 500.00,
"allowed_tools": ["web_search", "send_email", "get_order",
"issue_refund", "create_report"],
},
"history": {
"total_tasks_run": 47,
"last_active": "2024-01-15T09:30:00Z",
"common_goals": ["weekly report", "refund processing", "competitor research"],
}
}
# Agent personalises behaviour using user state
def get_agent_instructions(user_state: dict) -> str:
prefs = user_state["preferences"]
return (
f"You are assisting {user_state['name']} ({user_state['role']}). "
f"Format all outputs as {prefs['output_format']}. "
f"Use {prefs['language']} language."
)
print(get_agent_instructions(user_state))Key Takeaways
- User state stores information about a specific user that persists across sessions.
- Preferences: preferred language, communication style, output format
- History: previous tasks the user has run, common requests
- Permissions: what actions the agent is allowed to take on behalf of this user