

# Ask a question with agentic retrieval

The request is the same in the console, the AWS SDKs, and the AWS CLI. `messages` holds the conversation, oldest first: each message has a `role` (`USER` or `ASSISTANT`) and `content`, roles alternate, and the list starts and ends with a `USER` message. The last message is the question. For the other options, see [Step and time limits](control-scope-depth-and-timing.md). For the full request and response, see `AgenticRetrieveStream` in the * AWS Context API Reference*.

## To ask a question in the console
<a name="to-ask-a-question-in-the-console"></a>

1. Open the AWS Context console and choose your Agent context.

1. Choose **Chat with context**.

1. Enter a question and choose **Send question**, or choose one of the **Suggested questions**.

1. While the agent works, **Agent progress** shows each step.

1. When the answer is complete, review its inline citations and the **Sources** list. To see what the agent did, choose **Show trace**.

Follow-up questions build on the previous answers. To start over, choose **New conversation**.

**Note**  
The console answers with your own permissions. Another person or role can get a different answer to the same question.

## To ask a question (AWS CLI)
<a name="to-ask-a-question-cli"></a>

The CLI prints the stream’s events as they arrive.

```bash
aws context agentic-retrieve-stream --cli-input-json '{
  "agentContextId": "ac-1234567890abcdef",
  "messages": [{ "role": "USER", "content": "What was net revenue by Region last quarter?" }]
}'
```

## To ask a question (AWS SDK for Python)
<a name="to-ask-a-question-sdk-python"></a>

The following example prints progress as it arrives and keeps the final result. If you only need the answer, keep the `result` event and ignore the rest.

```python
import boto3
from botocore.config import Config

client = boto3.client(
    "context",
    region_name="us-east-1",
    config=Config(read_timeout=120),  # the stream can be quiet during a slow step
)

response = client.agentic_retrieve_stream(
    agentContextId="ac-1234567890abcdef",
    messages=[{"role": "USER", "content": "What was net revenue by Region last quarter?"}],
)

final = None
for event in response["stream"]:
    if "traceEvent" in event:
        attrs = event["traceEvent"]["attributes"]
        print(f"[{attrs['step']}/{attrs['status']}] {attrs['message']}")
    elif "responseEvent" in event:
        print(event["responseEvent"]["text"], end="", flush=True)
    elif "result" in event:
        final = event["result"]

if final:
    print("\nCitations:", len(final.get("citations", [])))
```