Skip to main content
--- title: “Automate agents with routines” description: “Create, manage, and monitor routines that trigger agents on a schedule, at a specific time, or in response to an external event.” manager: mcleans ms.service: microsoft-foundry ms.subservice: foundry-agent-service ms.topic: how-to ms.date: 08/27/2026 author: zhuoqunli ms.author: zhuoqunli ms.custom:
  • dev-focus
  • doc-kit-assisted
  • references_regions

ai-usage: ai-assisted

Automate agents with routines

A routine is a named automation rule that triggers an agent on a schedule, at a specific time, or in response to an external event. You define what fires the routine (the trigger) and what agent to invoke (the action). Microsoft Foundry queues the invocation, runs the agent, and stores a run record you can inspect later. This article shows you how to create, manage, and monitor routines by using the Foundry portal, the REST API, the Python SDK, .NET SDK, JavaScript SDK, or the Azure Developer CLI.
All routine operations are on the data plane under your project endpoint.

Prerequisites

The Foundry RBAC roles were recently renamed. Foundry User, Foundry Owner, Foundry Account Owner, and Foundry Project Manager were previously named Azure AI User, Azure AI Owner, Azure AI Account Owner, and Azure AI Project Manager. You might still see the previous names in some places while the rename rolls out. The role IDs and core permissions are unchanged by the rename.
  • A prompt agent or hosted agent. Workflow agents aren’t supported. By default, a routine invokes the agent by using the agent identity. If the agent has tools that require delegated user access, explicitly select the routine creator’s identity when you create the routine.
Routines are available in all Foundry regions except the following. Confirm that your Foundry project isn’t provisioned in one of these regions before you create a routine:
  • UK West
  • Switzerland West
  • Japan West
  • UAE North
  • Norway East
Routines work with projects secured by a virtual network. Because a routine uses the project’s existing agent invocation path, it inherits the project’s network configuration and doesn’t require extra networking setup. For more information, see Set up private networking for Foundry Agent Service.Routines don’t support customer-managed key (CMK) encryption. Don’t use routines for workloads that require CMK protection.

Create and test a scheduled routine

For the fastest path to a working routine, use the scheduled routine example and verify the complete lifecycle:
  1. Create a recurring scheduled routine that invokes your agent.
  2. Dispatch the routine manually instead of waiting for its schedule.
  3. Inspect the run history and confirm that the run completes.
  4. Delete the routine after you finish testing.

Choose a trigger or task

After the scheduled routine succeeds, choose the trigger or management task that fits your scenario.

Supported trigger types

Routines support the following trigger types:

Supported action types

Each routine specifies exactly one action that runs when the routine fires. Two action types are supported: For required and optional fields of each action type, see Action fields.

Choose a dispatch identity

Every routine uses the agent identity by default. This default applies to schedule, timer, GitHub issue, and Teams event routines. The agent’s permissions determine which resources its tools can access. If the agent has tools that require delegated user access, explicitly opt in to creator identity when you create the routine. Creator identity means only the Microsoft Entra identity of the person or service principal that creates the routine. It isn’t the identity of the agent creator, agent publisher, connection creator, a later routine editor, or another end user. Set the top-level authorization.identity field to "creator" in a REST create request or JavaScript create options. In Python, pass RoutineAuthorization(identity="creator"). Omitting authorization, or setting the identity to "agent", uses the default agent identity. The following examples create a disabled routine and retrieve it to confirm that authorization.identity is stored as "creator". Successful creation and retrieval confirm the saved configuration, not compatibility with every delegated tool. Check each tool’s authentication requirements and the creator’s permissions and consent separately. The authorization setting is accepted only when you create a routine. An update ignores it. To switch an existing routine between agent and creator identity, delete and recreate the routine with the required authorization.identity value. Creator identity has these constraints:
  • The routine delegates only the routine creator’s identity. You can’t supply an arbitrary user identity at dispatch time.
  • The creator must have access to every delegated resource the agent’s tools use. If that access or consent is removed, those tool calls fail.
  • Recreating the routine as a different principal changes the routine creator identity.
  • Authentication for an event trigger’s connector connection is separate from the identity used to dispatch the agent. The authorization object doesn’t change the connection identity.

Create a routine

