> ## 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.

# Session Management

> Create, list, and manage sessions for agents, teams, and workflows

**1. Create a Python file**

```python session_management.py theme={null}
import asyncio

from agno.client import AgentOSClient


async def main():
    client = AgentOSClient(base_url="http://localhost:7777")

    # Get available agents
    config = await client.aget_config()
    if not config.agents:
        print("No agents available")
        return

    agent_id = config.agents[0].id
    user_id = "example-user"

    print("=" * 60)
    print("Session Management")
    print("=" * 60)

    # Create a session
    print("\n1. Creating a session...")
    session = await client.create_session(
        agent_id=agent_id,
        user_id=user_id,
        session_name="My Test Session",
    )
    print(f"   Session ID: {session.session_id}")
    print(f"   Session Name: {session.session_name}")

    # List sessions
    print("\n2. Listing sessions...")
    sessions = await client.get_sessions(user_id=user_id)
    print(f"   Found {len(sessions.data)} sessions")
    for sess in sessions.data[:5]:
        print(f"   - {sess.session_id}: {sess.session_name or 'Unnamed'}")

    # Run some messages in the session
    print("\n3. Running messages in session...")
    await client.run_agent(
        agent_id=agent_id,
        message="Hello!",
        session_id=session.session_id,
    )
    await client.run_agent(
        agent_id=agent_id,
        message="How are you?",
        session_id=session.session_id,
    )

    # Get session runs
    print("\n4. Getting session runs...")
    runs = await client.get_session_runs(session_id=session.session_id)
    print(f"   Found {len(runs)} runs in session")
    for run in runs:
        content_preview = (
            (run.content[:50] + "...")
            if run.content and len(str(run.content)) > 50
            else run.content
        )
        print(f"   - {run.run_id}: {content_preview}")

    # Rename session
    print("\n5. Renaming session...")
    renamed = await client.rename_session(
        session_id=session.session_id,
        session_name="Renamed Test Session",
    )
    print(f"   New name: {renamed.session_name}")

    # Delete session
    print(f"\n6. Deleting session {session.session_id}...")
    await client.delete_session(session.session_id)
    print("   Session deleted")


if __name__ == "__main__":
    asyncio.run(main())
```

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

**2. Install dependencies**

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

**3. Export your OpenAI API key**

```bash Mac/Linux theme={null}
export OPENAI_API_KEY="your_openai_api_key_here"
```

```bash Windows theme={null}
$Env:OPENAI_API_KEY="your_openai_api_key_here"
```

**4. Start an AgentOS Server**

Start the [client example server](https://agno-v2.mintlify.site/examples/agent-os/python-client/-server.md) on port 7777. It registers the SQLite database used for sessions.

**5. Run the Client**

```bash Mac theme={null}
python session_management.py
```

```bash Windows theme={null}
python session_management.py
```


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