你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。

用于自助安排日程的代理的提醒工具

Important

本文中标记为预览的项目目前为预览版。 此预览版在没有服务级别协议的情况下提供,Microsoft不建议将其用于生产工作负荷。 某些功能可能不受支持,或者可能具有受限功能。 有关详细信息,请参阅 Microsoft Azure 预览版补充使用条款。

reminder_preview 工具可让托管代理安排 自身 在未来某个时间再次运行。 当代理在运行期间决定需要后续跟进(例如重新检查长时间运行的任务或提示用户进行状态更新)时,请使用此模式。

当代理调用提醒工具时,它会指定以分钟为单位的延迟。 在该延迟之后,Foundry 在同一会话中重新调用同一代理。 然后,代理可以继续其工作、检查外部系统或提示用户。

Important

提醒工具仅适用于托管代理。 不能将提醒工具与提示代理配合使用。 若要使用提醒工具,请创建包含该工具 reminder_preview 的工具箱,然后将工具箱附加到托管代理。

先决条件

提醒工具的工作原理

提醒工具接受以下参数:

论点 类型 范围 Description
minutes 整数 1–43,200 重新调用代理之前要等待的分钟数。
input 字符串 — 有关智能体被提醒调用时需要执行的操作的说明。

当代理调用该工具时,它会根据工具的推理决定延迟的时间。 然后,Foundry 将创建 一个计划例程,该例程 在指定的延迟后触发,并在同一会话中重新调用同一托管代理。 与启动新对话的常规例程不同,此方法会跨调用保留上下文。

将提醒工具添加到工具箱

该提醒工具无需连接。 无需配置任何外部服务或身份验证。

Foundry 门户中工具箱内的 reminder_preview 工具的屏幕截图。

  1. 在 Foundry 门户中,转到你的项目。
  2. 在左窗格中,选择“ 生成”和“自定义>工具箱”。
  3. 选择 “+ 新建 ”以创建工具箱,或选择要编辑的现有工具箱。
  4. 在工具箱编辑器中,选择“ + 添加”工具。
  5. 在“内置工具”下,选择“提醒”(预览版)。
  6. 配置工具名称和说明,然后选择“ 添加”。
  7. 选择 “保存 ”以保存工具箱。

工具箱详细信息页显示 MCP 终结点。 复制此终结点以连接托管代理。

from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
from azure.ai.projects.models import ReminderPreviewToolboxTool

# Create Foundry project client
endpoint = "https://<your-foundry-account>.services.ai.azure.com/api/projects/<your-project>"
project = AIProjectClient(
    endpoint=endpoint,
    credential=DefaultAzureCredential(),
)

# Create toolbox version with reminder tool
toolbox_version = project.toolboxes.create_version(
    name="reminder-toolbox",
    description="Built-in reminder tool for a self-scheduling agent",
    tools=[
        ReminderPreviewToolboxTool(
            name="schedule_reminder",
            description="Schedule a reminder that re-invokes this agent at a future time.",
        ),
    ],
)
print(f"Created toolbox: {toolbox_version.name}, version: {toolbox_version.version}")
print(f"MCP endpoint: {toolbox_version.mcp_endpoint}")
using Azure.Identity;
using Azure.AI.Projects;

// Create Foundry project client
var projectEndpoint = "https://<your-foundry-account>.services.ai.azure.com/api/projects/<your-project>";
AIProjectClient projectClient = new(new Uri(projectEndpoint), new DefaultAzureCredential());

// Create toolbox version with reminder tool
var reminderTool = new ReminderPreviewToolboxTool
{
    Name = "schedule_reminder",
    Description = "Schedule a reminder that re-invokes this agent at a future time."
};

ToolboxVersionObject toolboxVersion = await projectClient.Toolboxes.CreateVersionAsync(
    name: "reminder-toolbox",
    tools: [reminderTool],
    description: "Built-in reminder tool for a self-scheduling agent"
);
Console.WriteLine($"Created toolbox: {toolboxVersion.Name}, version: {toolboxVersion.Version}");
Console.WriteLine($"MCP endpoint: {toolboxVersion.McpEndpoint}");
import { DefaultAzureCredential } from "@azure/identity";
import { AIProjectClient } from "@azure/ai-projects";

