Triggers

Triggers let an agent speak up on its own when something happens, instead of waiting to be asked. For example:

  • a museum guide starts talking about the artwork a visitor stops at
  • a field coach points out a tool left in the wrong place
  • a build coach notices a skipped step
  • an agent checks in after a long silence

A trigger watches for one kind of moment: something the user said, something the camera saw, or time passing. It can ask a model to look at the camera frame, the conversation, and reference files, then decide whether the agent should say something. The agent says it in its own voice, without talking over the user.

Add a trigger

Ask Builder, for example: "When the visitor looks at an artwork, tell them one fact about it." Builder writes the trigger into the agent's files.

The Triggers section of the agent's configuration lists every trigger and marks the ones that need a fix. To remove a trigger, delete its file.

The Triggers section of an agent's configuration: the model that triggers ask, and one trigger with its title, what it does and its file.The Triggers section of an agent's configuration: the model that triggers ask, and one trigger with its title, what it does and its file.

To see a trigger at work, run the agent. The inspector beside the run shows when each trigger acted and why.

Technical reference

Exact names, paths, values and limits, for developers and AI assistants.

Trigger files

A trigger is a JavaScript module at data/triggers/<name>.trigger.js in the agent's folder: agents/<agent id>/data/triggers/<name>.trigger.js in the organization's files. Every valid file there runs in the agent's sessions. There is no list to attach it to and no switch to turn it off: to stop a trigger, delete its file. <name> uses lowercase letters, digits, and hyphens, such as check-in.trigger.js; any other file name is shown as needing a fix.

The module exports:

  • schemaVersion = "worldagents.trigger.v2" (required).
  • metadata, an object with a title and a summary (both required). The Triggers section shows them.
  • interests, the list of events the trigger runs on (required, see Events).
  • evaluate(ctx), which returns a list of decisions (required, see Decisions).
  • configSchema, an object schema whose property defaults reach the trigger as ctx.config (optional).
  • frameIntervalMs, timerIntervalMs, timeoutMs, and model (optional, described below).

A complete trigger:

  export const schemaVersion = "worldagents.trigger.v2";

export const metadata = {
  title: "Regular check-in",
  summary: "Asks whether the user needs help, at most once every five minutes.",
};

export const interests = ["timer"];
export const timerIntervalMs = 60000;

export async function evaluate(ctx) {
  if (ctx.cooldowns.has("check-in")) {
    return [];
  }
  return [{
    type: "speak",
    instruction: "Ask in one short sentence whether the user needs help.",
    cooldowns: [{ key: "check-in", cooldownMs: 300000 }],
    inspector: { title: "Check-in", summary: "No check-in in the last five minutes." },
  }];
}

A file that cannot be loaded does not run. The Triggers section shows it with the reason, such as an unsupported schemaVersion, a missing metadata.title, or an unknown name in interests. There is no tool that validates a trigger file, so after writing one through AI connections, ask the user to look at the Triggers section. Start a new session to try a change.

An agent.json saved before triggers became files may still hold a triggerRefs list. It is ignored: every trigger file in the folder runs.

Events

interests names the events a trigger runs on:

  • text.turn: the user finished a turn; ctx.text.latestUserText holds it. In chat, a speak decision answers instead of the model. In voice, the turn ends when the agent starts its reply, so a speak decision follows that reply, or cuts in with interrupt. A decision is dropped once the user's next turn closes, when they talk over the agent, or after 30 seconds.
  • visual.proactive_candidate: the camera recognized objects; ctx.visual.recognizedObjects lists them. It fires whether or not the conversation already covered them, so a trigger that should not repeat a story checks ctx.conversation.recentTurns itself. Only the camera recognizes: objects SIE merely expects in view from the visitor's position never fire it and sit in ctx.visual.latestContext.expectedObjects.
  • visual.frame: a camera frame. Frames reach the server about once a second.
  • timer: a regular tick in a voice session, camera or not, for nudges after silence or periodic check-ins.

How often it runs

A visual.frame trigger runs at most every frameIntervalMs (default 5000, from 1000 to 60000). A timer trigger runs every timerIntervalMs (default 60000, from 1000 to 3600000). Both count from the start of the last evaluation, and a trigger still busy when it is due again is skipped.

  export const interests = ["visual.frame"];
export const frameIntervalMs = 2000;

Each trigger keeps its own pace and runs one evaluation at a time per session, alongside the other triggers. A recognition event that arrives while it is busy is evaluated right after. A slow text.turn trigger delays the reply.

timeoutMs is the deadline for one evaluation: 10 seconds by default, from 1 to 60 seconds. Past it, the evaluation and its model call are dropped.

Asking the model

ctx.llm.generate asks the model about the moment. Pass includeCurrentFrame: true for the camera frame, messages for the conversation, data for anything else, and schema (a JSON Schema) to get a structured answer in json:

  const { json } = await ctx.llm.generate({
  system: "You check the build in the camera frame against the current step.",
  files: ["build-guide.md", `manual/step-${step}.png`],
  includeCurrentFrame: true,
  data: { currentStep: step },
  schema: {
    type: "object",
    properties: { shouldSpeak: { type: "boolean" }, about: { type: "string" } },
    required: ["shouldSpeak", "about"],
  },
});
  • files sends up to eight files from the agent's data/ folder, or the organization's files with a shared: prefix. JPEG and PNG pictures go as images (scaled down); anything else must be UTF-8 text. Files go first, so files that stay the same between calls can be cached.
  • An evaluation may make up to three calls. The model thinks at a low level by default; thinking: "high" thinks longer.

