@iqai/adk 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @iqai/adk
2
2
 
3
+ ## 0.1.11
4
+
5
+ ### Patch Changes
6
+
7
+ - 4a93c0a: Makes schema optional for createTool function
8
+
9
+ ## 0.1.10
10
+
11
+ ### Patch Changes
12
+
13
+ - 83e8a58: Add create tool function to easily create tools with zod schema
14
+
3
15
  ## 0.1.9
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -58,7 +58,7 @@ npm install @iqai/adk
58
58
  import { AgentBuilder } from '@iqai/adk';
59
59
 
60
60
  const response = await AgentBuilder
61
- .withModel("gpt-4")
61
+ .withModel("gpt-4.1")
62
62
  .ask("What is the primary function of an AI agent?");
63
63
 
64
64
  console.log(response);
@@ -129,7 +129,6 @@ async function quickQuery() {
129
129
  .create("query_assistant")
130
130
  .withModel("gemini-2.5-flash")
131
131
  .withInstruction("You are a helpful AI. Respond clearly and concisely.")
132
- .withQuickSession("my-app", "user-123")
133
132
  .ask("What is the capital of France?");
134
133
 
135
134
  console.log(response);
package/dist/index.d.mts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { Part, Content as Content$1, Blob, SpeechConfig, AudioTranscriptionConfig, RealtimeInputConfig, ProactivityConfig, GenerateContentConfig, LiveConnectConfig, GroundingMetadata, GenerateContentResponseUsageMetadata, GoogleGenAI, FunctionCall } from '@google/genai';
2
2
  export { Blob, Content } from '@google/genai';
3
3
  import { LanguageModel } from 'ai';
4
+ import * as z from 'zod/v4';
4
5
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
5
6
  import { CreateMessageRequestSchema, CreateMessageResultSchema, Tool } from '@modelcontextprotocol/sdk/types.js';
6
- import { z } from 'zod';
7
+ import { z as z$1 } from 'zod';
7
8
  import { Kysely, Generated } from 'kysely';
8
9
  import { StorageOptions } from '@google-cloud/storage';
9
10
  import { Tracer } from '@opentelemetry/api';
@@ -904,6 +905,110 @@ declare abstract class BaseTool {
904
905
  private findToolWithFunctionDeclarations;
905
906
  }
906
907
 
908
+ /**
909
+ * Configuration for creating a tool
910
+ */
911
+ interface CreateToolConfig<T extends Record<string, any> = Record<string, never>> {
912
+ /** The name of the tool */
913
+ name: string;
914
+ /** A description of what the tool does */
915
+ description: string;
916
+ /** Zod schema for validating tool arguments (optional) */
917
+ schema?: z.ZodSchema<T>;
918
+ /** The function to execute (can be sync or async) */
919
+ fn: (args: T, context?: ToolContext) => any;
920
+ /** Whether the tool is a long running operation */
921
+ isLongRunning?: boolean;
922
+ /** Whether the tool execution should be retried on failure */
923
+ shouldRetryOnFailure?: boolean;
924
+ /** Maximum retry attempts */
925
+ maxRetryAttempts?: number;
926
+ }
927
+ /**
928
+ * Configuration for creating a tool with schema
929
+ */
930
+ interface CreateToolConfigWithSchema<T extends Record<string, any>> {
931
+ /** The name of the tool */
932
+ name: string;
933
+ /** A description of what the tool does */
934
+ description: string;
935
+ /** Zod schema for validating tool arguments */
936
+ schema: z.ZodSchema<T>;
937
+ /** The function to execute (can be sync or async) */
938
+ fn: (args: T, context?: ToolContext) => any;
939
+ /** Whether the tool is a long running operation */
940
+ isLongRunning?: boolean;
941
+ /** Whether the tool execution should be retried on failure */
942
+ shouldRetryOnFailure?: boolean;
943
+ /** Maximum retry attempts */
944
+ maxRetryAttempts?: number;
945
+ }
946
+ /**
947
+ * Configuration for creating a tool without schema (no parameters)
948
+ */
949
+ interface CreateToolConfigWithoutSchema {
950
+ /** The name of the tool */
951
+ name: string;
952
+ /** A description of what the tool does */
953
+ description: string;
954
+ /** The function to execute (can be sync or async) */
955
+ fn: (args: Record<string, never>, context?: ToolContext) => any;
956
+ /** Whether the tool is a long running operation */
957
+ isLongRunning?: boolean;
958
+ /** Whether the tool execution should be retried on failure */
959
+ shouldRetryOnFailure?: boolean;
960
+ /** Maximum retry attempts */
961
+ maxRetryAttempts?: number;
962
+ }
963
+ /**
964
+ * Creates a tool from a configuration object.
965
+ *
966
+ * This is a more user-friendly alternative to FunctionTool that provides:
967
+ * - Automatic argument validation using Zod schemas
968
+ * - Clear error messages for invalid inputs
969
+ * - Automatic JSON Schema generation for LLM function declarations
970
+ * - Support for both sync and async functions
971
+ * - Optional ToolContext parameter support
972
+ *
973
+ * @param config The tool configuration object
974
+ * @returns A BaseTool instance ready for use with agents
975
+ *
976
+ * @example
977
+ * ```typescript
978
+ * import { createTool } from '@iqai/adk';
979
+ * import { z } from 'zod';
980
+ *
981
+ * // Tool with parameters
982
+ * const calculatorTool = createTool({
983
+ * name: 'calculator',
984
+ * description: 'Performs basic arithmetic operations',
985
+ * schema: z.object({
986
+ * operation: z.enum(['add', 'subtract', 'multiply', 'divide']),
987
+ * a: z.number().describe('First number'),
988
+ * b: z.number().describe('Second number')
989
+ * }),
990
+ * fn: ({ operation, a, b }) => {
991
+ * switch (operation) {
992
+ * case 'add': return { result: a + b };
993
+ * case 'subtract': return { result: a - b };
994
+ * case 'multiply': return { result: a * b };
995
+ * case 'divide': return { result: b !== 0 ? a / b : 'Cannot divide by zero' };
996
+ * default: return { error: 'Unknown operation' };
997
+ * }
998
+ * }
999
+ * });
1000
+ *
1001
+ * // Tool without parameters (schema is optional)
1002
+ * const timestampTool = createTool({
1003
+ * name: 'timestamp',
1004
+ * description: 'Gets the current timestamp',
1005
+ * fn: () => ({ timestamp: Date.now() })
1006
+ * });
1007
+ * ```
1008
+ */
1009
+ declare function createTool<T extends Record<string, any>>(config: CreateToolConfigWithSchema<T>): BaseTool;
1010
+ declare function createTool(config: CreateToolConfigWithoutSchema): BaseTool;
1011
+
907
1012
  /**
908
1013
  * A tool that wraps a user-defined TypeScript function.
909
1014
  *
@@ -1322,8 +1427,8 @@ declare class McpError extends Error {
1322
1427
  originalError?: Error;
1323
1428
  constructor(message: string, type: McpErrorType, originalError?: Error);
1324
1429
  }
1325
- type McpSamplingRequest = z.infer<typeof CreateMessageRequestSchema>;
1326
- type McpSamplingResponse = z.infer<typeof CreateMessageResultSchema>;
1430
+ type McpSamplingRequest = z$1.infer<typeof CreateMessageRequestSchema>;
1431
+ type McpSamplingResponse = z$1.infer<typeof CreateMessageResultSchema>;
1327
1432
  type SamplingHandler = (request: LlmRequest) => Promise<string | LlmResponse>;
1328
1433
 
1329
1434
  declare class McpClientService {
@@ -1752,6 +1857,9 @@ declare function getMcpTools(config: McpConfig, toolFilter?: string[] | ((tool:
1752
1857
  type index$6_BaseTool = BaseTool;
1753
1858
  declare const index$6_BaseTool: typeof BaseTool;
1754
1859
  type index$6_BuildFunctionDeclarationOptions = BuildFunctionDeclarationOptions;
1860
+ type index$6_CreateToolConfig<T extends Record<string, any> = Record<string, never>> = CreateToolConfig<T>;
1861
+ type index$6_CreateToolConfigWithSchema<T extends Record<string, any>> = CreateToolConfigWithSchema<T>;
1862
+ type index$6_CreateToolConfigWithoutSchema = CreateToolConfigWithoutSchema;
1755
1863
  type index$6_ExitLoopTool = ExitLoopTool;
1756
1864
  declare const index$6_ExitLoopTool: typeof ExitLoopTool;
1757
1865
  type index$6_FileOperationsTool = FileOperationsTool;
@@ -1807,12 +1915,13 @@ declare const index$6_adkToMcpToolType: typeof adkToMcpToolType;
1807
1915
  declare const index$6_buildFunctionDeclaration: typeof buildFunctionDeclaration;
1808
1916
  declare const index$6_createFunctionTool: typeof createFunctionTool;
1809
1917
  declare const index$6_createSamplingHandler: typeof createSamplingHandler;
1918
+ declare const index$6_createTool: typeof createTool;
1810
1919
  declare const index$6_getMcpTools: typeof getMcpTools;
1811
1920
  declare const index$6_jsonSchemaToDeclaration: typeof jsonSchemaToDeclaration;
1812
1921
  declare const index$6_mcpSchemaToParameters: typeof mcpSchemaToParameters;
1813
1922
  declare const index$6_normalizeJsonSchema: typeof normalizeJsonSchema;
1814
1923
  declare namespace index$6 {
1815
- export { index$6_BaseTool as BaseTool, type index$6_BuildFunctionDeclarationOptions as BuildFunctionDeclarationOptions, index$6_ExitLoopTool as ExitLoopTool, index$6_FileOperationsTool as FileOperationsTool, index$6_FunctionTool as FunctionTool, index$6_GetUserChoiceTool as GetUserChoiceTool, index$6_GoogleSearch as GoogleSearch, index$6_HttpRequestTool as HttpRequestTool, index$6_LoadArtifactsTool as LoadArtifactsTool, index$6_LoadMemoryTool as LoadMemoryTool, index$6_McpAbi as McpAbi, index$6_McpAtp as McpAtp, index$6_McpBamm as McpBamm, index$6_McpCoinGecko as McpCoinGecko, type index$6_McpConfig as McpConfig, index$6_McpDiscord as McpDiscord, index$6_McpError as McpError, index$6_McpErrorType as McpErrorType, index$6_McpFilesystem as McpFilesystem, index$6_McpFraxlend as McpFraxlend, index$6_McpGeneric as McpGeneric, index$6_McpIqWiki as McpIqWiki, index$6_McpMemory as McpMemory, index$6_McpNearAgent as McpNearAgent, index$6_McpNearIntentSwaps as McpNearIntentSwaps, index$6_McpOdos as McpOdos, index$6_McpSamplingHandler as McpSamplingHandler, type index$6_McpSamplingRequest as McpSamplingRequest, type index$6_McpSamplingResponse as McpSamplingResponse, type index$6_McpServerConfig as McpServerConfig, index$6_McpTelegram as McpTelegram, index$6_McpToolset as McpToolset, type index$6_McpTransportType as McpTransportType, type index$6_SamplingHandler as SamplingHandler, type index$6_ToolConfig as ToolConfig, index$6_ToolContext as ToolContext, index$6_TransferToAgentTool as TransferToAgentTool, index$6_UserInteractionTool as UserInteractionTool, index$6_adkToMcpToolType as adkToMcpToolType, index$6_buildFunctionDeclaration as buildFunctionDeclaration, index$6_createFunctionTool as createFunctionTool, index$6_createSamplingHandler as createSamplingHandler, index$6_getMcpTools as getMcpTools, index$6_jsonSchemaToDeclaration as jsonSchemaToDeclaration, index$6_mcpSchemaToParameters as mcpSchemaToParameters, index$6_normalizeJsonSchema as normalizeJsonSchema };
1924
+ export { index$6_BaseTool as BaseTool, type index$6_BuildFunctionDeclarationOptions as BuildFunctionDeclarationOptions, type index$6_CreateToolConfig as CreateToolConfig, type index$6_CreateToolConfigWithSchema as CreateToolConfigWithSchema, type index$6_CreateToolConfigWithoutSchema as CreateToolConfigWithoutSchema, index$6_ExitLoopTool as ExitLoopTool, index$6_FileOperationsTool as FileOperationsTool, index$6_FunctionTool as FunctionTool, index$6_GetUserChoiceTool as GetUserChoiceTool, index$6_GoogleSearch as GoogleSearch, index$6_HttpRequestTool as HttpRequestTool, index$6_LoadArtifactsTool as LoadArtifactsTool, index$6_LoadMemoryTool as LoadMemoryTool, index$6_McpAbi as McpAbi, index$6_McpAtp as McpAtp, index$6_McpBamm as McpBamm, index$6_McpCoinGecko as McpCoinGecko, type index$6_McpConfig as McpConfig, index$6_McpDiscord as McpDiscord, index$6_McpError as McpError, index$6_McpErrorType as McpErrorType, index$6_McpFilesystem as McpFilesystem, index$6_McpFraxlend as McpFraxlend, index$6_McpGeneric as McpGeneric, index$6_McpIqWiki as McpIqWiki, index$6_McpMemory as McpMemory, index$6_McpNearAgent as McpNearAgent, index$6_McpNearIntentSwaps as McpNearIntentSwaps, index$6_McpOdos as McpOdos, index$6_McpSamplingHandler as McpSamplingHandler, type index$6_McpSamplingRequest as McpSamplingRequest, type index$6_McpSamplingResponse as McpSamplingResponse, type index$6_McpServerConfig as McpServerConfig, index$6_McpTelegram as McpTelegram, index$6_McpToolset as McpToolset, type index$6_McpTransportType as McpTransportType, type index$6_SamplingHandler as SamplingHandler, type index$6_ToolConfig as ToolConfig, index$6_ToolContext as ToolContext, index$6_TransferToAgentTool as TransferToAgentTool, index$6_UserInteractionTool as UserInteractionTool, index$6_adkToMcpToolType as adkToMcpToolType, index$6_buildFunctionDeclaration as buildFunctionDeclaration, index$6_createFunctionTool as createFunctionTool, index$6_createSamplingHandler as createSamplingHandler, index$6_createTool as createTool, index$6_getMcpTools as getMcpTools, index$6_jsonSchemaToDeclaration as jsonSchemaToDeclaration, index$6_mcpSchemaToParameters as mcpSchemaToParameters, index$6_normalizeJsonSchema as normalizeJsonSchema };
1816
1925
  }
1817
1926
 
1818
1927
  /**
@@ -4427,15 +4536,6 @@ declare abstract class BaseLlmFlow {
4427
4536
  _handleBeforeModelCallback(invocationContext: InvocationContext, llmRequest: LlmRequest, modelResponseEvent: Event): Promise<LlmResponse | undefined>;
4428
4537
  _handleAfterModelCallback(invocationContext: InvocationContext, llmResponse: LlmResponse, modelResponseEvent: Event): Promise<LlmResponse | undefined>;
4429
4538
  _finalizeModelResponseEvent(llmRequest: LlmRequest, llmResponse: LlmResponse, modelResponseEvent: Event): Event;
4430
- /**
4431
- * Logs data in a visually appealing format that works well in any terminal size.
4432
- * Uses vertical layout for better readability and respects debug settings.
4433
- */
4434
- _formatContentPreview(content: any): string;
4435
- /**
4436
- * Formats response content preview for debug logging
4437
- */
4438
- _formatResponsePreview(llmResponse: LlmResponse): string;
4439
4539
  __getLlm(invocationContext: InvocationContext): BaseLlm;
4440
4540
  }