A routine definition specifies a trigger (when to fire) and an action (which agent to run and through which API). A routine supports exactly one trigger entry.

Schedule trigger

A schedule trigger fires repeatedly on a cron expression. The service enforces a minimum interval of five minutes.

Timer trigger

A timer trigger fires once at a specific future date and time, or after a duration from now.

Event-based triggers

An event-based trigger runs an agent when an external event occurs, such as a GitHub issue being opened or a message being posted to a Microsoft Teams channel. Event-based triggers rely on a connector connection that Foundry provisions in your account’s connector namespace and uses to authenticate to the external system. The trigger references this connection by ID. For more about connector connections, see Add managed MCP servers powered by connector namespaces. The connector connection authenticates with the external system independently of the routine’s dispatch identity. If the connection owner loses access to the connected resource, the trigger stops firing. Selecting creator identity for dispatch doesn’t change the connector connection identity. Routines support two event-based triggers: the github_issue trigger and the custom trigger with the teams provider.
Non-Microsoft tools including third-party MCP servers available in the Foundry Tools Catalog (“Third-Party Tools”) are Non-Microsoft Products under your agreement governing use of Azure. When you connect to a Third-Party Tool, you do so at your own risk. You’re responsible for any terms and charges for Third-Party Tools. Microsoft has no responsibility to you or others in relation to your use of Third-Party Tools. Carefully review and track the Third-Party Tools you add to your MCP client.Some of your information and data (such as authentication keys and prompt content) might be passed to the Third-Party Tool, or your MCP client might receive data from the Third-Party Tool. Review all data shared with Third-Party Tools and stay aware of third-party practices for data retention and location. You’re responsible for managing whether your data flows outside your organization’s Azure compliance and geographic boundaries.MCP implementations are vulnerable to attacks, cascading failures, and loss of human oversight. To mitigate these risks, vet MCP servers for security and reliability, follow Microsoft’s recommendations and industry best practices, and implement approval mechanisms to monitor cascading behaviors.

GitHub issue trigger

A github_issue trigger fires when an issue is opened or closed in a watched GitHub repository. When the trigger fires, Foundry forwards the GitHub issue payload to the agent as its input, so the agent can triage or act on the issue. The trigger relies on a GitHub connector connection. Foundry provisions the connection to GitHub in your account’s connector namespace and authenticates to GitHub through it. The connection_id you set on the trigger references this connection. Each tab shows how to create the connection and the routine that uses it. For more about connector connections, see Add managed MCP servers powered by connector namespaces. The issue_event field accepts opened or closed only. When an issue event fires, the GitHub issue payload replaces action.input. The configured input applies only to manual test dispatches.

Teams message trigger

A custom trigger fires on an event from an external provider. The teams provider supports the on_new_channel_message event, which fires when a new message is posted to a watched Microsoft Teams channel. When the trigger fires, Foundry forwards the Teams message payload to the agent as its input, so the agent can respond to the message. The trigger requires a Microsoft Teams connector connection. Foundry provisions the connection in your account’s connector namespace and uses it to authenticate to Teams. The connection_id in the trigger’s parameters references this connection. For more about connector connections, see Add managed MCP servers powered by connector namespaces. The parameters object scopes the trigger to a single Teams channel. Set thread_type to channel, group_id to the ID of the Teams team that contains the channel, and channel_id to the ID of the channel to watch. You can obtain the team and channel IDs from Microsoft Teams or Microsoft Graph. The authenticated Teams connection must have access to the specified team and channel.

Action fields

Each routine specifies exactly one action. The two supported action types have different required and optional fields.

Responses API action (invoke_agent_responses_api)

Invokes the agent through the Responses API.

Invocations API action (invoke_agent_invocations_api)

Invokes the agent through the Invocations API.

Dispatch authorization

Dispatch authorization is a top-level routine creation field, not an action field.

Enable and disable a routine

Routines start enabled if you set "enabled": true at creation. You can pause a routine without deleting it.

Test a routine manually

Queue a one-off run without waiting for the trigger to fire. This step lets you verify that the routine reaches your agent correctly.

View run history

Run history records every time a routine fires and the outcome of each attempt.

List and retrieve routines

Update a routine

To change a routine’s trigger or action, send a new create-or-update request with the same name. This operation replaces the stored definition.

Delete a routine

