> ## Documentation Index
> Fetch the complete documentation index at: https://docs.upsonic.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Context Manager

> Using Chat as an async context manager

## Basic Usage

Chat implements async context manager for automatic resource cleanup:

```python theme={null}
import asyncio
from upsonic import Agent, Chat


async def main():
    agent = Agent("anthropic/claude-sonnet-4-5")

    async with Chat(
        session_id="session1",
        user_id="user1",
        agent=agent
    ) as chat:
        response = await chat.invoke("Hello")
        print(response)


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

## With Storage

```python theme={null}
import asyncio
from upsonic import Agent, Chat
from upsonic.storage import SqliteStorage


async def main():
    storage = SqliteStorage(db_file="chat.db")
    agent = Agent("anthropic/claude-sonnet-4-5")

    async with Chat(
        session_id="session1",
        user_id="user1",
        agent=agent,
        storage=storage
    ) as chat:
        response = await chat.invoke("Hello")
        print(response)


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