Which model

The calls run on the agent's trigger model, picked in the Triggers section of its configuration (triggerModel in agent.json), or on the default model shown there when none is picked. A trigger file can pick its own:

  export const model = "gemini-3.5-flash-lite";

Only Google models that read images and answer in JSON are offered; any other name makes the file need a fix. A smaller model answers sooner but judges a picture less strictly, so check it against real frames before switching.

What the trigger can read

  • ctx.conversation.recentTurns: the last twelve messages.
  • ctx.conversation.recentToolCalls: the agent's last twelve tool calls, each with toolId and arguments. For example, a trigger can read the step from the manual page the agent opened last.
  • A trigger keeps no state between evaluations. Cooldowns are the only thing that lasts.
  • ctx.visual.recognizedObjects: what the camera recognizes now, each with objectId, title, artist, room, confidence, visibility.box, platformData and diagnostics.
  • ctx.visual.latestContext: the whole latest recognition. type is object_recognized or none_recognized; the first recognized object's fields (objectId, title, ...) sit at its top level beside summary, spatialContext, pov and expectedObjects.
  • ctx.visual.recentlySeen lists what the camera recognized in the last ten minutes, newest first, up to ten objects: {objectId, title, artist, date, room, seenCount, firstSeenAt, lastSeenAt, secondsAgo}. Recognition often loses an object for a while, so a trigger can come back to one it saw while the agent was busy.
  • ctx.visual.latestFrame: the camera frame's source, width, height, capturedAt and hasImage, when there is one.

Decisions

evaluate returns a list of decisions, or [] to stay quiet. At most the first four decisions of one evaluation are used.

  • { type: "speak", message } says the message as written.
  • { type: "speak", instruction } asks the agent to say or do something in its own words. If both message and instruction are set, voice uses the instruction and chat uses the message.
  • { type: "none", inspector } says nothing and only updates the inspector.
  • priority orders decisions across triggers (lower first, default 100). The first speak decision is delivered.
  • inspector: { title, summary, fields } shows in the session inspector why the trigger acted. fields is a list of [label, value] pairs.
  • Without interrupt, a speak decision waits until the agent and the user are quiet, and is dropped if that does not happen. No decision ever talks over the user or a running tool call.
  • An agent that has the stay_silent tool can decline a speak decision by calling it: the turn ends with no reply and the decision completes as silent.
  • The old text, dedupeKey, and top-level cooldownMs fields are rejected, and the inspector shows which field to use instead.

Cooldowns

  • cooldowns: [{ key, cooldownMs }] on a decision drops later decisions with the same key from the same trigger until the time passes.
  • A cooldown starts when the decision goes to the agent, and starts over when its reply is heard.
  • It holds even if the user talks over the reply or the agent declines it, since the agent already has the message.
  • It is given back when the agent never got the message or produced nothing for it, and when another trigger cut in before the reply was heard.
  • ctx.cooldowns.has(key) and ctx.cooldowns.set(key, ms) work on the same keys.

Interrupting

  • interrupt: true lets a speak decision cut the agent off. It works in voice only.
  • A talking agent first finishes its phrase, then stops.
  • The decision's turn tells the agent where the user stopped hearing it, quoting the last words they heard, so it can pick up from there. The same note reaches the agent when the user talks over it.

Silent context

context on a decision is silent context: the agent knows it from its next reply on, without anyone saying anything, until the trigger sends another one. It works in voice only.

  • Use it for state the agent must always answer from, such as the position of a game the trigger tracks. A spoken decision is not reliable for that, because it is dropped whenever the agent or the user is not quiet.
  • The limit is about 4000 tokens (16000 characters). A longer context is cut, and a note at the end tells the agent so.
  • The agent gets it under a label that names the trigger file, and is told that the label comes from the app, not the user, and that the newest context counts.
  • Sending the same text again resends nothing. Any change resends all of it, so leave out what changes on its own, such as a clock or a counter.
  • A decision dropped for a running cooldown drops its context too. Send context on a none decision of its own, within the first four decisions; later ones are dropped.

Where triggers run

Each evaluation runs in a fresh sandbox, away from the rest of the server and with no network, so a trigger cannot call an outside service. Voice and chat sessions both run triggers.

Recognition names in v1 files

worldagents.trigger.v1 files still work and still read the older recognition names. Those names are deprecated, so write new triggers as v2. A v1 file gets the v2 names and, beside them:

v2Also in v1
ctx.visual.recognizedObjectsctx.visual.recognizedArtworks
objectId, in every object and in latestContextartworkId
latestContext.expectedObjectslatestContext.expectedArtworks
latestContext.type: object_recognized, none_recognizedartwork_recognized, no_artwork_recognized

A type is a value, not a key, so the two cannot sit side by side: a v1 file sees only the old type values. To move a file to v2, set its schemaVersion, rename these reads, and compare type with the new values.