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

# Change State on Run

> Pass a user's name and age into session state at run time and keep the values isolated per session and user.

Set session state when you run the agent, with different values for different users and sessions. State persists within a session but stays isolated between sessions and users.

**1. Create a Python file**

```python change_state_on_run.py theme={null}
from agno.agent import Agent
from agno.db.in_memory import InMemoryDb
from agno.models.openai import OpenAIResponses

agent = Agent(
    db=InMemoryDb(),
    model=OpenAIResponses(id="gpt-5.2"),
    instructions="Users name is {user_name} and age is {age}",
    debug_mode=True,
)

# Sets the session state for the session with the id "user_1_session_1"
agent.print_response(
    "What is my name?",
    session_id="user_1_session_1",
    user_id="user_1",
    session_state={"user_name": "John", "age": 30},
)

# Will load the session state from the session with the id "user_1_session_1"
agent.print_response("How old am I?", session_id="user_1_session_1", user_id="user_1")

# Sets the session state for the session with the id "user_2_session_1"
agent.print_response(
    "What is my name?",
    session_id="user_2_session_1",
    user_id="user_2",
    session_state={"user_name": "Jane", "age": 25},
)

# Will load the session state from the session with the id "user_2_session_1"
agent.print_response("How old am I?", session_id="user_2_session_1", user_id="user_2")
```

<Snippet file="create-venv-step.mdx" />

**2. Install dependencies**

```bash theme={null}
uv pip install -U agno openai
```

**3. Export your OpenAI API key**

<Snippet file="set-openai-key.mdx" />

**4. Run Agent**

```bash theme={null}
python change_state_on_run.py
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.