agentic_retrieve_stream
async
¶
agentic_retrieve_stream(
agent_context_id: AgentContextIdentifier,
messages: MessageList,
*,
config_overrides: Optional[AsyncContextClientConfig] = None,
session_id: Optional[SessionId] = None,
analysis_configuration: Optional[AnalysisConfiguration] = None,
retrieval_configuration: Optional[StreamRetrievalConfiguration] = None,
) -> AsyncGenerator[AgenticRetrieveStreamResponse]
Answers a natural-language question against an agent context and streams the work as it happens. The response is an event stream that contains progress events while AWS Context searches the agent context, the answer in chunks as it is generated, and a final result. The final result contains the answer and the ranked retrieved context.
Parameters:
-
agent_context_id(AgentContextIdentifier) –The agent context to retrieve from, by its ID or ARN.
-
messages(MessageList) –The conversation, as an ordered list of turns. A single-question caller sends one user message. The list carries multi-turn history so a follow-up resolves against earlier turns.
-
session_id(Optional[SessionId], default:None) –Optional. A key that you supply to group related calls, for example the turns of one conversation, for trace storage and analysis. Grouping is per account, across agent contexts, so use a value that is unique to each conversation.
-
analysis_configuration(Optional[AnalysisConfiguration], default:None) –Optional controls for post-call analysis of the retrieval: whether its trace is stored for analysis. Trace events are streamed either way.
-
retrieval_configuration(Optional[StreamRetrievalConfiguration], default:None) –Optional bounds and configuration for the agent loop.
Raises:
-
AccessDeniedException–You don't have sufficient access to perform this operation. Verify that you have permission to perform the operation on the resource.
-
InternalServerException–The request failed because of an internal error. Retry the request.
-
ThrottlingException–The request was denied because it exceeded a request rate quota. Wait, then retry the request.
-
ValidationException–The input fails to satisfy the constraints of the operation. Correct the input before you retry the request.
-
ConflictException–The request conflicts with the current state of the resource. Check the resource's current state before you retry the request.
-
ResourceNotFoundException–The specified resource was not found. Check that the ID is correct and that the resource exists in your account and Region.
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
Ask a question about an agent context The following example asks which table holds customer orders. The response is an event stream; this example shows only its final result event, which carries the answer, the retrieved context, and a citation.
>>> await client.agentic_retrieve_stream(agent_context_id='ac-0123456789abcdef0123456789abcdef', session_id='sales-analytics-chat-0001', messages=[{'role': 'USER', 'content': 'Which table holds customer order data?'}], retrieval_configuration={'maxIterations': 10})
Source code in docs_src/capo_context/_services/async_context.py
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 | |