Developing Strategies
Strategy File
A AfferLab strategy is a single TypeScript module with exported metadata and hooks.
Required Structure
At minimum, a strategy file must export:
-
meta -
onContextBuild -
configSchema(optional)
onContextBuild is the only required hook.
Minimal Example
import { defineStrategy } from '@afferlab/strategy-sdk'
export default defineStrategy({
meta: {
name: 'Base',
description: 'Minimal',
version: '0.2.2',
features: { memoryCloud: false },
},
configSchema: [
{
key: 'historyDepth',
type: 'number',
default: 10,
min: 1,
max: 20,
},
{
key: 'systemPrompt',
type: 'text',
default: 'You are a helpful assistant.',
},
],
onContextBuild(ctx) {
const history = ctx.history.recent(ctx.config.historyDepth)
ctx.slots.add('system', ctx.config.systemPrompt, {
priority: 3,
})
ctx.slots.add('history', history, {
priority: 1,
})
ctx.slots.add('input', ctx.input, {
priority: 2,
})
return {
prompt: ctx.slots.render(),
tools: [],
}
},
})Optional Exports
The worker loader currently recognizes:
onInitonTurnEndonReplayTurnonCleanuponErroronToolCall
You can export them through a hooks object.