4441
4541
 
@@ -4991,4 +5091,4 @@ declare const traceLlmCall: (invocationContext: InvocationContext, eventId: stri
4991
5091
 
4992
5092
  declare const VERSION = "0.1.0";
4993
5093
 
4994
- export { AF_FUNCTION_CALL_ID_PREFIX, type AfterAgentCallback, LlmAgent as Agent, AgentBuilder, type AgentBuilderConfig, type AgentType, index$4 as Agents, AiSdkLlm, AnthropicLlm, ApiKeyCredential, ApiKeyScheme, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, AuthTool, type AuthToolArguments, AutoFlow, BaseAgent, BaseCodeExecutor, type BaseCodeExecutorConfig, BaseLLMConnection, BaseLlm, BaseLlmFlow, BaseLlmRequestProcessor, BaseLlmResponseProcessor, type BaseMemoryService, BasePlanner, BaseSessionService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BeforeAgentCallback, type BuildFunctionDeclarationOptions, type BuiltAgent, BuiltInCodeExecutor, BuiltInPlanner, CallbackContext, type CodeExecutionInput, type CodeExecutionResult, CodeExecutionUtils, CodeExecutorContext, DatabaseSessionService, EnhancedAuthConfig, type EnhancedRunner, Event, EventActions, index$1 as Events, ExitLoopTool, type File, FileOperationsTool, index as Flows, type FullMessage, type FunctionDeclaration, FunctionTool, GcsArtifactService, type GetSessionConfig, GetUserChoiceTool, GoogleLlm, GoogleSearch, HttpRequestTool, HttpScheme, InMemoryArtifactService, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, type InstructionProvider, InvocationContext, type JSONSchema, LLMRegistry, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionsResponse, LlmAgent, type LlmAgentConfig, LlmCallsLimitExceededError, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, McpCoinGecko, type McpConfig, McpDiscord, McpError, McpErrorType, McpFilesystem, McpFraxlend, McpGeneric, McpIqWiki, McpMemory, McpNearAgent, McpNearIntentSwaps, McpOdos, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, type McpServerConfig, McpTelegram, McpToolset, type McpTransportType, index$3 as Memory, type MessagePart, index$5 as Models, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAiLlm, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, PlanReActPlanner, REQUEST_EUC_FUNCTION_CALL_NAME, ReadonlyContext, RunConfig, Runner, type SamplingHandler, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionConfig, index$2 as Sessions, type SingleAgentCallback, SingleFlow, State, StreamingMode, type TelemetryConfig, TelemetryService, type ThinkingConfig, type ToolConfig, ToolContext, type ToolUnion, index$6 as Tools, TransferToAgentTool, UserInteractionTool, VERSION, VertexAiSessionService, _findFunctionCallEventIfLastEventIsFunctionResponse, adkToMcpToolType, requestProcessor$2 as agentTransferRequestProcessor, requestProcessor$6 as basicRequestProcessor, buildFunctionDeclaration, requestProcessor as codeExecutionRequestProcessor, responseProcessor as codeExecutionResponseProcessor, requestProcessor$3 as contentRequestProcessor, createAuthToolArguments, createBranchContextForSubAgent, createDatabaseSessionService, createFunctionTool, createMysqlSessionService, createPostgresSessionService, createSamplingHandler, createSqliteSessionService, generateAuthEvent, generateClientFunctionCallId, getLongRunningFunctionCalls, getMcpTools, handleFunctionCallsAsync, handleFunctionCallsLive, requestProcessor$5 as identityRequestProcessor, initializeTelemetry, injectSessionState, requestProcessor$4 as instructionsRequestProcessor, isEnhancedAuthConfig, jsonSchemaToDeclaration, mcpSchemaToParameters, mergeAgentRun, mergeParallelFunctionResponseEvents, newInvocationContextId, requestProcessor$1 as nlPlanningRequestProcessor, responseProcessor$1 as nlPlanningResponseProcessor, normalizeJsonSchema, populateClientFunctionCallId, registerProviders, removeClientFunctionCallId, requestProcessor$7 as requestProcessor, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };
5094
+ export { AF_FUNCTION_CALL_ID_PREFIX, type AfterAgentCallback, LlmAgent as Agent, AgentBuilder, type AgentBuilderConfig, type AgentType, index$4 as Agents, AiSdkLlm, AnthropicLlm, ApiKeyCredential, ApiKeyScheme, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, AuthTool, type AuthToolArguments, AutoFlow, BaseAgent, BaseCodeExecutor, type BaseCodeExecutorConfig, BaseLLMConnection, BaseLlm, BaseLlmFlow, BaseLlmRequestProcessor, BaseLlmResponseProcessor, type BaseMemoryService, BasePlanner, BaseSessionService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BeforeAgentCallback, type BuildFunctionDeclarationOptions, type BuiltAgent, BuiltInCodeExecutor, BuiltInPlanner, CallbackContext, type CodeExecutionInput, type CodeExecutionResult, CodeExecutionUtils, CodeExecutorContext, type CreateToolConfig, type CreateToolConfigWithSchema, type CreateToolConfigWithoutSchema, DatabaseSessionService, EnhancedAuthConfig, type EnhancedRunner, Event, EventActions, index$1 as Events, ExitLoopTool, type File, FileOperationsTool, index as Flows, type FullMessage, type FunctionDeclaration, FunctionTool, GcsArtifactService, type GetSessionConfig, GetUserChoiceTool, GoogleLlm, GoogleSearch, HttpRequestTool, HttpScheme, InMemoryArtifactService, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, type InstructionProvider, InvocationContext, type JSONSchema, LLMRegistry, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionsResponse, LlmAgent, type LlmAgentConfig, LlmCallsLimitExceededError, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, McpCoinGecko, type McpConfig, McpDiscord, McpError, McpErrorType, McpFilesystem, McpFraxlend, McpGeneric, McpIqWiki, McpMemory, McpNearAgent, McpNearIntentSwaps, McpOdos, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, type McpServerConfig, McpTelegram, McpToolset, type McpTransportType, index$3 as Memory, type MessagePart, index$5 as Models, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAiLlm, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, PlanReActPlanner, REQUEST_EUC_FUNCTION_CALL_NAME, ReadonlyContext, RunConfig, Runner, type SamplingHandler, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionConfig, index$2 as Sessions, type SingleAgentCallback, SingleFlow, State, StreamingMode, type TelemetryConfig, TelemetryService, type ThinkingConfig, type ToolConfig, ToolContext, type ToolUnion, index$6 as Tools, TransferToAgentTool, UserInteractionTool, VERSION, VertexAiSessionService, _findFunctionCallEventIfLastEventIsFunctionResponse, adkToMcpToolType, requestProcessor$2 as agentTransferRequestProcessor, requestProcessor$6 as basicRequestProcessor, buildFunctionDeclaration, requestProcessor as codeExecutionRequestProcessor, responseProcessor as codeExecutionResponseProcessor, requestProcessor$3 as contentRequestProcessor, createAuthToolArguments, createBranchContextForSubAgent, createDatabaseSessionService, createFunctionTool, createMysqlSessionService, createPostgresSessionService, createSamplingHandler, createSqliteSessionService, createTool, generateAuthEvent, generateClientFunctionCallId, getLongRunningFunctionCalls, getMcpTools, handleFunctionCallsAsync, handleFunctionCallsLive, requestProcessor$5 as identityRequestProcessor, initializeTelemetry, injectSessionState, requestProcessor$4 as instructionsRequestProcessor, isEnhancedAuthConfig, jsonSchemaToDeclaration, mcpSchemaToParameters, mergeAgentRun, mergeParallelFunctionResponseEvents, newInvocationContextId, requestProcessor$1 as nlPlanningRequestProcessor, responseProcessor$1 as nlPlanningResponseProcessor, normalizeJsonSchema, populateClientFunctionCallId, registerProviders, removeClientFunctionCallId, requestProcessor$7 as requestProcessor, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { Part, Content as Content$1, Blob, SpeechConfig, AudioTranscriptionConfig, RealtimeInputConfig, ProactivityConfig, GenerateContentConfig, LiveConnectConfig, GroundingMetadata, GenerateContentResponseUsageMetadata, GoogleGenAI, FunctionCall } from '@google/genai';
2
2
  export { Blob, Content } from '@google/genai';
3
3
  import { LanguageModel } from 'ai';
4
+ import * as z from 'zod/v4';
4
5
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
5
6
  import { CreateMessageRequestSchema, CreateMessageResultSchema, Tool } from '@modelcontextprotocol/sdk/types.js';
6
- import { z } from 'zod';
7
+ import { z as z$1 } from 'zod';
7
8
  import { Kysely, Generated } from 'kysely';
8
9
  import { StorageOptions } from '@google-cloud/storage';
9
10
  import { Tracer } from '@opentelemetry/api';
@@ -904,6 +905,110 @@ declare abstract class BaseTool {
904
905
  private findToolWithFunctionDeclarations;
905
906
  }
906
907
 
908
+ /**
909
+ * Configuration for creating a tool
910
+ */
911
+ interface CreateToolConfig<T extends Record<string, any> = Record<string, never>> {
912
+ /** The name of the tool */
913
+ name: string;
914
+ /** A description of what the tool does */
915
+ description: string;
916
+ /** Zod schema for validating tool arguments (optional) */
917
+ schema?: z.ZodSchema<T>;
918
+ /** The function to execute (can be sync or async) */
919
+ fn: (args: T, context?: ToolContext) => any;
920
+ /** Whether the tool is a long running operation */
921
+ isLongRunning?: boolean;
922
+ /** Whether the tool execution should be retried on failure */
923
+ shouldRetryOnFailure?: boolean;
924
+ /** Maximum retry attempts */
925
+ maxRetryAttempts?: number;
926
+ }
927
+ /**
928
+ * Configuration for creating a tool with schema
929
+ */
930
+ interface CreateToolConfigWithSchema<T extends Record<string, any>> {
931
+ /** The name of the tool */
932
+ name: string;
933
+ /** A description of what the tool does */
934
+ description: string;
935
+ /** Zod schema for validating tool arguments */
936
+ schema: z.ZodSchema<T>;
937
+ /** The function to execute (can be sync or async) */
938
+ fn: (args: T, context?: ToolContext) => any;
939
+ /** Whether the tool is a long running operation */
940
+ isLongRunning?: boolean;
941
+ /** Whether the tool execution should be retried on failure */
942
+ shouldRetryOnFailure?: boolean;
943
+ /** Maximum retry attempts */
944
+ maxRetryAttempts?: number;
945
+ }
946
+ /**
947
+ * Configuration for creating a tool without schema (no parameters)
948
+ */
949
+ interface CreateToolConfigWithoutSchema {
950
+ /** The name of the tool */
951
+ name: string;
952
+ /** A description of what the tool does */
953
+ description: string;
954
+ /** The function to execute (can be sync or async) */
955
+ fn: (args: Record<string, never>, context?: ToolContext) => any;
956
+ /** Whether the tool is a long running operation */
957
+ isLongRunning?: boolean;
958
+ /** Whether the tool execution should be retried on failure */
959
+ shouldRetryOnFailure?: boolean;
960
+ /** Maximum retry attempts */
961
+ maxRetryAttempts?: number;
962
+ }
963
+ /**
964
+ * Creates a tool from a configuration object.
965
+ *
966
+ * This is a more user-friendly alternative to FunctionTool that provides:
967
+ * - Automatic argument validation using Zod schemas
968
+ * - Clear error messages for invalid inputs
969
+ * - Automatic JSON Schema generation for LLM function declarations
970
+ * - Support for both sync and async functions
971
+ * - Optional ToolContext parameter support
972
+ *
973
+ * @param config The tool configuration object
974
+ * @returns A BaseTool instance ready for use with agents
975
+ *
976
+ * @example
977
+ * ```typescript
978
+ * import { createTool } from '@iqai/adk';
979
+ * import { z } from 'zod';
980
+ *
981
+ * // Tool with parameters
982
+ * const calculatorTool = createTool({
983
+ * name: 'calculator',
984
+ * description: 'Performs basic arithmetic operations',
985
+ * schema: z.object({
986
+ * operation: z.enum(['add', 'subtract', 'multiply', 'divide']),
987
+ * a: z.number().describe('First number'),
988
+ * b: z.number().describe('Second number')
989
+ * }),
990
+ * fn: ({ operation, a, b }) => {
991
+ * switch (operation) {
992
+ * case 'add': return { result: a + b };
993
+ * case 'subtract': return { result: a - b };
994
+ * case 'multiply': return { result: a * b };
995
+ * case 'divide': return { result: b !== 0 ? a / b : 'Cannot divide by zero' };
996
+ * default: return { error: 'Unknown operation' };
997
+ * }
998
+ * }
999
+ * });
1000
+ *
1001
+ * // Tool without parameters (schema is optional)
1002
+ * const timestampTool = createTool({
1003
+ * name: 'timestamp',
1004
+ * description: 'Gets the current timestamp',
1005
+ * fn: () => ({ timestamp: Date.now() })
1006
+ * });
1007
+ * ```
1008
+ */
1009
+ declare function createTool<T extends Record<string, any>>(config: CreateToolConfigWithSchema<T>): BaseTool;
1010
+ declare function createTool(config: CreateToolConfigWithoutSchema): BaseTool;
1011
+
907
1012
  /**
908
1013
  * A tool that wraps a user-defined TypeScript function.
909
1014
  *
@@ -1322,8 +1427,8 @@ declare class McpError extends Error {
1322
1427
  originalError?: Error;
1323
1428
  constructor(message: string, type: McpErrorType, originalError?: Error);
1324
1429
  }
1325
- type McpSamplingRequest = z.infer<typeof CreateMessageRequestSchema>;
1326
- type McpSamplingResponse = z.infer<typeof CreateMessageResultSchema>;
1430
+ type McpSamplingRequest = z$1.infer<typeof CreateMessageRequestSchema>;
1431
+ type McpSamplingResponse = z$1.infer<typeof CreateMessageResultSchema>;
1327
1432
  type SamplingHandler = (request: LlmRequest) => Promise<string | LlmResponse>;
1328
1433
 
1329
1434
  declare class McpClientService {
@@ -1752,6 +1857,9 @@ declare function getMcpTools(config: McpConfig, toolFilter?: string[] | ((tool:
1752
1857
  type index$6_BaseTool = BaseTool;
1753
1858
  declare const index$6_BaseTool: typeof BaseTool;
1754
1859
  type index$6_BuildFunctionDeclarationOptions = BuildFunctionDeclarationOptions;
1860
+ type index$6_CreateToolConfig<T extends Record<string, any> = Record<string, never>> = CreateToolConfig<T>;
1861
+ type index$6_CreateToolConfigWithSchema<T extends Record<string, any>> = CreateToolConfigWithSchema<T>;
1862
+ type index$6_CreateToolConfigWithoutSchema = CreateToolConfigWithoutSchema;
1755
1863
  type index$6_ExitLoopTool = ExitLoopTool;
1756
1864
  declare const index$6_ExitLoopTool: typeof ExitLoopTool;
1757
1865
  type index$6_FileOperationsTool = FileOperationsTool;
@@ -1807,12 +1915,13 @@ declare const index$6_adkToMcpToolType: typeof adkToMcpToolType;
1807
1915
  declare const index$6_buildFunctionDeclaration: typeof buildFunctionDeclaration;
1808
1916
  declare const index$6_createFunctionTool: typeof createFunctionTool;
1809
1917
  declare const index$6_createSamplingHandler: typeof createSamplingHandler;
1918
+ declare const index$6_createTool: typeof createTool;
1810
1919
  declare const index$6_getMcpTools: typeof getMcpTools;
1811
1920
  declare const index$6_jsonSchemaToDeclaration: typeof jsonSchemaToDeclaration;
1812
1921
  declare const index$6_mcpSchemaToParameters: typeof mcpSchemaToParameters;
1813
1922
  declare const index$6_normalizeJsonSchema: typeof normalizeJsonSchema;
1814
1923
  declare namespace index$6 {
1815
- export { index$6_BaseTool as BaseTool, type index$6_BuildFunctionDeclarationOptions as BuildFunctionDeclarationOptions, index$6_ExitLoopTool as ExitLoopTool, index$6_FileOperationsTool as FileOperationsTool, index$6_FunctionTool as FunctionTool, index$6_GetUserChoiceTool as GetUserChoiceTool, index$6_GoogleSearch as GoogleSearch, index$6_HttpRequestTool as HttpRequestTool, index$6_LoadArtifactsTool as LoadArtifactsTool, index$6_LoadMemoryTool as LoadMemoryTool, index$6_McpAbi as McpAbi, index$6_McpAtp as McpAtp, index$6_McpBamm as McpBamm, index$6_McpCoinGecko as McpCoinGecko, type index$6_McpConfig as McpConfig, index$6_McpDiscord as McpDiscord, index$6_McpError as McpError, index$6_McpErrorType as McpErrorType, index$6_McpFilesystem as McpFilesystem, index$6_McpFraxlend as McpFraxlend, index$6_McpGeneric as McpGeneric, index$6_McpIqWiki as McpIqWiki, index$6_McpMemory as McpMemory, index$6_McpNearAgent as McpNearAgent, index$6_McpNearIntentSwaps as McpNearIntentSwaps, index$6_McpOdos as McpOdos, index$6_McpSamplingHandler as McpSamplingHandler, type index$6_McpSamplingRequest as McpSamplingRequest, type index$6_McpSamplingResponse as McpSamplingResponse, type index$6_McpServerConfig as McpServerConfig, index$6_McpTelegram as McpTelegram, index$6_McpToolset as McpToolset, type index$6_McpTransportType as McpTransportType, type index$6_SamplingHandler as SamplingHandler, type index$6_ToolConfig as ToolConfig, index$6_ToolContext as ToolContext, index$6_TransferToAgentTool as TransferToAgentTool, index$6_UserInteractionTool as UserInteractionTool, index$6_adkToMcpToolType as adkToMcpToolType, index$6_buildFunctionDeclaration as buildFunctionDeclaration, index$6_createFunctionTool as createFunctionTool, index$6_createSamplingHandler as createSamplingHandler, index$6_getMcpTools as getMcpTools, index$6_jsonSchemaToDeclaration as jsonSchemaToDeclaration, index$6_mcpSchemaToParameters as mcpSchemaToParameters, index$6_normalizeJsonSchema as normalizeJsonSchema };
1924
+ export { index$6_BaseTool as BaseTool, type index$6_BuildFunctionDeclarationOptions as BuildFunctionDeclarationOptions, type index$6_CreateToolConfig as CreateToolConfig, type index$6_CreateToolConfigWithSchema as CreateToolConfigWithSchema, type index$6_CreateToolConfigWithoutSchema as CreateToolConfigWithoutSchema, index$6_ExitLoopTool as ExitLoopTool, index$6_FileOperationsTool as FileOperationsTool, index$6_FunctionTool as FunctionTool, index$6_GetUserChoiceTool as GetUserChoiceTool, index$6_GoogleSearch as GoogleSearch, index$6_HttpRequestTool as HttpRequestTool, index$6_LoadArtifactsTool as LoadArtifactsTool, index$6_LoadMemoryTool as LoadMemoryTool, index$6_McpAbi as McpAbi, index$6_McpAtp as McpAtp, index$6_McpBamm as McpBamm, index$6_McpCoinGecko as McpCoinGecko, type index$6_McpConfig as McpConfig, index$6_McpDiscord as McpDiscord, index$6_McpError as McpError, index$6_McpErrorType as McpErrorType, index$6_McpFilesystem as McpFilesystem, index$6_McpFraxlend as McpFraxlend, index$6_McpGeneric as McpGeneric, index$6_McpIqWiki as McpIqWiki, index$6_McpMemory as McpMemory, index$6_McpNearAgent as McpNearAgent, index$6_McpNearIntentSwaps as McpNearIntentSwaps, index$6_McpOdos as McpOdos, index$6_McpSamplingHandler as McpSamplingHandler, type index$6_McpSamplingRequest as McpSamplingRequest, type index$6_McpSamplingResponse as McpSamplingResponse, type index$6_McpServerConfig as McpServerConfig, index$6_McpTelegram as McpTelegram, index$6_McpToolset as McpToolset, type index$6_McpTransportType as McpTransportType, type index$6_SamplingHandler as SamplingHandler, type index$6_ToolConfig as ToolConfig, index$6_ToolContext as ToolContext, index$6_TransferToAgentTool as TransferToAgentTool, index$6_UserInteractionTool as UserInteractionTool, index$6_adkToMcpToolType as adkToMcpToolType, index$6_buildFunctionDeclaration as buildFunctionDeclaration, index$6_createFunctionTool as createFunctionTool, index$6_createSamplingHandler as createSamplingHandler, index$6_createTool as createTool, index$6_getMcpTools as getMcpTools, index$6_jsonSchemaToDeclaration as jsonSchemaToDeclaration, index$6_mcpSchemaToParameters as mcpSchemaToParameters, index$6_normalizeJsonSchema as normalizeJsonSchema };
1816
1925
  }
1817
1926
 
1818
1927
  /**
@@ -4427,15 +4536,6 @@ declare abstract class BaseLlmFlow {
4427
4536
  _handleBeforeModelCallback(invocationContext: InvocationContext, llmRequest: LlmRequest, modelResponseEvent: Event): Promise<LlmResponse | undefined>;
4428
4537
  _handleAfterModelCallback(invocationContext: InvocationContext, llmResponse: LlmResponse, modelResponseEvent: Event): Promise<LlmResponse | undefined>;
4429
4538
  _finalizeModelResponseEvent(llmRequest: LlmRequest, llmResponse: LlmResponse, modelResponseEvent: Event): Event;
4430
- /**
4431
- * Logs data in a visually appealing format that works well in any terminal size.
4432
- * Uses vertical layout for better readability and respects debug settings.
4433
- */
4434
- _formatContentPreview(content: any): string;
4435
- /**
4436
- * Formats response content preview for debug logging
4437
- */
4438
- _formatResponsePreview(llmResponse: LlmResponse): string;
4439
4539
  __getLlm(invocationContext: InvocationContext): BaseLlm;
4440
4540
  }
4441
4541
 
@@ -4991,4 +5091,4 @@ declare const traceLlmCall: (invocationContext: InvocationContext, eventId: stri
4991
5091
 
4992
5092
  declare const VERSION = "0.1.0";
4993
5093
 
4994
- export { AF_FUNCTION_CALL_ID_PREFIX, type AfterAgentCallback, LlmAgent as Agent, AgentBuilder, type AgentBuilderConfig, type AgentType, index$4 as Agents, AiSdkLlm, AnthropicLlm, ApiKeyCredential, ApiKeyScheme, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, AuthTool, type AuthToolArguments, AutoFlow, BaseAgent, BaseCodeExecutor, type BaseCodeExecutorConfig, BaseLLMConnection, BaseLlm, BaseLlmFlow, BaseLlmRequestProcessor, BaseLlmResponseProcessor, type BaseMemoryService, BasePlanner, BaseSessionService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BeforeAgentCallback, type BuildFunctionDeclarationOptions, type BuiltAgent, BuiltInCodeExecutor, BuiltInPlanner, CallbackContext, type CodeExecutionInput, type CodeExecutionResult, CodeExecutionUtils, CodeExecutorContext, DatabaseSessionService, EnhancedAuthConfig, type EnhancedRunner, Event, EventActions, index$1 as Events, ExitLoopTool, type File, FileOperationsTool, index as Flows, type FullMessage, type FunctionDeclaration, FunctionTool, GcsArtifactService, type GetSessionConfig, GetUserChoiceTool, GoogleLlm, GoogleSearch, HttpRequestTool, HttpScheme, InMemoryArtifactService, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, type InstructionProvider, InvocationContext, type JSONSchema, LLMRegistry, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionsResponse, LlmAgent, type LlmAgentConfig, LlmCallsLimitExceededError, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, McpCoinGecko, type McpConfig, McpDiscord, McpError, McpErrorType, McpFilesystem, McpFraxlend, McpGeneric, McpIqWiki, McpMemory, McpNearAgent, McpNearIntentSwaps, McpOdos, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, type McpServerConfig, McpTelegram, McpToolset, type McpTransportType, index$3 as Memory, type MessagePart, index$5 as Models, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAiLlm, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, PlanReActPlanner, REQUEST_EUC_FUNCTION_CALL_NAME, ReadonlyContext, RunConfig, Runner, type SamplingHandler, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionConfig, index$2 as Sessions, type SingleAgentCallback, SingleFlow, State, StreamingMode, type TelemetryConfig, TelemetryService, type ThinkingConfig, type ToolConfig, ToolContext, type ToolUnion, index$6 as Tools, TransferToAgentTool, UserInteractionTool, VERSION, VertexAiSessionService, _findFunctionCallEventIfLastEventIsFunctionResponse, adkToMcpToolType, requestProcessor$2 as agentTransferRequestProcessor, requestProcessor$6 as basicRequestProcessor, buildFunctionDeclaration, requestProcessor as codeExecutionRequestProcessor, responseProcessor as codeExecutionResponseProcessor, requestProcessor$3 as contentRequestProcessor, createAuthToolArguments, createBranchContextForSubAgent, createDatabaseSessionService, createFunctionTool, createMysqlSessionService, createPostgresSessionService, createSamplingHandler, createSqliteSessionService, generateAuthEvent, generateClientFunctionCallId, getLongRunningFunctionCalls, getMcpTools, handleFunctionCallsAsync, handleFunctionCallsLive, requestProcessor$5 as identityRequestProcessor, initializeTelemetry, injectSessionState, requestProcessor$4 as instructionsRequestProcessor, isEnhancedAuthConfig, jsonSchemaToDeclaration, mcpSchemaToParameters, mergeAgentRun, mergeParallelFunctionResponseEvents, newInvocationContextId, requestProcessor$1 as nlPlanningRequestProcessor, responseProcessor$1 as nlPlanningResponseProcessor, normalizeJsonSchema, populateClientFunctionCallId, registerProviders, removeClientFunctionCallId, requestProcessor$7 as requestProcessor, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };
5094
+ export { AF_FUNCTION_CALL_ID_PREFIX, type AfterAgentCallback, LlmAgent as Agent, AgentBuilder, type AgentBuilderConfig, type AgentType, index$4 as Agents, AiSdkLlm, AnthropicLlm, ApiKeyCredential, ApiKeyScheme, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, AuthTool, type AuthToolArguments, AutoFlow, BaseAgent, BaseCodeExecutor, type BaseCodeExecutorConfig, BaseLLMConnection, BaseLlm, BaseLlmFlow, BaseLlmRequestProcessor, BaseLlmResponseProcessor, type BaseMemoryService, BasePlanner, BaseSessionService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BeforeAgentCallback, type BuildFunctionDeclarationOptions, type BuiltAgent, BuiltInCodeExecutor, BuiltInPlanner, CallbackContext, type CodeExecutionInput, type CodeExecutionResult, CodeExecutionUtils, CodeExecutorContext, type CreateToolConfig, type CreateToolConfigWithSchema, type CreateToolConfigWithoutSchema, DatabaseSessionService, EnhancedAuthConfig, type EnhancedRunner, Event, EventActions, index$1 as Events, ExitLoopTool, type File, FileOperationsTool, index as Flows, type FullMessage, type FunctionDeclaration, FunctionTool, GcsArtifactService, type GetSessionConfig, GetUserChoiceTool, GoogleLlm, GoogleSearch, HttpRequestTool, HttpScheme, InMemoryArtifactService, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, type InstructionProvider, InvocationContext, type JSONSchema, LLMRegistry, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionsResponse, LlmAgent, type LlmAgentConfig, LlmCallsLimitExceededError, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, McpCoinGecko, type McpConfig, McpDiscord, McpError, McpErrorType, McpFilesystem, McpFraxlend, McpGeneric, McpIqWiki, McpMemory, McpNearAgent, McpNearIntentSwaps, McpOdos, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, type McpServerConfig, McpTelegram, McpToolset, type McpTransportType, index$3 as Memory, type MessagePart, index$5 as Models, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAiLlm, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, PlanReActPlanner, REQUEST_EUC_FUNCTION_CALL_NAME, ReadonlyContext, RunConfig, Runner, type SamplingHandler, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionConfig, index$2 as Sessions, type SingleAgentCallback, SingleFlow, State, StreamingMode, type TelemetryConfig, TelemetryService, type ThinkingConfig, type ToolConfig, ToolContext, type ToolUnion, index$6 as Tools, TransferToAgentTool, UserInteractionTool, VERSION, VertexAiSessionService, _findFunctionCallEventIfLastEventIsFunctionResponse, adkToMcpToolType, requestProcessor$2 as agentTransferRequestProcessor, requestProcessor$6 as basicRequestProcessor, buildFunctionDeclaration, requestProcessor as codeExecutionRequestProcessor, responseProcessor as codeExecutionResponseProcessor, requestProcessor$3 as contentRequestProcessor, createAuthToolArguments, createBranchContextForSubAgent, createDatabaseSessionService, createFunctionTool, createMysqlSessionService, createPostgresSessionService, createSamplingHandler, createSqliteSessionService, createTool, generateAuthEvent, generateClientFunctionCallId, getLongRunningFunctionCalls, getMcpTools, handleFunctionCallsAsync, handleFunctionCallsLive, requestProcessor$5 as identityRequestProcessor, initializeTelemetry, injectSessionState, requestProcessor$4 as instructionsRequestProcessor, isEnhancedAuthConfig, jsonSchemaToDeclaration, mcpSchemaToParameters, mergeAgentRun, mergeParallelFunctionResponseEvents, newInvocationContextId, requestProcessor$1 as nlPlanningRequestProcessor, responseProcessor$1 as nlPlanningResponseProcessor, normalizeJsonSchema, populateClientFunctionCallId, registerProviders, removeClientFunctionCallId, requestProcessor$7 as requestProcessor, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };