Skip to content

Run a Tool-Enabled Agent ​

Use streamAgent on a bound AI Scene when the backend needs to run a bounded tool loop and await its result rather than consume SDK events itself:

ts
const result = await scene.streamAgent({ messages, tools, maxSteps: 4, abortSignal });

Supply the tools the caller is allowed to use. maxSteps caps the number of model steps, and an optional stopWhen can end the loop sooner. For text without tools, pass maxSteps: 1. The result distinguishes finished, aborted, and failed; a finished result includes the model's finish reason, final-step text, tool call counts, and aggregate usage. finished describes the stream, not whether the application should accept or publish its result. An optional onText receives provisional text events, including text from intermediate steps. Omit it if the application must review the result before showing text to a user.

Each model step is subject to the Scene's input, output, and timeout limits. This API runs the tool loop; it does not provide the built-in Chat review and confirmation flow. The caller owns application admission, disclosure, and any required user review.

Select local tools in backend code ​

Trusted backend callers can pass toolNames to this.$scope.cabloyAi.service.agent.prepareTools({ siteId, userId, limits, deadlineAt, signal, toolNames }) inside the active request. This opens the local Catalog and returns a request-local callback. Call it with the run's progress emitter to resolve current visibility and create the tool runtime; pass the runtime's options to streamAgent(). The callback can return undefined if no tools are visible. Keep the application responsible for handling progress, rechecking disclosures before publishing results, and persisting any proposal for user confirmation.

Omit toolNames for the default behavior (all currently visible tools); [] skips tool preparation. Use exact, case-sensitive published Controller tool names. Repeated names are deduplicated. If any requested name is unknown or inaccessible, preparation fails without identifying the name or falling back to other tools. The selection narrows declarations, calls, and contract lookups; it does not grant access. Chat's HTTP API does not accept this option, and it does not select tools from a remote MCP server.

Use skillPaths on the same backend call to select the Skill files independently of toolNames. For bundled files, resolve each path with this.app.util.getAssetPathPhysical('cabloy-ai', 'skills', '<name>/SKILL.md'). A nonempty list replaces defaults; omitting skillPaths or passing [] discovers all bundled */SKILL.md files. Each file declares a unique lowercase name (letters, digits, and hyphens) and a nonempty description in YAML frontmatter. Invalid metadata or duplicate names fail activation, not fall back to another Skill. Only trusted backend code supplies paths; the model and Chat HTTP API cannot supply paths or read other files through the loader. toolNames: [] still skips the entire tool runtime.

Released under the MIT License.