feat: auto-route research-prefixed prompts to research agent

This commit is contained in:
William Valentin
2026-02-17 15:23:04 -08:00
parent 2b89024a71
commit a055f4d338
4 changed files with 118 additions and 0 deletions
+78
View File
@@ -510,6 +510,84 @@ describe('daemon command fast-path integration', () => {
expect(keys.some(key => key.includes(':coder'))).toBe(true);
});
it('auto-routes research-prefixed messages to research agent when configured', async () => {
const processSpy = vi.spyOn(AgentOrchestrator.prototype, 'process').mockResolvedValue('ok');
const session = {
id: 'telegram:user-research',
addMessage: vi.fn(),
getHistory: vi.fn(() => []),
clear: vi.fn(),
replaceHistory: vi.fn(),
getConfig: vi.fn(() => undefined),
setConfig: vi.fn(),
deleteConfig: vi.fn(),
};
const commandRegistry = new CommandRegistry();
registerBuiltinCommands(commandRegistry);
const agentConfigRegistry = new AgentConfigRegistry();
agentConfigRegistry.loadFromConfig({
assistant: { model_tier: 'default', sandbox: false },
research: { model_tier: 'complex', sandbox: false },
});
const agentRouter = new AgentRouter({
default_agent: 'assistant',
channels: {},
senders: {},
});
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: {
intents: { enabled: false },
agents: {
primary_tier: 'default',
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'],
commandRegistry,
agentConfigRegistry,
agentRouter,
});
await router.handler({
id: 'm-research',
channel: 'telegram',
senderId: 'user-research',
text: 'research compare k0s vs k3s for a homelab',
timestamp: Date.now(),
} as MessageRouterInput, vi.fn(async () => {}));
const keys = Array.from(router.agents.keys());
expect(keys.some(key => key.includes(':research'))).toBe(true);
expect(processSpy).toHaveBeenCalledWith('compare k0s vs k3s for a homelab', undefined);
});
it('falls back to llm path when confidence is below fast threshold', async () => {
const session = {
id: 'telegram:user-3',
+20
View File
@@ -72,6 +72,19 @@ function tierFromUseCase(config: Config, useCaseRaw: unknown): ModelTier | undef
return undefined;
}
function parseResearchPrefix(text: string): string | undefined {
const trimmed = text.trim();
const researchMatch = trimmed.match(/^research(?:\s*[:,-])?\s+(.+)$/i);
if (researchMatch?.[1]) {
return researchMatch[1].trim();
}
const lookupMatch = trimmed.match(/^(?:look\s+up|lookup)(?:\s*[:,-])?\s+(.+)$/i);
if (lookupMatch?.[1]) {
return lookupMatch[1].trim();
}
return undefined;
}
/**
* Create the unified message handler for the channel registry.
* Each channel+sender pair gets its own AgentOrchestrator backed by a persistent session.
@@ -362,6 +375,13 @@ export function createMessageRouter(deps: {
let intentAgentOverride: string | undefined;
let intentSkillOverride: string | undefined;
if (!deps.config.intents?.enabled && deps.agentConfigRegistry?.get('research')) {
const researchTask = parseResearchPrefix(incomingText);
if (researchTask) {
intentAgentOverride = 'research';
incomingText = researchTask;
}
}
if (deps.config.intents?.enabled && deps.intentRegistry) {
const intentMatch = deps.intentRegistry.match(incomingText);