agentic_retrieve
async
¶
agentic_retrieve(
agent_context_id: AgentContextIdentifier,
messages: MessageList,
*,
config_overrides: Optional[AsyncContextClientConfig] = None,
session_id: Optional[SessionId] = None,
analysis_configuration: Optional[AnalysisConfiguration] = None,
retrieval_configuration: Optional[RetrievalConfiguration] = None,
) -> AgenticRetrieveResponse
Retrieves ranked context from an agent context for a natural-language question, in a single response. Send the question as a user message in messages and read the ranked retrievedContext. AWS Context searches and traverses the agent context for you until it has gathered enough context or reaches maxIterations. Prefer this over SearchAgentContext when finding the context needs more than one search or hop. To stream progress and receive a generated answer, use AgenticRetrieveStream.
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.
-
retrieval_configuration(Optional[RetrievalConfiguration], 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:
Retrieve context for a question about an agent context The following example asks which table holds customer orders and returns the retrieved context in a single response.
>>> await client.agentic_retrieve(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
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | |