defineSkill
Define AI agent skills
defineSkill
Define AI agent skills
Skills define reusable instructions and capabilities that AI agents can use within your workspace. Use Key points:
defineSkill() to define skills with built-in validation:src/skills/example-skill.ts
nameis a unique identifier string for the skill (kebab-case recommended).labelis the human-readable display name shown in the UI.contentcontains the skill instructions — this is the text the AI agent uses.icon(optional) sets the icon displayed in the UI.description(optional) provides additional context about the skill’s purpose.
defineAgent
Define AI agents with custom prompts
defineAgent
Define AI agents with custom prompts
Agents are AI assistants that live inside your workspace. Use Key points:Schema notes:
defineAgent() to create agents with a custom system prompt:src/agents/example-agent.ts
nameis the unique identifier string for the agent (kebab-case recommended).labelis the display name shown in the UI.promptis the system prompt that defines the agent’s behavior.description(optional) provides context about what the agent does.icon(optional) sets the icon displayed in the UI.modelId(optional) overrides the default AI model used by the agent.responseFormat(optional) controls the shape of the agent’s output. Defaults to{ type: 'text' }for free-form text. Use{ type: 'json', schema }to force structured JSON output.
responseFormat to { type: 'json' } and provide a schema:src/agents/structured-agent.ts
- The schema is a flat object: each property’s
typemust be a primitive (string,number, orboolean). Nested objects and arrays are not supported. description(optional) on each property guides the model on what to put there.required(optional) lists the properties the model must always return.additionalProperties: false(optional) forbids any property not declared inproperties.
runAgent
Run an agent from a logic function
runAgent
Run an agent from a logic function
runAgent() lets a logic function run one of your app’s agents (with its
skills and tools). Identify the agent by the universalIdentifier you passed
to defineAgent(). Pass either a prompt string or a messages conversation
history — not both:src/logic-functions/run-enricher.ts
messages instead of a single prompt:src/logic-functions/reply-in-thread.ts
- Provide exactly one of
prompt(string) ormessages(1 to 100 entries of{ role: 'user' | 'assistant', content: string }). Ausermessage can also carry file attachments — see below. - The agent runs synchronously and can read/update records itself via its
own tools —
runAgent()resolves once the run completes. - An app can only run its own agents.
- The app’s default role must grant the
AIpermission flag — addSystemPermissionFlag.AIto itspermissionFlagUniversalIdentifiers(or setcanAccessAllTools: true). Without it,runAgent()fails with a permission error. - Set a generous
timeoutSecondson the logic function — agent runs can take several seconds. successistrueandresultis non-null when the run completes; on failuresuccessisfalse,resultisnull, anderrorholds the reason (for example, when the workspace ran out of AI credits mid-run).
src/roles/default-role.ts
Sending files with a message
Auser message can carry attachments, so the agent sees a screenshot or a
PDF instead of only its name. Each entry references a file your app has already
uploaded into the agent-chat folder:src/logic-functions/describe-screenshot.ts
UPLOAD_FILE permission flag on the app’s default role,
alongside AI. filename is optional and only labels the file for the model.- Only
usermessages may carry attachments. They cannot be represented on an assistant turn, sorunAgent()rejects them there rather than dropping them. - At most 10 attachments per message.
- The
fileIdmust name a fully uploaded file in the same workspace, under theagent-chatfolder. Anything else fails the call instead of quietly answering without the file.
Running on behalf of a workspace member
PassrunAsWorkspaceMemberId when the run is triggered by a person — a chat
bot answering a message, for instance — so the agent acts as that member
instead of as the app:src/logic-functions/answer-question.ts
- A token with no user attached may name any member. A logic function runs
with one, and so do tokens minted through
client_credentialsor from an API key. - A token issued on behalf of a user, as a front component receives, may only name that user’s own member.