File size: 1,260 Bytes
68d7816 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import type { AgentEventStore } from '#/agent/slices';
import { createUserMessage } from '#/llm/message';
import type { Plugin } from '#/plugin';
import { readTodoState } from './slice';
import { createTodoListTool } from './tool';
import { renderTodoList } from './todoItem';
const STALE_TURNS = 2;
export interface TodoPlugin extends Plugin {
readonly name: 'todo';
}
export function createTodoPlugin(store: AgentEventStore): TodoPlugin {
const tool = createTodoListTool(store);
return {
name: 'todo',
tools: () => [tool],
connect(target) {
if (target.kind !== 'agent') return;
target.on('turn.started', (event) => {
if (event.type !== 'turn.started') return;
const { todos, currentTurn, lastWriteTurn } = readTodoState(store);
if (todos.length === 0) return;
if (todos.every((todo) => todo.status === 'done')) return;
if (currentTurn - lastWriteTurn !== STALE_TURNS) return;
target.notify(
createUserMessage(
`<system-reminder>\nThe todo list has not been updated recently. If the work is still in progress, update the list to reflect the current progress.\n${renderTodoList(todos)}\n</system-reminder>`,
),
);
});
},
};
}
|