// Create Foundry project client
const projectEndpoint = "https://<your-foundry-account>.services.ai.azure.com/api/projects/<your-project>";
const project = new AIProjectClient(projectEndpoint, new DefaultAzureCredential());

const toolboxVersion = await project.toolboxes.createVersion(
  "reminder-toolbox",
  [
    {
      type: "reminder_preview",
      name: "schedule_reminder",
      description: "Schedule a reminder that re-invokes this agent at a future time.",
    },
  ],
  {
    description: "Built-in reminder tool for a self-scheduling agent",
  },
);
console.log(`Created toolbox: ${toolboxVersion.name}, version: ${toolboxVersion.version}`);
console.log(`MCP endpoint: ${toolboxVersion.mcpEndpoint}`);
POST https://{project_endpoint}/toolboxes/reminder-toolbox/versions?api-version=v1
Authorization: Bearer {token}
Content-Type: application/json

{
  "description": "Built-in reminder tool for a self-scheduling agent",
  "tools": [
    {
      "type": "reminder_preview",
      "name": "schedule_reminder",
      "description": "Schedule a reminder that re-invokes this agent at a future time."
    }
  ]
}

注释

获取持有者令牌时使用令牌范围 https://ai.azure.com/.default 。

响应包含mcp_endpoint。 将托管代理连接到此终结点。

创建工具箱清单文件:

# reminder-toolbox.yaml
description: Built-in reminder tool for a self-scheduling agent
tools:
  - type: reminder_preview
    name: schedule_reminder
    description: Schedule a reminder that re-invokes this agent at a future time.

创建工具箱:

azd ai toolbox create reminder-toolbox --from-file reminder-toolbox.yaml

该命令输出工具箱 MCP 端点。 将托管代理连接到此终结点。

配置托管代理

创建工具箱后,将托管代理配置为使用它。 在代理清单中,在 resources 下添加工具箱端点:

# agent.yaml
name: reminder-agent
model_deployment: gpt-4.1
instructions: |
  You are a helpful assistant. When the user asks you to follow up later,
  use the schedule_reminder tool to re-invoke yourself after the specified time.
resources:
  - kind: toolbox
    url: https://{project-endpoint}/agents/toolboxes/reminder-toolbox/mcp?version=1

示例场景:轮询任务完成状态

一种常见场景是轮询外部系统以检查任务是否完成。 在此模式中,代理:

  1. 收到用户发出的启动长期运行任务的请求。
  2. 调用外部 API 以启动任务并接收任务 ID。
  3. 使用提醒工具安排 15 分钟后的后续跟进。
  4. 当提醒触发时,代理将检查任务状态。
  5. 如果任务仍在运行,智能体会再次安排提醒。
  6. 任务完成后,代理会通知用户。

若要启用此行为,请在代理清单中包含说明:

# agent.yaml
name: task-monitor
model_deployment: gpt-4.1
instructions: |
  You help users monitor long-running tasks.
  
  When a user asks you to start a task:
  1. Call the start_task tool with the user's parameters.
  2. Note the task_id in your response.
  3. Use the schedule_reminder tool to check back in 15 minutes.
  
  When you're re-invoked by a reminder:
  1. Call the check_status tool with the task_id.
  2. If the task is still running, schedule another reminder for 10 minutes.
  3. If the task is complete, summarize the results for the user.
resources:
  - kind: toolbox
    url: https://{project-endpoint}/agents/toolboxes/my-toolbox/mcp?version=1

模型根据这些说明决定何时以及如何使用提醒工具。 无需编写代码来处理提醒调用。

局限性

  • 仅限托管代理。 提醒工具仅适用于托管代理。 不能与提示代理一起使用。
  • 同一对话。 提醒会在同一对话中再次调用智能体。 他们不会开始新的对话。
  • 最小延迟。 最小延迟为 1 分钟。
  • 最大延迟。 最大延迟为 43,200 分钟(30 天)。