Dynamic Schedules
defineDynamicSchedules lets users and agents create recurring or one-time schedules while the agent runs. Export the definition from a file in agent/schedules/; the file path names it unless you set id. Use it when a user or the model picks the timing. For fixed cron jobs written in code, use defineSchedule instead.
The definition gives the model tools to manage schedules, and gives you a run callback that runs each time a schedule fires. Each firing is an occurrence. This API is experimental and may change. Import it from eve/experimental/schedules.
Define scheduled work
The model supplies a payload that matches inputSchema. eve records who created the schedule separately, and checks that creator's current access each time the schedule fires.
Options
| Field | Default | Purpose |
|---|---|---|
inputSchema | Required | Validates the payload from the model or client. |
auth | Required | Resolves the creator to current access. See Revalidate creator identity. |
run | Required | Runs each time a schedule fires. See Handle occurrences and retries. |
id | Name from the file path | Names the definition and the schedules stored under it. See Keep a stable identity. |
description | None | Text added to each management tool's description. |
scope | byPrincipal | Decides which caller can manage which schedules. |
scopes | None | Named scopes, in place of scope, for schedules with more than one owner. See Declare named scopes. |
provider | vercelScheduleProvider() | Stores schedules and fires them. See Choose a provider and test locally. |
preparePayload | None | Checks and reshapes the payload before eve saves it. See Prepare payloads and destinations. |
tool | true | How the model reaches the management tools. See Expose management tools. |
approval | User approval for changes | Approval policy for each operation the model calls. |
events | None | occurrence.dispatched and occurrence.failed handlers. |
scope decides who can manage a schedule. byPrincipal limits each caller to their own schedules, keyed by identity type, authenticator, issuer, and ID, plus the application and definition. A custom scope function must authorize each operation before it returns a namespace. Return null to deny.
Keep a stable identity
A definition's name comes from its path under agent/schedules/: agent/schedules/billing/requests.ts is billing/requests. eve stores each schedule under that name, and uses it in the management tool names, occurrence.collection, and ctx.session.schedule.definition. Renaming or moving the file changes the name, so schedules created under the old name are no longer listed or run.
Set id to fix the name whatever the path. To move a file and keep its schedules, set id to the old name:
An id has up to 64 ASCII letters, digits, _, and -, with / allowed between segments. The build fails when two collections, or a collection and a static schedule, in one agent have the same name, whether it comes from id or the path.
In an extension, a path-derived name takes the mount's prefix, such as crm__requests, so it changes with the mount filename. eve uses an id as written, without the prefix, so the extension's schedules keep one name in every agent that mounts it. Mounting that extension twice in one agent fails the build.
Expose management tools
Each definition adds one tool for each operation: create, get, list, update, enable, disable, invoke, and delete. Each tool has its own schema, approval policy, and action label. For example, agent/schedules/billing/requests.ts generates schedule__billing-requests__create, schedule__billing-requests__update, and so on. With an id, the tool names use it instead of the path.
| Tool | Input |
|---|---|
create | { name, expression, payload } |
update | { name, expression?, payload? }, with an expression or a complete payload |
list | Optional { cursor, limit }, with limit from 1 through 100 |
| All other operations | { name }, the unique name from receipts or reads |
Set tool to choose how the model reaches these operations:
tool | Behavior |
|---|---|
true (default) | Direct tools. |
"deferred" | The same tools, names, schemas, approval policies, and authorization checks, discovered with eve__search and called with eve__tool. See Dynamic capabilities. |
false | No tools; code-only scheduling. |
By default, reads need no approval and changes need user approval. Set top-level approval, keyed by operation, with ordinary request and response policies. Each operation's once() grants are independent.
toolInput.payload is also the prepared payload. Approval policies apply only to model calls, not to code that uses schedules(definition). So eve rejects approval with tool: false, in TypeScript and at runtime. Approvals don't bypass scope checks.
Declare named scopes
Some schedules have more than one owner: a person's own, and the ones a channel shares. Declare each owner as a named scope with scopes, in place of scope:
The definition still offers one set of tools, named for the file: schedule__workflows__create, schedule__workflows__list, and so on. Each takes a scope input, here "personal" or "channel", and the model sees each scope's description beside its name. The named scope's resolver authorizes the call, as scope does for a definition without names.
A scope is a resolver function, or an object that also says what the scope does differently:
| Field | Purpose |
|---|---|
resolve | Required. Authorizes each operation and returns the namespace, as scope does. |
description | Tells the model what the scope holds, beside its name. Without it, only the name is shown. |
id | The name the scope's schedules are stored under. Defaults to <definition>/<scope>, such as workflows/channel. |
preparePayload | Replaces the definition's preparePayload for this scope. It returns the same shape. |
run | Replaces the definition's run for this scope. |
approval | Policies that replace the definition's for this scope, operation by operation. |
The definition's description is added to every management tool as common instructions. A scope's description explains only that scope, beside its name in the tool's scope input.
inputSchema, auth, events, tool, and provider are the definition's, for every scope. A shared preparePayload or scope resolver reads which scope it acts for from context.scopeName.
Each scope stores its schedules apart, so occurrence.collection is the scope's stored name. To turn two existing definitions into one, set each scope's id to the old definition's name, and the schedules already stored there keep running:
| With named scopes | Behavior |
|---|---|
once() grants | Kept for each scope. Approving an operation for "personal" doesn't approve it for "channel". |
| A response policy | Decides who answers that scope's approvals. A scope without one keeps the default: only the requester answers. Once any scope sets one for an operation, each answer to that tool needs an authenticated responder. |
| Replacing the tools | The tool file named for the definition, agent/tools/schedule__workflows.ts, replaces or disables the set. |
| The client | schedules(definition, { scope: "channel" }) binds one scope. |
| Names that clash | The build fails when a scope's stored name, or the definition's tool name, is already another definition's. |
Use the authenticated client
Call the client inside an active eve context, not at module scope.
The name you pass is a display label, and several schedules can share it. It must start with an ASCII letter or digit, contain only letters, digits, ., _, or -, and have at most 256 characters. eve truncates it to 218 characters and appends -- plus a UUID to make the unique management name.
Receipts and reads return that unique name, which management calls take, plus displayName. In callbacks and events, they are occurrence.name and occurrence.displayName. Approval covers the label, timing, and payload, before the unique name exists.
Generated tools and the client check scope on every operation, including in scheduled turns and local delegated work. Scheduled sessions have no one present, so tools that change schedules and need human approval can't wait for it. Authorize these operations with approval policies, or use the client in your own code. Neither one bypasses scope checks.
Your tools, hooks, and channel events can read ctx.session.schedule. It is undefined for ordinary work. Scheduled work, including static schedules that run as a user, gets { definition, instance?, occurrenceId? }. It records where the work came from, not who is authorized. A custom scope function can read context.session.schedule to restrict scheduled callers. A new ordinary inbound message clears it; approval and input responses keep it.
Set timing
expression.type | Fields | Use for |
|---|---|---|
delay | minutes, a whole number from 1 through 525,600 | “In one minute”: { type: "delay", minutes: 1 } |
single | at, a YYYY-MM-DDTHH:mm local datetime, IANA timezone | One absolute time |
cron | cron, a five-field expression, IANA timezone | Recurring work |
Vercel Schedules takes numeric cron fields with *, ,, -, and /: months are 1-12 and weekdays are 0-6, where 0 is Sunday. An expression can't set both a day of the month and a day of the week. An expression that breaks these rules, such as one with MON or JAN, fails before the write is prepared, so a model's call is corrected before a person is asked to approve it. eve dev applies the same rules.
Omit timezone to use UTC. A delay starts when the approved write runs, not when approval is requested. It rounds up to the next minute, which adds up to 59 seconds before provider and execution latency. A separate client retry computes a new time, so a delay isn't idempotent across retries.
Update and control schedules
get and list return identity, timing, state, and timestamps, not payload or creator data. New schedules are always active. Use disable to pause future runs.
client.update(name, patch) changes timing, replaces the whole payload, or both. Timing-only updates keep the stored payload and creator and skip preparePayload. Payload replacement isn't a merge. It validates the complete new input, reruns preparation, and makes the updating caller the new creator. In a shared scope, permission to replace the payload is also permission to change who the schedule runs as.
Updates keep the management name, schedule ID, state, and destination. An update doesn't activate an inactive or completed schedule; use enable or disable to change state.
Updates, enable, disable, and delete affect future runs, not callbacks already started or running sessions. Delete-and-create gives a new schedule identity, but isn't atomic.
invoke(name) requests an extra run as the stored creator. It works on inactive schedules but not completed ones, and doesn't use up a pending one-time run. An accepted invocation doesn't mean the callback or agent succeeded.
Choose a provider and test locally
The built-in vercelScheduleProvider() uses Vercel Schedules in production and supports local development:
| Environment | Storage and delivery |
|---|---|
| Vercel deployments | Hosted Vercel Schedules delivers occurrences through Vercel Queues. |
eve dev without local Vercel Schedules | Process-local storage, with no background clock. Call invoke through the client to dispatch an occurrence. |
vc dev with local Schedules and Queues support | Local Vercel Schedules stores timing, and eve delivers due occurrences automatically through local Queues. |
| Self-hosted production | Create a provider for your application's storage and scheduling needs. |
On Vercel, schedules belong to the deployment's track, selected by its OIDC credentials. Preview schedules are separate from production schedules. Occurrences run on the track's current leader deployment, so schedules follow updates within that track.
Under vc dev, local queue errors appear in the dev server logs and retry after five seconds.
Import vercelScheduleProvider from eve/experimental/schedules/vercel to configure the Vercel endpoint explicitly. Import the in-memory provider from eve/experimental/schedules/testing for code-driven tests.
Create a provider for your use case
Create a provider when your application needs a different scheduling backend, storage system, or deployment environment. Implement ScheduleProvider from eve/experimental/schedules and pass it as provider to defineDynamicSchedules.
Your provider owns schedule storage, timing, and occurrence delivery. eve handles payload validation, management authorization, approvals, and creator revalidation.
| Part of the contract | What your provider implements |
|---|---|
| Management | create, get, list, update, enable, disable, invoke, and delete, plus a kind string identifying the provider. |
| Isolation | Restrict every operation to context.collection and context.namespace. |
| Storage | Preserve the supplied payload and delivery target. Return ScheduleRecord values without payload or creator data, and a SchedulePage from list. |
| Updates | Change only supplied fields. Preserve schedule identity, state, delivery target, and omitted fields. |
| Delivery | Deliver the stored payload with an occurrence's executionId, name, scheduleId, and scheduledAt. Keep executionId stable across retries. |
| Timing checks | Optional validateExpression, sync or async. Throw for a cron or one-time expression your backend can't run. eve calls it before it prepares a write. |
ScheduleProviderContext is also exported from eve/experimental/schedules. It supplies an abortSignal, an operationId for recognizing retried operations, and a delivery target. Use target.deliver, when present, to dispatch an occurrence through eve. Your backend must arrange when occurrences fire and how they retry; the management interface alone does not start a clock.
For fixed cron jobs without runtime management, use Schedules.
Handle occurrences and retries
run receives payload, occurrence, auth, schedule, to, and waitUntil. It can start any number of sessions or do application work directly.
to(channel, target).send(message, options) runs as the resolved creator and takes no auth argument. options takes context, history, idempotencyKey, outputSchema, and title, as on a route handler's to().send(). It takes no turnPolicy, because a send only reaches sessions the schedule started. It always starts a new session with no one present, through one of your channels, even when the target names an existing thread. Those sessions can't wait for approvals or questions, so configure tools to match.
schedule controls the schedule that fired the occurrence. schedule.disable() pauses its future runs, and schedule.delete() deletes it. Neither one calls scope, because an occurrence has no caller to authorize. Neither one stops the current run. On Vercel, a deleted schedule's occurrence isn't retried, so call schedule.delete() after the work that must finish. The handle's type, ScheduleHandle, is exported from eve/experimental/schedules.
After the callback and its waitUntil promises finish, eve calls occurrence.dispatched with sessionIds. That event means the callback succeeded, not that the agent finished its task. Channels send the output and report session failures.
Callbacks run at least once. Provider retries, including after an events handler fails, can repeat the callback. Deduplicate your own side effects with occurrence.executionId plus the schedule or resource identity.
A retried callback doesn't start its sessions again. eve keys each send by the occurrence, the target, and the message, so a repeat of the same send reaches the session the first attempt started. A message that differs between attempts, such as one that includes the current time, starts another session; pass your own idempotencyKey, such as `${occurrence.executionId}:digest`, to keep it to one. Keys are scoped to the schedule, and the usual limits apply.
occurrence.failed reports an occurrence that won't run: a permanent failure, such as auth returning null, or a provider that ran out of retries. Its reason says why.
Revalidate creator identity
auth({ principal, payload, occurrence, schedule }) turns the stored creator reference into current access. principal identifies the creator; it holds no credentials or permissions. Look up current account status and permissions instead of replaying credentials or roles captured at creation.
auth result | What happens |
|---|---|
{ attributes } | The run uses the stored creator's identity with these attributes. |
A full SessionAuthContext | The run uses it. Its identity type, authenticator, issuer, ID, and subject must match the creator reference, or the occurrence fails. |
null | The occurrence fails without a retry, and run isn't called. |
| A thrown error | The provider retries the occurrence. Throw when a lookup fails, so an outage doesn't read as a denial. |
A result of any other shape also fails the occurrence without a retry. On Vercel and under vc dev, occurrence.failed reports these failures. With process-local storage, the invoke call that dispatched the occurrence rejects instead. Type a standalone auth helper's return value as ScheduleAuthResult, exported from eve/experimental/schedules.
A denial fails only the current occurrence; a recurring schedule keeps firing and failing. When a denial is permanent, such as a removed account, stop the schedule through schedule before you return null:
eve never falls back to app identity. Manual invoke runs as the creator, not the caller. Tool and connection authorization still applies during the run.
Prepare payloads and destinations
Without preparePayload, eve validates payloads before saving and again before each run. Each saved write, including timing and payload, is limited to 64 KB. Store JSON data and stable references, not credentials or sensitive recipient details.
preparePayload(input, context) checks application policy, reads the caller's context, and returns the shape eve saves. It runs on creation and payload replacement, after input validation and scope authorization:
| Caller | When preparation runs |
|---|---|
| Model tool call | Before approval, so errors reach the model before a person is asked, and again before writing. Approval policies receive the prepared payload. eve rejects the call if the second result differs. |
| Authenticated client code | Once, before writing, with no approval. |
Preparation can repeat when a write is retried, so avoid irreversible effects. Reads, timing-only updates, state changes, and runs never call it.
context.expression is the timing the schedule has after the write: the one the caller passed, or the stored one when an update replaces only the payload. Read context.expression.type to tell a recurring schedule ("cron") from a one-time one, so the payload doesn't need a field for it. A relative delay arrives as written, not resolved to a time.
A timing-only update doesn't call preparePayload, so a value you derive from context.expression keeps the timing it was prepared with. Vercel Schedules rejects an update that changes a schedule between recurring and one-time. With another provider, send the payload again when you change a schedule's kind.
auth, run, and occurrence events infer the prepared return type. Declare preparePayload before them, or give it an explicit return type. Without preparation, the payload type comes from the schema.
Before each run, eve checks only the saved payload's size and JSON validity, not inputSchema. Validate the prepared shape yourself if needed.
For channel messages, preparePayload can check trusted caller context and save channel and workspace references that the model-facing schema doesn't expose. Reject callers that lack the required channel context, including delegated work when appropriate. Payload replacement captures the destination and creator again from the updating caller.
Destination IDs are optional. run can derive a DM from the creator, pick an authorized configured channel, or look up a destination from another payload value. A schema may expose explicit IDs, but a valid ID doesn't prove access, and scope doesn't authorize sending everywhere. Check model-selected destinations against the creator's current permissions.
eve doesn't save the conversation that created a schedule. To reply in that thread, save an authorized thread reference through preparePayload or application code. Save a destination reference whenever the destination must stay fixed, because lookups at run time follow configuration changes.
Troubleshooting
| What you see | What to do |
|---|---|
vercelScheduleProvider() requires a Vercel deployment or eve dev. | Use eve dev or a Vercel deployment with this provider, or create a provider for your use case. |
Prepared schedule write exceeds the 64 KB limit, including timing and payload. | Store stable references instead of large data in the payload. |
Scheduled execution is no longer authorized: "auth" returned null for the schedule creator. | auth denied the creator. Restore their access, or delete the schedule. |
Scheduled execution auth must resolve the schedule creator. | Return { attributes } from auth, or a SessionAuthContext whose identity matches principal. |
What to read next
- Schedules: author fixed cron jobs with
defineSchedule. - Channels: deliver schedule output to users.
- Sessions, runs & streaming: inspect a scheduled run.