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

# Basic Example

> Simple chat session example

## Basic Chat

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


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

    chat = Chat(
        session_id="example_session",
        user_id="example_user",
        agent=agent
    )

    response1 = await chat.invoke("Hello, my name is Alice")
    print(f"Assistant: {response1}")

    response2 = await chat.invoke("What is my name?")
    print(f"Assistant: {response2}")

    print(f"\nMessages: {len(chat.all_messages)}")
    print(f"Cost: ${chat.total_cost:.4f}")


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

## With Task Objects

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


async def main():
    agent = Agent("anthropic/claude-sonnet-4-5")
    chat = Chat(session_id="session1", user_id="user1", agent=agent)

    task = Task(description="Explain quantum computing in simple terms")
    response = await chat.invoke(task)
    print(response)


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

## Streaming

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


async def main():
    agent = Agent("anthropic/claude-sonnet-4-5")
    chat = Chat(session_id="session1", user_id="user1", agent=agent)

    print("Assistant: ", end="")
    async for chunk in chat.stream("Tell me a short joke"):
        print(chunk, end="", flush=True)
    print()


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