本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
調用內嵌代理程式
注意
設定和調用內嵌代理程式功能是 Amazon Bedrock 的預覽版本,可能會有所變更。
調用內嵌代理程式之前,請確定您已完成必要條件。
若要調用內嵌代理程式,請使用 Amazon Bedrock 代理人執行時期端點傳送 InvokeInlineAgent API 請求,並至少包含下列欄位。
| 欄位 | 使用案例 |
|---|---|
| 指示 | 提供指示,告知內嵌代理程式應做什麼,以及應如何與使用者互動。 |
| foundationModel | 指定要由您建立的內嵌代理程式用於協調的基礎模型。例如,Anthropic Claude、meta Llama3.1 等。 |
| sessionid | 工作階段的唯一識別碼。在請求之間使用相同的值,以繼續相同的對話。 |
以下是選填欄位:
| 欄位 | 使用案例 |
|---|---|
| actionGroups | 動作群組清單,其中每個動作群組定義內嵌代理程式可執行的動作。 |
| knowledgeBases | 知識庫與內嵌代理程式的關聯,以增強模型產生的回應。 |
| guardrailConfiguration | 用於封鎖主題、防止幻覺,以及為應用程式實作保護措施的防護機制組態。 |
| agentCollaboration | 定義協作者代理程式如何處理跨多個協作者代理程式的資訊,以協調最終回應。協作者代理程式也可以是主管。 |
| collaboratorConfigurations | 協作者代理程式的組態。 |
| collaborators | 協作者代理程式的清單。 |
| promptOverrideConfiguration | 用於覆寫預設提示的進階提示組態。 |
| enableTrace | 指定是否開啟追蹤,以追蹤內嵌客服人員的推理程序。 |
| idleSessionTTLInSeconds | 指定內嵌代理程式應結束工作階段並刪除任何預存資訊的持續時間。 |
| customerEncryptionKeyArn | 指定 KMS 金鑰的 ARN 來加密代理程式資源, |
| endSession | 指定是否要結束內嵌代理程式的工作階段。 |
| inlineSessionState | 指定工作階段各種屬性的參數。 |
| inputText | 指定要傳送給代理程式的提示文字。 |
| reasoning_config | 啟用模型推理,讓模型解釋如何得出結論。在 additionalModelRequestFields 欄位內使用。您必須指定用於模型推理的 budget_tokens 數目,這是輸出字符的子集。如需詳細資訊,請參閱使用模型推理增強模型回應。 |
下列 InvokeInlineAgent API 範例提供完整的內嵌代理程式組態,包括基礎模型、指示、具有程式碼解譯器的動作群組、防護機制和知識庫。
response = bedrock_agent_runtime.invoke_inline_agent( // Initialization parameters: cannot be changed for a conversation sessionId='uniqueSessionId', customerEncryptionKeyArn: String, // Input inputText="Hello, can you help me with a task?", endSession=False, enableTrace=True, // Agent configurations foundationModel='anthropic.claude-3-7-sonnet-20250219-v1:0', instruction="You are a helpful assistant...", actionGroups=[ { 'name': 'CodeInterpreterAction', 'parentActionGroupSignature': 'AMAZON.CodeInterpreter' }, { 'actionGroupName': 'FetchDetails', 'parentActionGroupSignature': '', "actionGroupExecutor": { ... }, "apiSchema": { ... }, "description": "string", "functionSchema": { ... } } ], knowledgeBases=[ { knowledgeBaseId: "string", description: 'Use this KB to get all the info', retrievalConfiguration: { vectorSearchConfiguration: { filter: { ... }, numberOfResults: number, overrideSearchType: "string" } } } ], guardrailConfiguration={ guardrailIdentifier: 'BlockEverything', gurardrailVersion: '1.0' }, promptOverrideConfiguration: {...} // session properties: persisted throughout conversation inlineSessionState = { sessionAttributes = { 'key': 'value' }, promptSessionAttributes = {k:v}, returnControlInvocationResults = {...}, invocationId = 'abc', files = {...}, } }
您可以在請求中包含模型推理參數。以下是在 additionalModelRequestFields 中開啟模型推理的單一提示範例。
{ "basePromptTemplate": " ... ", "inferenceConfiguration": { "stopSequences": [ "</answer>" ] }, "parserMode": "DEFAULT", "promptCreationMode": "DEFAULT", "promptState": "DISABLED", "promptType": "ORCHESTRATION", "additionalModelRequestFields": "reasoning_config": { "type": "enabled", "budget_tokens": 1024 } }