When you delete a routine, you remove it and stop all future trigger deliveries. The process preserves existing run records.

Trigger fields

Schedule trigger fields

Timer trigger fields

GitHub issue trigger fields

Custom (Teams) trigger fields

For the teams provider, parameters accepts the following fields:

Dispatch behavior and retry policy

When a trigger fires or you call :dispatch_async manually, Foundry acknowledges that the run was enqueued. The acknowledgment doesn’t mean the downstream agent call finished. Use the run state, telemetry, or the returned dispatch_id to confirm completion.

Downstream call outcomes

The delivery worker waits for the downstream invoke_agent_responses_api or invoke_agent_invocations_api HTTP call to finish before marking the run. If retries are exhausted, the run is marked failed with the last dispatch error. A successful run means the downstream API accepted the dispatch request. It doesn’t guarantee that asynchronous work started by the agent has completed.

Retry and timeout defaults

  • The default delivery policy is three total attempts with exponential backoff starting at 1 second and capped at 5 seconds.
  • The downstream HTTP request has a per-attempt timeout of 30 seconds. Queueing time, retry backoff, and worker concurrency limits aren’t included in that per-request timeout.

Troubleshooting

Let an agent schedule its own reminders

Routines let an external trigger start an agent. A hosted agent can also schedule itself to run again at a future time by calling the built-in reminder_preview toolbox tool. Use this pattern when the agent decides during a run that it needs to follow up later, such as to check back on a long-running task. The reminder tool is available only for hosted agents. You can’t use the reminder tool with prompt agents. When the agent calls the reminder tool, it specifies a delay in minutes. After that delay, Foundry re-invokes the same agent on the same conversation. The agent can then continue its work or check on external systems. For full setup instructions, usage examples, and how reminders differ from routines, see Reminder tool for self-scheduling agents.

Known issues and limitations

Routines have the following known issues and limitations:
  • One trigger and one action per routine. Each routine supports exactly one entry in the triggers map and one action. To run multiple agents or multiple schedules, create separate routines.
  • Agent types. Routines support prompt agents and hosted agents. They don’t support workflow agents. The agent-scheduled reminder tool is available only for hosted agents.
  • Routine and trigger types. Routines can be one-shot (timer), recurring (schedule), or event-based. Supported event triggers are github_issue and custom with the teams provider. Other routine and trigger types aren’t supported.
  • Action types. The only action is invoking one Foundry agent. Use invoke_agent_responses_api with a prompt agent or a hosted agent that exposes the Responses protocol. Use invoke_agent_invocations_api with a hosted agent that exposes the Invocations protocol.
  • Dispatch identity. Every routine uses agent identity by default. Creator identity is an explicit create-time opt-in for agent tools that require delegated user access. It always represents the principal that creates the routine, not the agent creator or another user. You can’t change the dispatch identity by updating the routine.
  • Network and encryption. Routines support projects secured by a virtual network and inherit the project’s network configuration. Routines don’t support customer-managed key (CMK) encryption.
  • Schedule minimum interval. A schedule trigger fires at most once every five minutes. Cron expressions that resolve to a shorter interval are rejected.
  • Regional availability. Routines aren’t available in UK West, Switzerland West, Japan West, UAE North, or Norway East. If you don’t see Routines in the Foundry portal navigation, the feature isn’t enabled for your region or subscription.
  • Use :dispatch_async for manual dispatch. Only the POST .../routines/{routineName}:dispatch_async?api-version=v1 route is part of the public contract. The legacy :dispatch route isn’t supported for customer use.
  • Acknowledgment isn’t completion. A :dispatch_async response acknowledges that the run was enqueued, not that the downstream agent call finished. Use the run state, telemetry, or the returned dispatch_id to observe final delivery.
  • Per-attempt timeout. The downstream HTTP request to the agent has a per-attempt timeout of 30 seconds. Queueing time, retry backoff, message-bus delivery time, and worker concurrency limits aren’t included in that timeout. Requests that exceed the per-attempt timeout are retried per the retry and timeout defaults. The routine run is marked failed if all attempts time out.
  • Successful delivery doesn’t guarantee end-to-end completion. A completed routine run means the downstream API returned success for the dispatch request. It doesn’t guarantee that asynchronous work started by the agent has finished.