Superego

Tools and prompts

An agent part gives a profile's agents tools and pieces of system prompt. Superego's agents run on pi-durable, and agent parts are its extensions: defineExtension, defineTool and section, imported from 'superego'.

import { defineExtension, defineTool, section } from 'superego'

export default defineExtension({
  name: 'orders',                      // lowercase, unique in the profile
  tools: [findOrder],
  sections: [section('orders_policy', () => 'Refunds over $100 need a human. Say so instead of promising one.')],
})

Name it in a profile's extensions (a module's default export), or hand it to superego.agent(…) from a daemon extension's setup when it needs the daemon's API too (superego --skill daemon).

Tools

const findOrder = defineTool({
  name: 'find_order',                  // what the model calls; snake_case
  description: 'Find an order by its number. Returns its lines, status and shipping.',
  parameters: obj({
    number: str({ minLength: 1 }),
    include: opt(union([lit('lines'), lit('shipping')], { description: 'what to add' })),
  }),
  async execute({ number }, api, context) {
    api.output(`looking up ${number}…\n`)        // streams to the transcript while it runs
    const order = await lookUp(number)
    return {
      output: [{ type: 'text', text: JSON.stringify(order) }],   // what the model sees
      details: { number, status: order.status },                 // JSON for a UI to draw the call with
    }
  },
})

Tools should do one thing and say plainly what they return. The model reads description and the parameters' descriptions to decide when to call it: write them for the model.

Prompt sections

section('vault_agents_md', async ({ env }) => readAgentsMd(env?.cwd))   // rendered as <vault_agents_md>…</vault_agents_md>
section('preamble', () => 'You are terse.', { tag: false })              // without the tags

A section renders before each request; returning undefined leaves it out. Sections are cached by what they return, so one that changes every time (the current time) defeats prompt caching: keep them stable.

A profile's prompt is simpler for fixed text. Use a section for text computed from the thread's folder or other state.

Replacing built-in tools

A profile's tool with the name of a built-in one (read, bash, …) replaces it in that profile's threads. To leave built-ins out entirely, use the profile's without (coding-tools, agent-ui, panes, thread-tools, …).

wrapTool, wrapSection and hook are pi-durable's lower-level decorators (wrapping a tool or a section by name); prefer tools and sections. To hear every tool call a thread makes, a daemon half has superego.toolCalls: Watching tool calls.

Testing a tool

Start a thread with the profile, ask for it, and read its answer: id=$(superego start . -P <profile> -p "Use find_order for 1234") && superego read "$id" --wait. Tool calls and errors show in the transcript. Edits load on the thread's next turn (a project's profile needs allowing again).

packages/cli/skill/tools.md