本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
注意
配置和调用内联代理功能在 Amazon Bedrock 的预览版中,可能会发生变化。
在调用内联代理之前,请确保已完成先决条件。
要调用内联代理,请使用适用于 Amazon Bedrock 的代理运行时终端节点发送 InvokeInlineAgentAPI 请求,并至少包含以下字段。
字段 | 应用场景 |
---|---|
instruction | 提供指示,告诉内联代理应该做什么以及它应该如何与用户交互。 |
foundationModel | 指定基础模型以供您创建的内联代理进行编排。例如,anthropic claude、meta Llama3.1 等。 |
sessionId | 会话的唯一标识符。在请求中使用相同的值以继续相同的对话。 |
以下字段是可选字段:
字段 | 应用场景 |
---|---|
行动小组 | 操作组列表,每个操作组定义了内联代理可以执行的操作。 |
knowledgeBases | 知识库与内联代理关联以增强模型生成的响应。 |
guardrailConfiguration | Guardrail 配置用于屏蔽话题、防止出现幻觉并为您的应用程序实施保护措施。 |
代理协作 | 定义协作者代理如何处理多个协作者代理之间的信息以协调最终响应。协作者代理也可以是主管。 |
协作者配置 | 协作者代理的配置。 |
collaborators | 合作者代理名单。 |
promptOverrideConfiguration | 用于覆盖默认提示的高级提示的配置。 |
enableTrace | 指定是否开启跟踪以跟踪内联代理的推理过程。 |
空闲会话秒 TTLIn | 指定内联代理应在多长时间后结束会话并删除所有存储的信息。 |
customerEncryptionKeyArn | 指定 KMS 密钥的 ARN 以加密代理资源, |
endSession | 指定是否结束与内联代理的会话。 |
inlineSessionState | 用于指定会话各种属性的参数。 |
inputText | 指定要发送给代理的提示文本。 |
推理配置 | 启用模型推理,以便模型解释它是如何得出结论的。在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
}
}