// Example mod: route requests between models, and call a model yourself. // // hooks.beforeModelRequest runs at the start of each request's round, so its tools and prompt are // built for the model it picks. Returning {model} sends THAT request to another model; the next request goes back to the session's model (use // prepareNextTurn to switch for the rest of a run). Here: the first request of each run, which // usually just reads the prompt and picks tools, goes to a cheaper model. // // cmd.model.complete runs one prompt on the session's own client, with no transcript and no // tools. It always resolves: {isAnswered: true, text} or {isAnswered: false, reason}. import type {ModApi} from '@commandcode/harness'; export default function (cmd: ModApi): void { cmd.addFlag('router-model', { type: 'string', description: 'Model for the first request of each run', }); cmd.hooks({ beforeModelRequest: async ({turnNumber}) => { const cheap = cmd.getFlag('router-model'); if (turnNumber !== 1 || typeof cheap !== 'string' || !cheap) return undefined; return {model: cheap}; }, }); cmd.addCommand({ name: 'haiku', description: 'Write a haiku about the argument with a one-shot model call', argumentHint: '', handler: async ({args}) => { const result = await cmd.model.complete({ prompt: `Write a haiku about: ${args || 'code review'}`, maxOutputTokens: 200, }); if (!result.isAnswered) return {message: `No haiku (${result.reason}).`}; return {message: result.text}; }, }); }