UNPKG

adk-typescript

Version:

TypeScript port of Google's Agent Development Kit (ADK)

380 lines (379 loc) 13.4 kB
"use strict"; /** * Tools module - Provides utility functions and interfaces for agent tools */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ToolRegistry = exports.Tools = exports.RestApiTool = exports.OpenAPIToolset = exports.googleSearch = void 0; // Base tool exports __exportStar(require("./BaseTool"), exports); __exportStar(require("./FunctionTool"), exports); __exportStar(require("./AgentTool"), exports); __exportStar(require("./CrewaiTool"), exports); __exportStar(require("./ToolContext"), exports); __exportStar(require("./toolActions"), exports); // Additional tool exports __exportStar(require("./GoogleSearchTool"), exports); var GoogleSearchTool_1 = require("./GoogleSearchTool"); Object.defineProperty(exports, "googleSearch", { enumerable: true, get: function () { return GoogleSearchTool_1.googleSearch; } }); __exportStar(require("./LoadWebPageTool"), exports); __exportStar(require("./LongRunningTool"), exports); __exportStar(require("./TransferToAgentTool"), exports); __exportStar(require("./ExitLoopTool"), exports); __exportStar(require("./LoadMemoryTool"), exports); __exportStar(require("./PreloadMemoryTool"), exports); __exportStar(require("./BuiltInCodeExecutionTool"), exports); __exportStar(require("./GetUserChoiceTool"), exports); __exportStar(require("./CodeExecutionTool"), exports); __exportStar(require("./ExampleTool"), exports); __exportStar(require("./VertexAISearchTool"), exports); __exportStar(require("./ToolboxTool"), exports); __exportStar(require("./LangchainTool"), exports); // Export MCP tools __exportStar(require("./mcp-tool"), exports); // Export Google API tools __exportStar(require("./google-api-tool"), exports); // Export OpenAPI tools var openapi_tool_1 = require("./openapi-tool"); Object.defineProperty(exports, "OpenAPIToolset", { enumerable: true, get: function () { return openapi_tool_1.OpenAPIToolset; } }); Object.defineProperty(exports, "RestApiTool", { enumerable: true, get: function () { return openapi_tool_1.RestApiTool; } }); // Export APIHub tools __exportStar(require("./apihub-tool"), exports); // Re-export specific tool directories __exportStar(require("./retrieval/BaseRetrievalTool"), exports); __exportStar(require("./retrieval/WebSearchTool"), exports); /** * Tool categories collection */ exports.Tools = { /** * Web-related tools */ web: { /** * Web search tool */ search: { name: 'web_search', description: 'Search the web for information', execute: async (query) => { // Implementation will be added in a future version console.log(`Searching the web for: ${query}`); return { status: 'search implementation pending', query }; } }, /** * Load web page tool */ loadPage: { name: 'load_web_page', description: 'Fetches the content from a URL and returns the text content', execute: async (url) => { // Import dynamically to avoid circular dependencies const { loadWebPage } = require('./LoadWebPageTool'); return loadWebPage({ url }, {}); } } }, /** * File system related tools */ file: { /** * Read file tool */ read: { name: 'file_read', description: 'Read content from a file', execute: async (filePath) => { // Implementation will be added in a future version console.log(`Reading file: ${filePath}`); return { status: 'file read implementation pending', filePath }; } }, /** * Write file tool */ write: { name: 'file_write', description: 'Write content to a file', execute: async (args) => { // Implementation will be added in a future version console.log(`Writing to file: ${args.filePath}`); return { status: 'file write implementation pending', filePath: args.filePath }; } } }, /** * Agent control tools */ agent: { /** * Exit loop tool */ exitLoop: { name: 'exit_loop', description: 'Exits the loop. Call this function only when you are instructed to do so.', execute: async () => { // Implementation will be added in a future version console.log('Exiting loop'); return { status: 'exit loop implementation pending' }; } }, /** * Transfer to agent tool */ transferToAgent: { name: 'transfer_to_agent', description: 'Transfers the question to another agent', execute: async (agentName) => { // Implementation will be added in a future version console.log(`Transferring to agent: ${agentName}`); return { status: 'transfer to agent implementation pending', agentName }; } }, /** * Get user choice tool */ getUserChoice: { name: 'get_user_choice', description: 'Provides options to the user and asks them to choose one', execute: async (options) => { // Implementation will be added in a future version console.log(`Asking user to choose from: ${options.join(', ')}`); return { status: 'get user choice implementation pending', options }; } } }, /** * Memory-related tools */ memory: { /** * Load memory tool */ loadMemory: { name: 'load_memory', description: 'Loads memory for the current user based on a query', execute: async (query) => { // Implementation will be added in a future version console.log(`Loading memory for query: ${query}`); return { status: 'load memory implementation pending', query }; } }, /** * Preload memory tool */ preloadMemory: { name: 'preload_memory', description: 'Preloads memory for the current user\'s query', execute: async () => { // Implementation will be added in a future version console.log('Preloading memory'); return { status: 'preload memory implementation pending' }; } } }, /** * Code-related tools */ code: { /** * Code execution tool (built-in) */ codeExecution: { name: 'code_execution', description: 'A built-in tool that enables Gemini models to execute code', execute: async () => { // Implementation will be added in a future version console.log('Executing code'); return { status: 'code execution implementation pending' }; } }, /** * Local code execution tool */ executeCode: { name: 'execute_code', description: 'Executes code in various programming languages locally', execute: async (params) => { // Import dynamically to avoid circular dependencies const { executeCode } = require('./CodeExecutionTool'); return executeCode(params, {}); } } }, /** * Instruction enhancement tools */ instruction: { /** * Example tool for few-shot learning */ examples: { name: 'example_tool', description: 'A tool that adds examples to guide the model responses', execute: async (examples) => { // Import dynamically to avoid circular dependencies const { createExampleTool } = require('./ExampleTool'); const exampleTool = createExampleTool(examples); return { status: 'Example tool is not meant to be executed directly. It automatically processes LLM requests.', examplesCount: examples.length }; } } }, /** * Vertex AI tools */ vertex: { /** * Vertex AI Search with Data Store */ searchWithDataStore: { name: 'vertex_ai_search_datastore', description: 'Uses Vertex AI Search with a data store to retrieve information', execute: async (dataStoreId) => { // Import dynamically to avoid circular dependencies const { createVertexAISearchToolWithDataStore } = require('./VertexAISearchTool'); return { status: 'Vertex AI Search tool is not meant to be executed directly. It is handled internally by the model.', dataStoreId }; } }, /** * Vertex AI Search with Engine */ searchWithEngine: { name: 'vertex_ai_search_engine', description: 'Uses Vertex AI Search with a search engine to retrieve information', execute: async (searchEngineId) => { // Import dynamically to avoid circular dependencies const { createVertexAISearchToolWithEngine } = require('./VertexAISearchTool'); return { status: 'Vertex AI Search tool is not meant to be executed directly. It is handled internally by the model.', searchEngineId }; } } }, /** * MCP tools */ mcp: { /** * Create an MCP toolset with stdio connection */ createStdioToolset: { name: 'create_mcp_stdio_toolset', description: 'Creates an MCP toolset using stdio connection', execute: async (params) => { // Import dynamically to avoid circular dependencies const { MCPToolset } = require('./mcp_tool'); const [tools, exitStack] = await MCPToolset.fromServer({ connectionParams: { command: params.command, args: params.args } }); return { status: 'MCP Toolset created', tools, exitStack }; } }, /** * Create an MCP toolset with SSE connection */ createSseToolset: { name: 'create_mcp_sse_toolset', description: 'Creates an MCP toolset using SSE connection', execute: async (params) => { // Import dynamically to avoid circular dependencies const { MCPToolset, SseServerParams } = require('./mcp_tool'); const [tools, exitStack] = await MCPToolset.fromServer({ connectionParams: new SseServerParams({ url: params.url, headers: params.headers }) }); return { status: 'MCP Toolset created', tools, exitStack }; } } } }; /** * Tool registry for managing custom tools */ class ToolRegistry { constructor() { this.tools = new Map(); } /** * Register a new tool * @param tool The tool to register */ register(tool) { this.tools.set(tool.name, tool); } /** * Get a tool by name * @param name The name of the tool to retrieve * @returns The tool if found, undefined otherwise */ get(name) { return this.tools.get(name); } /** * Get all registered tools * @returns Array of all registered tools */ getAll() { return Array.from(this.tools.values()); } } exports.ToolRegistry = ToolRegistry;