Wire agent.delegate into TUI tool registry

This commit is contained in:
William Valentin
2026-02-17 11:03:55 -08:00
parent e3b6f9df7c
commit 8394086446
4 changed files with 74 additions and 8 deletions
+40 -1
View File
@@ -102,9 +102,25 @@ export function registerTuiCommand(program: Command): void {
setLogLevel(tuiLogLevel);
const { MinimalTui, startFullscreenTui } = await import('../frontends/tui/index.js');
const { NativeAgent } = await import('../backends/index.js');
const { ToolRegistry, ToolExecutor, ToolPolicy, allBuiltinTools, createWebSearchTools, createProcessTools, ProcessManager, createGmailTools, createGcalTools, createGdocsTools, createGdriveTools, createGtasksTools } = await import('../tools/index.js');
const {
ToolRegistry,
ToolExecutor,
ToolPolicy,
allBuiltinTools,
createWebSearchTools,
createProcessTools,
ProcessManager,
createGmailTools,
createGcalTools,
createGdocsTools,
createGdriveTools,
createGtasksTools,
createAgentsListTool,
createAgentDelegateTool,
} = await import('../tools/index.js');
const { HookEngine } = await import('../hooks/index.js');
const { createModelRouter } = await import('../daemon/index.js');
const { AgentConfigRegistry } = await import('../agents/index.js');
const dataDir = process.env.FLYNN_DATA_DIR ?? resolve(homedir(), '.local/share/flynn');
mkdirSync(dataDir, { recursive: true });
@@ -194,6 +210,29 @@ export function registerTuiCommand(program: Command): void {
}
}
const agentConfigRegistry = new AgentConfigRegistry();
agentConfigRegistry.loadFromConfig(config.agent_configs);
if (agentConfigRegistry.list().length > 0) {
toolRegistry.register(createAgentsListTool(agentConfigRegistry));
toolRegistry.register(createAgentDelegateTool({
registry: agentConfigRegistry,
orchestrator: {
async delegate(request) {
const response = await modelRouter.chat({
messages: [{ role: 'user', content: request.message }],
system: request.systemPrompt,
maxTokens: request.maxTokens,
}, request.tier);
return {
content: response.content,
usage: response.usage,
tier: request.tier,
};
},
},
}));
}
toolRegistry.setPolicy(new ToolPolicy(config.tools));
const toolExecutor = new ToolExecutor(toolRegistry, hookEngine);