@iqai/adk 0.0.6 → 0.0.8

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,13 +1,13 @@
1
1
  # @iqai/adk
2
2
 
3
- ## 0.0.6
3
+ ## 0.0.8
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - 54902c8: Adds debug logs
7
+ - 74ee653: Simplified sampling handler with adk message and response typings
8
8
 
9
- ## 0.0.5
9
+ ## 0.0.7
10
10
 
11
11
  ### Patch Changes
12
12
 
13
- - 5448661: Updates pglite session to take pglite instance as input instead of drizzle
13
+ - 35cb95d: Adds MCP Sampling request handling
package/README.md ADDED
@@ -0,0 +1,177 @@
1
+ # @iqai/adk - Agent Development Kit Core
2
+
3
+ `@iqai/adk` is the core TypeScript library for the Agent Development Kit, providing the foundational tools and abstractions to build sophisticated AI agents. It enables seamless integration with multiple Large Language Models (LLMs), advanced tool usage, and persistent memory capabilities.
4
+
5
+ <p align="center">
6
+ <a href="https://www.npmjs.com/package/@iqai/adk">
7
+ <img src="https://img.shields.io/npm/v/@iqai/adk" alt="NPM Version" />
8
+ </a>
9
+ <a href="https://www.npmjs.com/package/@iqai/adk">
10
+ <img src="https://img.shields.io/npm/dm/@iqai/adk" alt="NPM Downloads" />
11
+ </a>
12
+ <a href="https://github.com/IQAIcom/adk-ts/blob/main/LICENSE.md">
13
+ <img src="https://img.shields.io/npm/l/@iqai/adk" alt="License" />
14
+ </a>
15
+ <a href="https://github.com/IQAIcom/adk-ts">
16
+ <img src="https://img.shields.io/github/stars/IQAIcom/adk-ts?style=social" alt="GitHub Stars" />
17
+ </a>
18
+ </p>
19
+
20
+ ## 🚀 Core Features
21
+
22
+ The `@iqai/adk` package empowers your AI agent development with:
23
+
24
+ * **Multi-Provider LLM Support:** Flexibly integrate and switch between leading LLM providers like OpenAI, Anthropic, and Google.
25
+ * **Extensible Tool System:** Define and utilize custom tools with declarative schemas, allowing LLMs to intelligently leverage external functionalities.
26
+ * **Advanced Agent Reasoning Loop:** A complete reasoning loop implementation for complex task execution and iterative problem-solving.
27
+ * **Real-Time Streaming:** Support for streaming responses from LLMs for dynamic user interactions.
28
+ * **Flexible Authentication:** Mechanisms for securing agent API access.
29
+ * **Persistent Memory Systems:** Capabilities for agents to retain context and learn from past interactions.
30
+
31
+ ## 🚦 Installation
32
+
33
+ Install the `@iqai/adk` package using your preferred package manager:
34
+
35
+ ```bash
36
+ # Using npm
37
+ npm install @iqai/adk
38
+
39
+ # Using yarn
40
+ yarn add @iqai/adk
41
+
42
+ # Using pnpm
43
+ pnpm add @iqai/adk
44
+ ```
45
+
46
+ ## ⚙️ Environment Configuration
47
+
48
+ For the library to connect to LLM providers, you need to set up API keys. Create a `.env` file in the root of your project and add your keys:
49
+
50
+ ```env
51
+ OPENAI_API_KEY=your_openai_api_key
52
+ ANTHROPIC_API_KEY=your_anthropic_api_key
53
+ GOOGLE_API_KEY=your_google_api_key
54
+ ```
55
+ The library uses `dotenv` to load these variables automatically if `dotenv.config()` is called in your application.
56
+
57
+ ## 📖 Basic Usage
58
+
59
+ Here's a fundamental example of creating and running an agent:
60
+
61
+ ```typescript
62
+ import { Agent } from '@iqai/adk';
63
+ import dotenv from 'dotenv';
64
+
65
+ // Load environment variables
66
+ dotenv.config();
67
+
68
+ // Instantiate the agent
69
+ const myAgent = new Agent({
70
+ name: "simple_query_assistant",
71
+ model: "gemini-2.5-flash-preview-05-20", // Or "gpt-4-turbo", "claude-3-opus"
72
+ description: "A basic assistant to answer questions.",
73
+ instructions: "You are a helpful AI. Respond clearly and concisely."
74
+ });
75
+
76
+ // Asynchronously run the agent
77
+ async function runQuery() {
78
+ try {
79
+ const query = "What is the capital of France?";
80
+ console.log(`User: ${query}`);
81
+
82
+ const response = await myAgent.run({
83
+ messages: [{ role: 'user', content: query }]
84
+ });
85
+
86
+ console.log(`Agent: ${response.content}`);
87
+ } catch (error) {
88
+ console.error("Error during agent execution:", error);
89
+ }
90
+ }
91
+
92
+ runQuery();
93
+ ```
94
+
95
+ ## 🛠️ Using Tools with an Agent
96
+
97
+ Extend your agent's capabilities by defining and integrating custom tools.
98
+
99
+ ```typescript
100
+ import { Agent, BaseTool } from '@iqai/adk';
101
+ import dotenv from 'dotenv';
102
+
103
+ dotenv.config();
104
+
105
+ // Define a simple calculator tool
106
+ class CalculatorTool extends BaseTool {
107
+ constructor() {
108
+ super({
109
+ name: 'calculator',
110
+ description: 'Performs basic arithmetic operations: add, subtract, multiply, divide.'
111
+ });
112
+ }
113
+
114
+ getDeclaration() {
115
+ return {
116
+ name: this.name,
117
+ description: this.description,
118
+ parameters: {
119
+ type: 'object',
120
+ properties: {
121
+ operation: {
122
+ type: 'string',
123
+ enum: ['add', 'subtract', 'multiply', 'divide']
124
+ },
125
+ operand1: { type: 'number' },
126
+ operand2: { type: 'number' }
127
+ },
128
+ required: ['operation', 'operand1', 'operand2']
129
+ }
130
+ };
131
+ }
132
+
133
+ async runAsync(args: { operation: string; operand1: number; operand2: number }) {
134
+ const { operation, operand1, operand2 } = args;
135
+ switch (operation) {
136
+ case 'add': return { result: operand1 + operand2 };
137
+ case 'subtract': return { result: operand1 - operand2 };
138
+ case 'multiply': return { result: operand1 * operand2 };
139
+ case 'divide':
140
+ if (operand2 === 0) return { error: 'Cannot divide by zero.' };
141
+ return { result: operand1 / operand2 };
142
+ default: return { error: `Unknown operation: ${operation}` };
143
+ }
144
+ }
145
+ }
146
+
147
+ // Create an agent equipped with the calculator tool
148
+ const mathAgent = new Agent({
149
+ name: "math_assistant_agent",
150
+ model: "gpt-4-turbo", // Choose a model proficient with tool usage
151
+ instructions:
152
+ "You are a helpful assistant. Use the calculator tool for any mathematical calculations requested.",
153
+ tools: [new CalculatorTool()]
154
+ });
155
+
156
+ async function performCalculation() {
157
+ const response = await mathAgent.run({
158
+ messages: [
159
+ { role: 'user', content: 'What is 15 multiplied by 4?' }
160
+ ]
161
+ });
162
+ // The response.content will likely include the thought process and the tool's output.
163
+ console.log(JSON.stringify(response, null, 2));
164
+ }
165
+
166
+ performCalculation().catch(console.error);
167
+ ```
168
+
169
+ More detailed examples and advanced usage patterns can be found in the `apps/examples` directory of the main [ADK TypeScript repository](https://github.com/IQAIcom/adk-ts).
170
+
171
+ ## 🤝 Contributing
172
+
173
+ While this README focuses on the `@iqai/adk` package, contributions to the overall ADK TypeScript project are welcome. Please see the [Contributing Guide](https://github.com/IQAIcom/adk-ts/blob/main/CONTRIBUTING.md) in the main repository for details on how to contribute.
174
+
175
+ ## 📜 License
176
+
177
+ This package is licensed under the [MIT License](https://github.com/IQAIcom/adk-ts/blob/main/LICENSE.md).
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
2
- import { Tool } from '@modelcontextprotocol/sdk/types.js';
2
+ import { CreateMessageRequestSchema, CreateMessageResultSchema, Tool } from '@modelcontextprotocol/sdk/types.js';
3
+ import { z } from 'zod';
3
4
  import { AxiosInstance } from 'axios';
4
5
  import OpenAI from 'openai';
5
6
  import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
@@ -440,6 +441,7 @@ declare class AnthropicLLM extends BaseLLM {
440
441
  * Default parameters for requests
441
442
  */
442
443
  private defaultParams;
444
+ private logger;
443
445
  /**
444
446
  * Constructor for AnthropicLLM
445
447
  */
@@ -516,6 +518,7 @@ declare class AnthropicLLMConnection extends BaseLLMConnection {
516
518
  private responseCallback?;
517
519
  private errorCallback?;
518
520
  private endCallback?;
521
+ private logger;
519
522
  /**
520
523
  * Constructor
521
524
  */
@@ -712,6 +715,7 @@ declare class OpenAILLM extends BaseLLM {
712
715
  * Default parameters for requests
713
716
  */
714
717
  private defaultParams;
718
+ private logger;
715
719
  /**
716
720
  * Constructor for OpenAILLM
717
721
  */
@@ -1995,6 +1999,7 @@ declare class Agent extends BaseAgent {
1995
1999
  * The minimum relevance score for memory augmentation (0-1)
1996
2000
  */
1997
2001
  private memoryRelevanceThreshold;
2002
+ private logger;
1998
2003
  /**
1999
2004
  * Constructor for Agent
2000
2005
  */
@@ -2069,6 +2074,7 @@ interface EnhancedLLMResponse extends LLMResponse {
2069
2074
  * Each sub-agent's output becomes input to the next agent
2070
2075
  */
2071
2076
  declare class SequentialAgent extends BaseAgent {
2077
+ private logger;
2072
2078
  /**
2073
2079
  * Constructor for SequentialAgent
2074
2080
  */
@@ -2113,6 +2119,7 @@ interface ParallelAgentConfig {
2113
2119
  * All sub-agents execute independently with the same input
2114
2120
  */
2115
2121
  declare class ParallelAgent extends BaseAgent {
2122
+ private logger;
2116
2123
  /**
2117
2124
  * Constructor for ParallelAgent
2118
2125
  */
@@ -2181,6 +2188,7 @@ declare class LoopAgent extends BaseAgent {
2181
2188
  * Custom condition check function
2182
2189
  */
2183
2190
  private conditionCheck?;
2191
+ private logger;
2184
2192
  /**
2185
2193
  * Constructor for LoopAgent
2186
2194
  */
@@ -2278,6 +2286,7 @@ declare class LangGraphAgent extends BaseAgent {
2278
2286
  * Results from node executions
2279
2287
  */
2280
2288
  private results;
2289
+ private logger;
2281
2290
  /**
2282
2291
  * Constructor for LangGraphAgent
2283
2292
  */
@@ -2439,6 +2448,7 @@ declare function createFunctionTool(func: (...args: any[]) => any, options?: {
2439
2448
  * Simple GoogleSearch tool implementation
2440
2449
  */
2441
2450
  declare class GoogleSearch extends BaseTool {
2451
+ private logger;
2442
2452
  /**
2443
2453
  * Constructor for GoogleSearch
2444
2454
  */
@@ -2591,6 +2601,7 @@ declare module "./tool-context" {
2591
2601
  * Tool that allows an agent to exit the current execution loop
2592
2602
  */
2593
2603
  declare class ExitLoopTool extends BaseTool {
2604
+ private logger;
2594
2605
  /**
2595
2606
  * Constructor for ExitLoopTool
2596
2607
  */
@@ -2609,6 +2620,7 @@ declare class ExitLoopTool extends BaseTool {
2609
2620
  * Tool that allows an agent to get a choice from the user
2610
2621
  */
2611
2622
  declare class GetUserChoiceTool extends BaseTool {
2623
+ private logger;
2612
2624
  /**
2613
2625
  * Constructor for GetUserChoiceTool
2614
2626
  */
@@ -2632,6 +2644,7 @@ declare class GetUserChoiceTool extends BaseTool {
2632
2644
  * Tool that allows an agent to transfer control to another agent
2633
2645
  */
2634
2646
  declare class TransferToAgentTool extends BaseTool {
2647
+ private logger;
2635
2648
  /**
2636
2649
  * Constructor for TransferToAgentTool
2637
2650
  */
@@ -2652,6 +2665,7 @@ declare class TransferToAgentTool extends BaseTool {
2652
2665
  * Tool that allows an agent to load memories relevant to a query
2653
2666
  */
2654
2667
  declare class LoadMemoryTool extends BaseTool {
2668
+ private logger;
2655
2669
  /**
2656
2670
  * Constructor for LoadMemoryTool
2657
2671
  */
@@ -2670,7 +2684,6 @@ declare class LoadMemoryTool extends BaseTool {
2670
2684
 
2671
2685
  type McpConfig = {
2672
2686
  name: string;
2673
- description: string;
2674
2687
  transport: McpTransportType;
2675
2688
  timeout?: number;
2676
2689
  retryOptions?: {
@@ -2704,7 +2717,9 @@ declare enum McpErrorType {
2704
2717
  TOOL_EXECUTION_ERROR = "tool_execution_error",
2705
2718
  RESOURCE_CLOSED_ERROR = "resource_closed_error",
2706
2719
  TIMEOUT_ERROR = "timeout_error",
2707
- INVALID_SCHEMA_ERROR = "invalid_schema_error"
2720
+ INVALID_SCHEMA_ERROR = "invalid_schema_error",
2721
+ SAMPLING_ERROR = "SAMPLING_ERROR",
2722
+ INVALID_REQUEST_ERROR = "INVALID_REQUEST_ERROR"
2708
2723
  }
2709
2724
  /**
2710
2725
  * Custom error class for MCP-related errors
@@ -2714,12 +2729,49 @@ declare class McpError extends Error {
2714
2729
  originalError?: Error;
2715
2730
  constructor(message: string, type: McpErrorType, originalError?: Error);
2716
2731
  }
2732
+ type SamplingRequest = z.infer<typeof CreateMessageRequestSchema>;
2733
+ type SamplingResponse = z.infer<typeof CreateMessageResultSchema>;
2734
+
2735
+ /**
2736
+ * ADK sampling request format - what we pass to the user's handler
2737
+ */
2738
+ interface ADKSamplingRequest {
2739
+ messages: Message[];
2740
+ systemPrompt?: string;
2741
+ modelPreferences?: {
2742
+ hints?: Array<{
2743
+ name?: string;
2744
+ }>;
2745
+ costPriority?: number;
2746
+ speedPriority?: number;
2747
+ intelligencePriority?: number;
2748
+ };
2749
+ includeContext?: "none" | "thisServer" | "allServers";
2750
+ temperature?: number;
2751
+ maxTokens: number;
2752
+ stopSequences?: string[];
2753
+ metadata?: Record<string, unknown>;
2754
+ }
2755
+ /**
2756
+ * ADK sampling response format - what we expect from the user's handler
2757
+ */
2758
+ interface ADKSamplingResponse {
2759
+ model: string;
2760
+ stopReason?: "endTurn" | "stopSequence" | "maxTokens" | string;
2761
+ content: string | null;
2762
+ }
2763
+ /**
2764
+ * ADK sampling handler function type - receives ADK formatted messages
2765
+ */
2766
+ type ADKSamplingHandler = (request: ADKSamplingRequest) => Promise<ADKSamplingResponse>;
2717
2767
 
2718
2768
  declare class McpClientService {
2719
2769
  private config;
2720
2770
  private client;
2721
2771
  private transport;
2722
2772
  private isClosing;
2773
+ private mcpSamplingHandler;
2774
+ private logger;
2723
2775
  constructor(config: McpConfig);
2724
2776
  /**
2725
2777
  * Initializes and returns an MCP client based on configuration.
@@ -2754,6 +2806,15 @@ declare class McpClientService {
2754
2806
  * Checks if the client is currently connected
2755
2807
  */
2756
2808
  isConnected(): boolean;
2809
+ private setupSamplingHandler;
2810
+ /**
2811
+ * Set an ADK sampling handler
2812
+ */
2813
+ setSamplingHandler(handler: ADKSamplingHandler): void;
2814
+ /**
2815
+ * Remove the sampling handler
2816
+ */
2817
+ removeSamplingHandler(): void;
2757
2818
  }
2758
2819
 
2759
2820
  /**
@@ -2861,6 +2922,8 @@ declare const index$2_McpErrorType: typeof McpErrorType;
2861
2922
  type index$2_McpToolset = McpToolset;
2862
2923
  declare const index$2_McpToolset: typeof McpToolset;
2863
2924
  type index$2_McpTransportType = McpTransportType;
2925
+ type index$2_SamplingRequest = SamplingRequest;
2926
+ type index$2_SamplingResponse = SamplingResponse;
2864
2927
  type index$2_ToolConfig = ToolConfig;
2865
2928
  type index$2_ToolContext = ToolContext;
2866
2929
  declare const index$2_ToolContext: typeof ToolContext;
@@ -2876,7 +2939,7 @@ declare const index$2_jsonSchemaToDeclaration: typeof jsonSchemaToDeclaration;
2876
2939
  declare const index$2_mcpSchemaToParameters: typeof mcpSchemaToParameters;
2877
2940
  declare const index$2_normalizeJsonSchema: typeof normalizeJsonSchema;
2878
2941
  declare namespace index$2 {
2879
- export { index$2_BaseTool as BaseTool, type index$2_BuildFunctionDeclarationOptions as BuildFunctionDeclarationOptions, index$2_ExitLoopTool as ExitLoopTool, index$2_FileOperationsTool as FileOperationsTool, index$2_FunctionTool as FunctionTool, index$2_GetUserChoiceTool as GetUserChoiceTool, index$2_GoogleSearch as GoogleSearch, index$2_HttpRequestTool as HttpRequestTool, type index$2_IToolContext as IToolContext, index$2_LoadMemoryTool as LoadMemoryTool, type index$2_McpConfig as McpConfig, index$2_McpError as McpError, index$2_McpErrorType as McpErrorType, index$2_McpToolset as McpToolset, type index$2_McpTransportType as McpTransportType, type index$2_ToolConfig as ToolConfig, index$2_ToolContext as ToolContext, index$2_TransferToAgentTool as TransferToAgentTool, index$2_UserInteractionTool as UserInteractionTool, index$2_adkToMcpToolType as adkToMcpToolType, index$2_buildFunctionDeclaration as buildFunctionDeclaration, index$2_createFunctionTool as createFunctionTool, index$2_getMcpTools as getMcpTools, index$2_jsonSchemaToDeclaration as jsonSchemaToDeclaration, index$2_mcpSchemaToParameters as mcpSchemaToParameters, index$2_normalizeJsonSchema as normalizeJsonSchema };
2942
+ export { index$2_BaseTool as BaseTool, type index$2_BuildFunctionDeclarationOptions as BuildFunctionDeclarationOptions, index$2_ExitLoopTool as ExitLoopTool, index$2_FileOperationsTool as FileOperationsTool, index$2_FunctionTool as FunctionTool, index$2_GetUserChoiceTool as GetUserChoiceTool, index$2_GoogleSearch as GoogleSearch, index$2_HttpRequestTool as HttpRequestTool, type index$2_IToolContext as IToolContext, index$2_LoadMemoryTool as LoadMemoryTool, type index$2_McpConfig as McpConfig, index$2_McpError as McpError, index$2_McpErrorType as McpErrorType, index$2_McpToolset as McpToolset, type index$2_McpTransportType as McpTransportType, type index$2_SamplingRequest as SamplingRequest, type index$2_SamplingResponse as SamplingResponse, type index$2_ToolConfig as ToolConfig, index$2_ToolContext as ToolContext, index$2_TransferToAgentTool as TransferToAgentTool, index$2_UserInteractionTool as UserInteractionTool, index$2_adkToMcpToolType as adkToMcpToolType, index$2_buildFunctionDeclaration as buildFunctionDeclaration, index$2_createFunctionTool as createFunctionTool, index$2_getMcpTools as getMcpTools, index$2_jsonSchemaToDeclaration as jsonSchemaToDeclaration, index$2_mcpSchemaToParameters as mcpSchemaToParameters, index$2_normalizeJsonSchema as normalizeJsonSchema };
2880
2943
  }
2881
2944
 
2882
2945
  /**
@@ -2955,6 +3018,7 @@ declare class PersistentMemoryService implements BaseMemoryService {
2955
3018
  * File prefix for memory files
2956
3019
  */
2957
3020
  private filePrefix;
3021
+ private logger;
2958
3022
  /**
2959
3023
  * Constructor for PersistentMemoryService
2960
3024
  */
@@ -3434,4 +3498,4 @@ declare class InMemoryRunner extends Runner {
3434
3498
 
3435
3499
  declare const VERSION = "0.1.0";
3436
3500
 
3437
- export { Agent, type AgentConfig, index$3 as Agents, AnthropicLLM, type AnthropicLLMConfig, AnthropicLLMConnection, ApiKeyCredential, ApiKeyScheme, type AudioTranscriptionConfig, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, BaseAgent, BaseLLM, BaseLLMConnection, type BaseMemoryService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BuildFunctionDeclarationOptions, ExitLoopTool, FileOperationsTool, type FunctionCall, type FunctionDeclaration, FunctionTool, GetUserChoiceTool, GoogleLLM, type GoogleLLMConfig, GoogleSearch, HttpRequestTool, HttpScheme, type IToolContext, type ImageContent, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, InvocationContext, type JSONSchema, LLMRegistry, LLMRequest, type LLMRequestConfig, LLMResponse, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionOptions, LoadMemoryTool, LoopAgent, type LoopAgentConfig, type McpConfig, McpError, McpErrorType, McpToolset, type McpTransportType, index$1 as Memory, type MemoryResult, type Message, type MessageContent, type MessageRole, index$4 as Models, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAILLM, type OpenAILLMConfig, OpenAILLMConnection, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, PersistentMemoryService, PgLiteSessionService, PostgresSessionService, RunConfig, Runner, type SearchMemoryOptions, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionService, SessionState, index as Sessions, type SpeechConfig, SqliteSessionService, StreamingMode, type TextContent, type ToolCall, type ToolConfig, ToolContext, index$2 as Tools, TransferToAgentTool, UserInteractionTool, VERSION, adkToMcpToolType, buildFunctionDeclaration, cloneSession, createFunctionTool, generateSessionId, getMcpTools, jsonSchemaToDeclaration, mcpSchemaToParameters, normalizeJsonSchema, registerProviders, validateSession };
3501
+ export { Agent, type AgentConfig, index$3 as Agents, AnthropicLLM, type AnthropicLLMConfig, AnthropicLLMConnection, ApiKeyCredential, ApiKeyScheme, type AudioTranscriptionConfig, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, BaseAgent, BaseLLM, BaseLLMConnection, type BaseMemoryService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BuildFunctionDeclarationOptions, ExitLoopTool, FileOperationsTool, type FunctionCall, type FunctionDeclaration, FunctionTool, GetUserChoiceTool, GoogleLLM, type GoogleLLMConfig, GoogleSearch, HttpRequestTool, HttpScheme, type IToolContext, type ImageContent, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, InvocationContext, type JSONSchema, LLMRegistry, LLMRequest, type LLMRequestConfig, LLMResponse, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionOptions, LoadMemoryTool, LoopAgent, type LoopAgentConfig, type McpConfig, McpError, McpErrorType, McpToolset, type McpTransportType, index$1 as Memory, type MemoryResult, type Message, type MessageContent, type MessageRole, index$4 as Models, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAILLM, type OpenAILLMConfig, OpenAILLMConnection, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, PersistentMemoryService, PgLiteSessionService, PostgresSessionService, RunConfig, Runner, type SamplingRequest, type SamplingResponse, type SearchMemoryOptions, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionService, SessionState, index as Sessions, type SpeechConfig, SqliteSessionService, StreamingMode, type TextContent, type ToolCall, type ToolConfig, ToolContext, index$2 as Tools, TransferToAgentTool, UserInteractionTool, VERSION, adkToMcpToolType, buildFunctionDeclaration, cloneSession, createFunctionTool, generateSessionId, getMcpTools, jsonSchemaToDeclaration, mcpSchemaToParameters, normalizeJsonSchema, registerProviders, validateSession };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
2
- import { Tool } from '@modelcontextprotocol/sdk/types.js';
2
+ import { CreateMessageRequestSchema, CreateMessageResultSchema, Tool } from '@modelcontextprotocol/sdk/types.js';
3
+ import { z } from 'zod';
3
4
  import { AxiosInstance } from 'axios';
4
5
  import OpenAI from 'openai';
5
6
  import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
@@ -440,6 +441,7 @@ declare class AnthropicLLM extends BaseLLM {
440
441
  * Default parameters for requests
441
442
  */
442
443
  private defaultParams;
444
+ private logger;
443
445
  /**
444
446
  * Constructor for AnthropicLLM
445
447
  */
@@ -516,6 +518,7 @@ declare class AnthropicLLMConnection extends BaseLLMConnection {
516
518
  private responseCallback?;
517
519
  private errorCallback?;
518
520
  private endCallback?;
521
+ private logger;
519
522
  /**
520
523
  * Constructor
521
524
  */
@@ -712,6 +715,7 @@ declare class OpenAILLM extends BaseLLM {
712
715
  * Default parameters for requests
713
716
  */
714
717
  private defaultParams;
718
+ private logger;
715
719
  /**
716
720
  * Constructor for OpenAILLM
717
721
  */
@@ -1995,6 +1999,7 @@ declare class Agent extends BaseAgent {
1995
1999
  * The minimum relevance score for memory augmentation (0-1)
1996
2000
  */
1997
2001
  private memoryRelevanceThreshold;
2002
+ private logger;
1998
2003
  /**
1999
2004
  * Constructor for Agent
2000
2005
  */
@@ -2069,6 +2074,7 @@ interface EnhancedLLMResponse extends LLMResponse {
2069
2074
  * Each sub-agent's output becomes input to the next agent
2070
2075
  */
2071
2076
  declare class SequentialAgent extends BaseAgent {
2077
+ private logger;
2072
2078
  /**
2073
2079
  * Constructor for SequentialAgent
2074
2080
  */
@@ -2113,6 +2119,7 @@ interface ParallelAgentConfig {
2113
2119
  * All sub-agents execute independently with the same input
2114
2120
  */
2115
2121
  declare class ParallelAgent extends BaseAgent {
2122
+ private logger;
2116
2123
  /**
2117
2124
  * Constructor for ParallelAgent
2118
2125
  */
@@ -2181,6 +2188,7 @@ declare class LoopAgent extends BaseAgent {
2181
2188
  * Custom condition check function
2182
2189
  */
2183
2190
  private conditionCheck?;
2191
+ private logger;
2184
2192
  /**
2185
2193
  * Constructor for LoopAgent
2186
2194
  */
@@ -2278,6 +2286,7 @@ declare class LangGraphAgent extends BaseAgent {
2278
2286
  * Results from node executions
2279
2287
  */
2280
2288
  private results;
2289
+ private logger;
2281
2290
  /**
2282
2291
  * Constructor for LangGraphAgent
2283
2292
  */
@@ -2439,6 +2448,7 @@ declare function createFunctionTool(func: (...args: any[]) => any, options?: {
2439
2448
  * Simple GoogleSearch tool implementation
2440
2449
  */
2441
2450
  declare class GoogleSearch extends BaseTool {
2451
+ private logger;
2442
2452
  /**
2443
2453
  * Constructor for GoogleSearch
2444
2454
  */
@@ -2591,6 +2601,7 @@ declare module "./tool-context" {
2591
2601
  * Tool that allows an agent to exit the current execution loop
2592
2602
  */
2593
2603
  declare class ExitLoopTool extends BaseTool {
2604
+ private logger;
2594
2605
  /**
2595
2606
  * Constructor for ExitLoopTool
2596
2607
  */
@@ -2609,6 +2620,7 @@ declare class ExitLoopTool extends BaseTool {
2609
2620
  * Tool that allows an agent to get a choice from the user
2610
2621
  */
2611
2622
  declare class GetUserChoiceTool extends BaseTool {
2623
+ private logger;
2612
2624
  /**
2613
2625
  * Constructor for GetUserChoiceTool
2614
2626
  */
@@ -2632,6 +2644,7 @@ declare class GetUserChoiceTool extends BaseTool {
2632
2644
  * Tool that allows an agent to transfer control to another agent
2633
2645
  */
2634
2646
  declare class TransferToAgentTool extends BaseTool {
2647
+ private logger;
2635
2648
  /**
2636
2649
  * Constructor for TransferToAgentTool
2637
2650
  */
@@ -2652,6 +2665,7 @@ declare class TransferToAgentTool extends BaseTool {
2652
2665
  * Tool that allows an agent to load memories relevant to a query
2653
2666
  */
2654
2667
  declare class LoadMemoryTool extends BaseTool {
2668
+ private logger;
2655
2669
  /**
2656
2670
  * Constructor for LoadMemoryTool
2657
2671
  */
@@ -2670,7 +2684,6 @@ declare class LoadMemoryTool extends BaseTool {
2670
2684
 
2671
2685
  type McpConfig = {
2672
2686
  name: string;
2673
- description: string;
2674
2687
  transport: McpTransportType;
2675
2688
  timeout?: number;
2676
2689
  retryOptions?: {
@@ -2704,7 +2717,9 @@ declare enum McpErrorType {
2704
2717
  TOOL_EXECUTION_ERROR = "tool_execution_error",
2705
2718
  RESOURCE_CLOSED_ERROR = "resource_closed_error",
2706
2719
  TIMEOUT_ERROR = "timeout_error",
2707
- INVALID_SCHEMA_ERROR = "invalid_schema_error"
2720
+ INVALID_SCHEMA_ERROR = "invalid_schema_error",
2721
+ SAMPLING_ERROR = "SAMPLING_ERROR",
2722
+ INVALID_REQUEST_ERROR = "INVALID_REQUEST_ERROR"
2708
2723
  }
2709
2724
  /**
2710
2725
  * Custom error class for MCP-related errors
@@ -2714,12 +2729,49 @@ declare class McpError extends Error {
2714
2729
  originalError?: Error;
2715
2730
  constructor(message: string, type: McpErrorType, originalError?: Error);
2716
2731
  }
2732
+ type SamplingRequest = z.infer<typeof CreateMessageRequestSchema>;
2733
+ type SamplingResponse = z.infer<typeof CreateMessageResultSchema>;
2734
+
2735
+ /**
2736
+ * ADK sampling request format - what we pass to the user's handler
2737
+ */
2738
+ interface ADKSamplingRequest {
2739
+ messages: Message[];
2740
+ systemPrompt?: string;
2741
+ modelPreferences?: {
2742
+ hints?: Array<{
2743
+ name?: string;
2744
+ }>;
2745
+ costPriority?: number;
2746
+ speedPriority?: number;
2747
+ intelligencePriority?: number;
2748
+ };
2749
+ includeContext?: "none" | "thisServer" | "allServers";
2750
+ temperature?: number;
2751
+ maxTokens: number;
2752
+ stopSequences?: string[];
2753
+ metadata?: Record<string, unknown>;
2754
+ }
2755
+ /**
2756
+ * ADK sampling response format - what we expect from the user's handler
2757
+ */
2758
+ interface ADKSamplingResponse {
2759
+ model: string;
2760
+ stopReason?: "endTurn" | "stopSequence" | "maxTokens" | string;
2761
+ content: string | null;
2762
+ }
2763
+ /**
2764
+ * ADK sampling handler function type - receives ADK formatted messages
2765
+ */
2766
+ type ADKSamplingHandler = (request: ADKSamplingRequest) => Promise<ADKSamplingResponse>;
2717
2767
 
2718
2768
  declare class McpClientService {
2719
2769
  private config;
2720
2770
  private client;
2721
2771
  private transport;
2722
2772
  private isClosing;
2773
+ private mcpSamplingHandler;
2774
+ private logger;
2723
2775
  constructor(config: McpConfig);
2724
2776
  /**
2725
2777
  * Initializes and returns an MCP client based on configuration.
@@ -2754,6 +2806,15 @@ declare class McpClientService {
2754
2806
  * Checks if the client is currently connected
2755
2807
  */
2756
2808
  isConnected(): boolean;
2809
+ private setupSamplingHandler;
2810
+ /**
2811
+ * Set an ADK sampling handler
2812
+ */
2813
+ setSamplingHandler(handler: ADKSamplingHandler): void;
2814
+ /**
2815
+ * Remove the sampling handler
2816
+ */
2817
+ removeSamplingHandler(): void;
2757
2818
  }
2758
2819
 
2759
2820
  /**
@@ -2861,6 +2922,8 @@ declare const index$2_McpErrorType: typeof McpErrorType;
2861
2922
  type index$2_McpToolset = McpToolset;
2862
2923
  declare const index$2_McpToolset: typeof McpToolset;
2863
2924
  type index$2_McpTransportType = McpTransportType;
2925
+ type index$2_SamplingRequest = SamplingRequest;
2926
+ type index$2_SamplingResponse = SamplingResponse;
2864
2927
  type index$2_ToolConfig = ToolConfig;
2865
2928
  type index$2_ToolContext = ToolContext;
2866
2929
  declare const index$2_ToolContext: typeof ToolContext;
@@ -2876,7 +2939,7 @@ declare const index$2_jsonSchemaToDeclaration: typeof jsonSchemaToDeclaration;
2876
2939
  declare const index$2_mcpSchemaToParameters: typeof mcpSchemaToParameters;
2877
2940
  declare const index$2_normalizeJsonSchema: typeof normalizeJsonSchema;
2878
2941
  declare namespace index$2 {
2879
- export { index$2_BaseTool as BaseTool, type index$2_BuildFunctionDeclarationOptions as BuildFunctionDeclarationOptions, index$2_ExitLoopTool as ExitLoopTool, index$2_FileOperationsTool as FileOperationsTool, index$2_FunctionTool as FunctionTool, index$2_GetUserChoiceTool as GetUserChoiceTool, index$2_GoogleSearch as GoogleSearch, index$2_HttpRequestTool as HttpRequestTool, type index$2_IToolContext as IToolContext, index$2_LoadMemoryTool as LoadMemoryTool, type index$2_McpConfig as McpConfig, index$2_McpError as McpError, index$2_McpErrorType as McpErrorType, index$2_McpToolset as McpToolset, type index$2_McpTransportType as McpTransportType, type index$2_ToolConfig as ToolConfig, index$2_ToolContext as ToolContext, index$2_TransferToAgentTool as TransferToAgentTool, index$2_UserInteractionTool as UserInteractionTool, index$2_adkToMcpToolType as adkToMcpToolType, index$2_buildFunctionDeclaration as buildFunctionDeclaration, index$2_createFunctionTool as createFunctionTool, index$2_getMcpTools as getMcpTools, index$2_jsonSchemaToDeclaration as jsonSchemaToDeclaration, index$2_mcpSchemaToParameters as mcpSchemaToParameters, index$2_normalizeJsonSchema as normalizeJsonSchema };
2942
+ export { index$2_BaseTool as BaseTool, type index$2_BuildFunctionDeclarationOptions as BuildFunctionDeclarationOptions, index$2_ExitLoopTool as ExitLoopTool, index$2_FileOperationsTool as FileOperationsTool, index$2_FunctionTool as FunctionTool, index$2_GetUserChoiceTool as GetUserChoiceTool, index$2_GoogleSearch as GoogleSearch, index$2_HttpRequestTool as HttpRequestTool, type index$2_IToolContext as IToolContext, index$2_LoadMemoryTool as LoadMemoryTool, type index$2_McpConfig as McpConfig, index$2_McpError as McpError, index$2_McpErrorType as McpErrorType, index$2_McpToolset as McpToolset, type index$2_McpTransportType as McpTransportType, type index$2_SamplingRequest as SamplingRequest, type index$2_SamplingResponse as SamplingResponse, type index$2_ToolConfig as ToolConfig, index$2_ToolContext as ToolContext, index$2_TransferToAgentTool as TransferToAgentTool, index$2_UserInteractionTool as UserInteractionTool, index$2_adkToMcpToolType as adkToMcpToolType, index$2_buildFunctionDeclaration as buildFunctionDeclaration, index$2_createFunctionTool as createFunctionTool, index$2_getMcpTools as getMcpTools, index$2_jsonSchemaToDeclaration as jsonSchemaToDeclaration, index$2_mcpSchemaToParameters as mcpSchemaToParameters, index$2_normalizeJsonSchema as normalizeJsonSchema };
2880
2943
  }
2881
2944
 
2882
2945
  /**
@@ -2955,6 +3018,7 @@ declare class PersistentMemoryService implements BaseMemoryService {
2955
3018
  * File prefix for memory files
2956
3019
  */
2957
3020
  private filePrefix;
3021
+ private logger;
2958
3022
  /**
2959
3023
  * Constructor for PersistentMemoryService
2960
3024
  */
@@ -3434,4 +3498,4 @@ declare class InMemoryRunner extends Runner {
3434
3498
 
3435
3499
  declare const VERSION = "0.1.0";
3436
3500
 
3437
- export { Agent, type AgentConfig, index$3 as Agents, AnthropicLLM, type AnthropicLLMConfig, AnthropicLLMConnection, ApiKeyCredential, ApiKeyScheme, type AudioTranscriptionConfig, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, BaseAgent, BaseLLM, BaseLLMConnection, type BaseMemoryService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BuildFunctionDeclarationOptions, ExitLoopTool, FileOperationsTool, type FunctionCall, type FunctionDeclaration, FunctionTool, GetUserChoiceTool, GoogleLLM, type GoogleLLMConfig, GoogleSearch, HttpRequestTool, HttpScheme, type IToolContext, type ImageContent, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, InvocationContext, type JSONSchema, LLMRegistry, LLMRequest, type LLMRequestConfig, LLMResponse, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionOptions, LoadMemoryTool, LoopAgent, type LoopAgentConfig, type McpConfig, McpError, McpErrorType, McpToolset, type McpTransportType, index$1 as Memory, type MemoryResult, type Message, type MessageContent, type MessageRole, index$4 as Models, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAILLM, type OpenAILLMConfig, OpenAILLMConnection, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, PersistentMemoryService, PgLiteSessionService, PostgresSessionService, RunConfig, Runner, type SearchMemoryOptions, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionService, SessionState, index as Sessions, type SpeechConfig, SqliteSessionService, StreamingMode, type TextContent, type ToolCall, type ToolConfig, ToolContext, index$2 as Tools, TransferToAgentTool, UserInteractionTool, VERSION, adkToMcpToolType, buildFunctionDeclaration, cloneSession, createFunctionTool, generateSessionId, getMcpTools, jsonSchemaToDeclaration, mcpSchemaToParameters, normalizeJsonSchema, registerProviders, validateSession };
3501
+ export { Agent, type AgentConfig, index$3 as Agents, AnthropicLLM, type AnthropicLLMConfig, AnthropicLLMConnection, ApiKeyCredential, ApiKeyScheme, type AudioTranscriptionConfig, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, BaseAgent, BaseLLM, BaseLLMConnection, type BaseMemoryService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BuildFunctionDeclarationOptions, ExitLoopTool, FileOperationsTool, type FunctionCall, type FunctionDeclaration, FunctionTool, GetUserChoiceTool, GoogleLLM, type GoogleLLMConfig, GoogleSearch, HttpRequestTool, HttpScheme, type IToolContext, type ImageContent, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, InvocationContext, type JSONSchema, LLMRegistry, LLMRequest, type LLMRequestConfig, LLMResponse, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionOptions, LoadMemoryTool, LoopAgent, type LoopAgentConfig, type McpConfig, McpError, McpErrorType, McpToolset, type McpTransportType, index$1 as Memory, type MemoryResult, type Message, type MessageContent, type MessageRole, index$4 as Models, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAILLM, type OpenAILLMConfig, OpenAILLMConnection, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, PersistentMemoryService, PgLiteSessionService, PostgresSessionService, RunConfig, Runner, type SamplingRequest, type SamplingResponse, type SearchMemoryOptions, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionService, SessionState, index as Sessions, type SpeechConfig, SqliteSessionService, StreamingMode, type TextContent, type ToolCall, type ToolConfig, ToolContext, index$2 as Tools, TransferToAgentTool, UserInteractionTool, VERSION, adkToMcpToolType, buildFunctionDeclaration, cloneSession, createFunctionTool, generateSessionId, getMcpTools, jsonSchemaToDeclaration, mcpSchemaToParameters, normalizeJsonSchema, registerProviders, validateSession };