hataraku
Version:
An autonomous coding agent for building AI-powered development tools. The name "Hataraku" (働く) means "to work" in Japanese.
94 lines • 3.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createCLIAgent = createCLIAgent;
const agent_1 = require("../agent");
const prompts_1 = require("../prompts");
const task_history_1 = require("../task-history");
const tools_1 = require("../tools");
const toolWrapper_1 = require("../mcp/toolWrapper");
const ToolManager_1 = require("../../config/ToolManager");
const colors_1 = require("../../utils/colors");
/**
* Creates a CLI agent with built-in tools and MCP tools.
*
* The agent is initialized with standard tools and attempts to load additional
* MCP (Model-Code-Prompt) tools from the tool manager configurations.
*
* @param model - The language model to use for the agent
* @param options - Configuration options for the CLI agent
* @returns A promise that resolves to the created agent instance
* @throws Will log a warning if MCP tools fail to load but won't throw an error
*
* @example
* ```typescript
* import { createCLIAgent } from './cli-agent';
* import { openai } from 'ai';
*
* const model = openai('gpt-4');
* const agent = await createCLIAgent(model, { verbose: true });
* const response = await agent.run('What can you help me with?');
* ```
*/
async function createCLIAgent(model, options) {
const verbose = options?.verbose === true;
// Initialize tools
const tools = { ...tools_1.ALL_TOOLS };
if (verbose) {
colors_1.log.system('Initializing CLI agent with built-in tools');
}
try {
// Get MCP tools from tool manager
const toolManager = new ToolManager_1.ToolManager();
await toolManager.initializeDefaults();
// Get tool configurations
const toolConfigs = await toolManager.listTools();
if (verbose) {
colors_1.log.system(`Loading MCP tools from ${toolConfigs.length} configurations`);
}
// Load MCP tools for each configuration
for (const toolConfig of toolConfigs) {
try {
if (verbose) {
colors_1.log.system(`Loading tool configuration: ${toolConfig}`);
}
const resolvedConfig = await toolManager.getResolvedToolConfig(toolConfig);
// Convert to the format expected by getMcpTools
const mcpConfig = {
mcpServers: {}
};
for (const server of resolvedConfig.mcpServers) {
mcpConfig.mcpServers[server.name] = {
command: server.command,
args: server.args || [],
env: server.env || {},
disabledTools: server.disabledTools
};
}
// Get MCP tools for this configuration
const { tools: mcpTools } = await (0, toolWrapper_1.getMcpTools)({ config: mcpConfig });
// Add MCP tools to the agent's tools
Object.assign(tools, mcpTools);
}
catch (error) {
console.warn(`Warning: Failed to load MCP tools for configuration '${toolConfig}':`, error);
}
}
}
catch (error) {
console.warn('Warning: Failed to load MCP tools:', error);
}
// Create and return the agent
return (0, agent_1.createAgent)({
name: 'CLI Agent',
description: 'A helpful CLI agent that can answer questions and perform tasks',
role: `
${(0, prompts_1.getAgentRules)()}
${(0, prompts_1.getEnvironmentInfo)()}`,
model,
taskHistory: new task_history_1.TaskHistory(),
tools,
verbose: verbose,
enableCaching: true // Always enable caching for CLI agent
});
}
//# sourceMappingURL=cli-agent.js.map