feat(routing): add auto_escalate retry to complex tier
This commit is contained in:
@@ -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();
|
||||
|
||||
+14
-1
@@ -888,7 +888,20 @@ export function createMessageRouter(deps: {
|
||||
}
|
||||
}
|
||||
|
||||
const response = await agent.process(messageText, attachments);
|
||||
let response: string;
|
||||
try {
|
||||
response = await agent.process(messageText, attachments);
|
||||
} catch (error) {
|
||||
const currentTier = agent.getModelTier();
|
||||
const canEscalate = deps.config.agents.auto_escalate && currentTier !== 'complex';
|
||||
if (!canEscalate) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
console.warn(`Auto-escalating session ${msg.channel}:${msg.senderId} from ${currentTier} to complex after processing failure.`);
|
||||
agent.setModelTier('complex');
|
||||
response = await agent.process(messageText, attachments);
|
||||
}
|
||||
const outboundAttachments = collector.drain();
|
||||
await reply({
|
||||
text: response,
|
||||
|
||||
Reference in New Issue
Block a user