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. For the full request and response, see AgenticRetrieveStream in the
AWS Context API Reference.
To ask a question in the console
-
Open the AWS Context console and choose your Agent context.
-
Choose Chat with context.
-
Enter a question and choose Send question, or choose one of the Suggested questions.
-
While the agent works, Agent progress shows each step.
-
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.
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)
The CLI prints the stream’s events as they arrive.
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)
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.
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", [])))