feat(routing): add auto_escalate retry to complex tier

This commit is contained in:
William Valentin
2026-02-17 10:39:47 -08:00
parent d67cfa64a6
commit 70bb14a6f6
3 changed files with 97 additions and 1 deletions
+71
View File
@@ -974,6 +974,77 @@ describe('daemon audio routing integration', () => {
});
});
describe('daemon auto-escalate integration', () => {
afterEach(() => {
vi.restoreAllMocks();
});
it('retries on complex tier when auto_escalate is enabled', async () => {
const processSpy = vi.spyOn(AgentOrchestrator.prototype, 'process')
.mockRejectedValueOnce(new Error('primary tier failed'))
.mockResolvedValueOnce('complex-tier response');
const setModelTierSpy = vi.spyOn(AgentOrchestrator.prototype, 'setModelTier');
const session = {
id: 'telegram:auto-escalate',
addMessage: vi.fn(),
getHistory: vi.fn(() => []),
clear: vi.fn(),
replaceHistory: vi.fn(),
getConfig: vi.fn(() => undefined),
setConfig: vi.fn(),
deleteConfig: vi.fn(),
};
const router = createMessageRouter({
sessionManager: {
getSession: vi.fn(() => session),
} as unknown as MessageRouterDeps['sessionManager'],
modelRouter: {
getAvailableTiers: () => ['fast', 'default', 'complex', 'local'],
getAllLabels: () => ({ fast: 'fast', default: 'default', complex: 'complex', local: 'local' }),
getLabel: (tier: string) => tier,
} as unknown as MessageRouterDeps['modelRouter'],
systemPrompt: 'test prompt',
toolRegistry: {
clone() { return this; },
register: vi.fn(),
} as unknown as MessageRouterDeps['toolRegistry'],
toolExecutor: {} as unknown as MessageRouterDeps['toolExecutor'],
config: {
agents: {
primary_tier: 'default',
auto_escalate: true,
delegation: {
compaction: 'fast',
memory_extraction: 'fast',
classification: 'fast',
tool_summarisation: 'fast',
complex_reasoning: 'complex',
},
max_delegation_depth: 3,
max_iterations: 10,
},
compaction: { enabled: false },
models: { default: { provider: 'anthropic', model: 'claude' } },
} as unknown as MessageRouterDeps['config'],
});
const reply = vi.fn(async (_message: OutboundMessage) => {});
await router.handler({
id: 'm-auto-escalate',
channel: 'telegram',
senderId: 'auto-escalate',
text: 'do something hard',
timestamp: Date.now(),
} as MessageRouterInput, reply);
expect(processSpy).toHaveBeenCalledTimes(2);
expect(setModelTierSpy).toHaveBeenCalledWith('complex');
expect(reply).toHaveBeenCalledWith(expect.objectContaining({ text: 'complex-tier response' }));
});
});
describe('daemon talk mode (voice wake) integration', () => {
afterEach(() => {
vi.restoreAllMocks();