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

# Manage Context

> Learn how to work with context data

## The Context Object

The `context` parameter provides access to conversation history and user data in your agent functions.

```python theme={null}
@cycls.app()
async def app(context):
    # Access conversation history
    messages = context.messages

    # Access the latest message
    latest_msg = messages[-1]

    yield f"You said: {latest_msg['content']}"
```

### Context Properties

<ResponseField name="context" type="Context Object">
  <Expandable title="properties" defaultOpen="True">
    <ResponseField name="messages" type="list[Message]">
      The conversation history in OpenAI format. Contains all previous messages in the conversation.
    </ResponseField>

    <ResponseField name="user" type="User Object">
      User information object when `auth=True`. (See [Authentication](/core-concepts/auth) for details).
    </ResponseField>
  </Expandable>
</ResponseField>

### Message Format

The `context.messages` follows the standard OpenAI message format, which can include text and images (multimodal).

Here is an example of what `context.messages` looks like:

```python theme={null}
[
    {'role': 'user', 'content': 'hello'},
    {'role': 'assistant', 'content': 'Hello! How can I assist you today?'},
    {'role': 'user', 'content': [
        {'type': 'image_url', 'image_url': {'url': 'https://.../image.png'}}
    ]},
    {'role': 'assistant', 'content': "It looks like you're looking at an image..."},
]
```

### Working with Messages

You can easily process these messages to extract text or pass them directly to an LLM.

```python theme={null}
import cycls

@cycls.app(pip=["openai"])
async def app(context):
    from openai import AsyncOpenAI

    client = AsyncOpenAI()
    response = await client.chat.completions.create(
        model="gpt-4o-mini",
        messages=context.messages,
        stream=True
    )
    async for chunk in response:
        content = chunk.choices[0].delta.content
        if content:
            yield content

app.local()
```

## Next Steps

<Card title="Customize UI" horizontal href="/core-concepts/agent-ui">
  Tailor the chat interface to match your brand.
</Card>
