@iqai/adk 0.1.14 → 0.1.16
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 +12 -0
- package/dist/index.d.mts +38 -2
- package/dist/index.d.ts +38 -2
- package/dist/index.js +92 -33
- package/dist/index.mjs +120 -61
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Part, Content, Blob, SpeechConfig, AudioTranscriptionConfig, RealtimeInputConfig, ProactivityConfig, FunctionDeclaration, GroundingMetadata, GenerateContentResponseUsageMetadata, GenerateContentConfig, Schema, LiveConnectConfig, GoogleGenAI, FunctionCall } from '@google/genai';
|
|
2
2
|
export { Blob, Content, FunctionDeclaration, Schema as JSONSchema } from '@google/genai';
|
|
3
3
|
import { LanguageModel } from 'ai';
|
|
4
|
-
import * as z from 'zod
|
|
4
|
+
import * as z from 'zod';
|
|
5
|
+
import { z as z$1 } from 'zod';
|
|
5
6
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
6
7
|
import { CreateMessageRequestSchema, CreateMessageResultSchema, Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
7
|
-
import { z as z$1 } from 'zod';
|
|
8
8
|
import { Kysely, Generated } from 'kysely';
|
|
9
9
|
import { StorageOptions } from '@google-cloud/storage';
|
|
10
10
|
import { Tracer } from '@opentelemetry/api';
|
|
@@ -1304,6 +1304,18 @@ interface LlmAgentConfig<T extends BaseLlm = BaseLlm> {
|
|
|
1304
1304
|
* Description of the agent
|
|
1305
1305
|
*/
|
|
1306
1306
|
description: string;
|
|
1307
|
+
/**
|
|
1308
|
+
* Sub-agents that this agent can delegate to
|
|
1309
|
+
*/
|
|
1310
|
+
subAgents?: BaseAgent[];
|
|
1311
|
+
/**
|
|
1312
|
+
* Callback or list of callbacks to be invoked before the agent run
|
|
1313
|
+
*/
|
|
1314
|
+
beforeAgentCallback?: BeforeAgentCallback;
|
|
1315
|
+
/**
|
|
1316
|
+
* Callback or list of callbacks to be invoked after the agent run
|
|
1317
|
+
*/
|
|
1318
|
+
afterAgentCallback?: AfterAgentCallback;
|
|
1307
1319
|
/**
|
|
1308
1320
|
* The LLM model to use
|
|
1309
1321
|
* When not set, the agent will inherit the model from its ancestor
|
|
@@ -1877,6 +1889,10 @@ declare class TransferToAgentTool extends BaseTool {
|
|
|
1877
1889
|
* Constructor for TransferToAgentTool
|
|
1878
1890
|
*/
|
|
1879
1891
|
constructor();
|
|
1892
|
+
/**
|
|
1893
|
+
* Get the function declaration for the tool
|
|
1894
|
+
*/
|
|
1895
|
+
getDeclaration(): FunctionDeclaration;
|
|
1880
1896
|
/**
|
|
1881
1897
|
* Execute the transfer to agent action
|
|
1882
1898
|
*/
|
|
@@ -3921,6 +3937,8 @@ interface AgentBuilderConfig {
|
|
|
3921
3937
|
planner?: BasePlanner;
|
|
3922
3938
|
codeExecutor?: BaseCodeExecutor;
|
|
3923
3939
|
subAgents?: BaseAgent[];
|
|
3940
|
+
beforeAgentCallback?: BeforeAgentCallback;
|
|
3941
|
+
afterAgentCallback?: AfterAgentCallback;
|
|
3924
3942
|
maxIterations?: number;
|
|
3925
3943
|
nodes?: LangGraphNode[];
|
|
3926
3944
|
rootNode?: string;
|
|
@@ -4080,6 +4098,24 @@ declare class AgentBuilder {
|
|
|
4080
4098
|
* @returns This builder instance for chaining
|
|
4081
4099
|
*/
|
|
4082
4100
|
withOutputKey(outputKey: string): this;
|
|
4101
|
+
/**
|
|
4102
|
+
* Add sub-agents to the agent
|
|
4103
|
+
* @param subAgents Sub-agents to add to the agent
|
|
4104
|
+
* @returns This builder instance for chaining
|
|
4105
|
+
*/
|
|
4106
|
+
withSubAgents(subAgents: BaseAgent[]): this;
|
|
4107
|
+
/**
|
|
4108
|
+
* Set the before agent callback
|
|
4109
|
+
* @param callback Callback to invoke before agent execution
|
|
4110
|
+
* @returns This builder instance for chaining
|
|
4111
|
+
*/
|
|
4112
|
+
withBeforeAgentCallback(callback: BeforeAgentCallback): this;
|
|
4113
|
+
/**
|
|
4114
|
+
* Set the after agent callback
|
|
4115
|
+
* @param callback Callback to invoke after agent execution
|
|
4116
|
+
* @returns This builder instance for chaining
|
|
4117
|
+
*/
|
|
4118
|
+
withAfterAgentCallback(callback: AfterAgentCallback): this;
|
|
4083
4119
|
/**
|
|
4084
4120
|
* Configure as a sequential agent
|
|
4085
4121
|
* @param subAgents Sub-agents to execute in sequence
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Part, Content, Blob, SpeechConfig, AudioTranscriptionConfig, RealtimeInputConfig, ProactivityConfig, FunctionDeclaration, GroundingMetadata, GenerateContentResponseUsageMetadata, GenerateContentConfig, Schema, LiveConnectConfig, GoogleGenAI, FunctionCall } from '@google/genai';
|
|
2
2
|
export { Blob, Content, FunctionDeclaration, Schema as JSONSchema } from '@google/genai';
|
|
3
3
|
import { LanguageModel } from 'ai';
|
|
4
|
-
import * as z from 'zod
|
|
4
|
+
import * as z from 'zod';
|
|
5
|
+
import { z as z$1 } from 'zod';
|
|
5
6
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
6
7
|
import { CreateMessageRequestSchema, CreateMessageResultSchema, Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
7
|
-
import { z as z$1 } from 'zod';
|
|
8
8
|
import { Kysely, Generated } from 'kysely';
|
|
9
9
|
import { StorageOptions } from '@google-cloud/storage';
|
|
10
10
|
import { Tracer } from '@opentelemetry/api';
|
|
@@ -1304,6 +1304,18 @@ interface LlmAgentConfig<T extends BaseLlm = BaseLlm> {
|
|
|
1304
1304
|
* Description of the agent
|
|
1305
1305
|
*/
|
|
1306
1306
|
description: string;
|
|
1307
|
+
/**
|
|
1308
|
+
* Sub-agents that this agent can delegate to
|
|
1309
|
+
*/
|
|
1310
|
+
subAgents?: BaseAgent[];
|
|
1311
|
+
/**
|
|
1312
|
+
* Callback or list of callbacks to be invoked before the agent run
|
|
1313
|
+
*/
|
|
1314
|
+
beforeAgentCallback?: BeforeAgentCallback;
|
|
1315
|
+
/**
|
|
1316
|
+
* Callback or list of callbacks to be invoked after the agent run
|
|
1317
|
+
*/
|
|
1318
|
+
afterAgentCallback?: AfterAgentCallback;
|
|
1307
1319
|
/**
|
|
1308
1320
|
* The LLM model to use
|
|
1309
1321
|
* When not set, the agent will inherit the model from its ancestor
|
|
@@ -1877,6 +1889,10 @@ declare class TransferToAgentTool extends BaseTool {
|
|
|
1877
1889
|
* Constructor for TransferToAgentTool
|
|
1878
1890
|
*/
|
|
1879
1891
|
constructor();
|
|
1892
|
+
/**
|
|
1893
|
+
* Get the function declaration for the tool
|
|
1894
|
+
*/
|
|
1895
|
+
getDeclaration(): FunctionDeclaration;
|
|
1880
1896
|
/**
|
|
1881
1897
|
* Execute the transfer to agent action
|
|
1882
1898
|
*/
|
|
@@ -3921,6 +3937,8 @@ interface AgentBuilderConfig {
|
|
|
3921
3937
|
planner?: BasePlanner;
|
|
3922
3938
|
codeExecutor?: BaseCodeExecutor;
|
|
3923
3939
|
subAgents?: BaseAgent[];
|
|
3940
|
+
beforeAgentCallback?: BeforeAgentCallback;
|
|
3941
|
+
afterAgentCallback?: AfterAgentCallback;
|
|
3924
3942
|
maxIterations?: number;
|
|
3925
3943
|
nodes?: LangGraphNode[];
|
|
3926
3944
|
rootNode?: string;
|
|
@@ -4080,6 +4098,24 @@ declare class AgentBuilder {
|
|
|
4080
4098
|
* @returns This builder instance for chaining
|
|
4081
4099
|
*/
|
|
4082
4100
|
withOutputKey(outputKey: string): this;
|
|
4101
|
+
/**
|
|
4102
|
+
* Add sub-agents to the agent
|
|
4103
|
+
* @param subAgents Sub-agents to add to the agent
|
|
4104
|
+
* @returns This builder instance for chaining
|
|
4105
|
+
*/
|
|
4106
|
+
withSubAgents(subAgents: BaseAgent[]): this;
|
|
4107
|
+
/**
|
|
4108
|
+
* Set the before agent callback
|
|
4109
|
+
* @param callback Callback to invoke before agent execution
|
|
4110
|
+
* @returns This builder instance for chaining
|
|
4111
|
+
*/
|
|
4112
|
+
withBeforeAgentCallback(callback: BeforeAgentCallback): this;
|
|
4113
|
+
/**
|
|
4114
|
+
* Set the after agent callback
|
|
4115
|
+
* @param callback Callback to invoke after agent execution
|
|
4116
|
+
* @returns This builder instance for chaining
|
|
4117
|
+
*/
|
|
4118
|
+
withAfterAgentCallback(callback: AfterAgentCallback): this;
|
|
4083
4119
|
/**
|
|
4084
4120
|
* Configure as a sequential agent
|
|
4085
4121
|
* @param subAgents Sub-agents to execute in sequence
|
package/dist/index.js
CHANGED
|
@@ -3855,7 +3855,8 @@ init_base_tool();
|
|
|
3855
3855
|
|
|
3856
3856
|
// src/tools/base/create-tool.ts
|
|
3857
3857
|
init_base_tool();
|
|
3858
|
-
var
|
|
3858
|
+
var _zod = require('zod'); var z = _interopRequireWildcard(_zod);
|
|
3859
|
+
var _zodtojsonschema = require('zod-to-json-schema');
|
|
3859
3860
|
var CreatedTool = class extends BaseTool {
|
|
3860
3861
|
|
|
3861
3862
|
|
|
@@ -3885,7 +3886,7 @@ var CreatedTool = class extends BaseTool {
|
|
|
3885
3886
|
} catch (error) {
|
|
3886
3887
|
if (error instanceof z.ZodError) {
|
|
3887
3888
|
return {
|
|
3888
|
-
error: `Invalid arguments for ${this.name}: ${
|
|
3889
|
+
error: `Invalid arguments for ${this.name}: ${error.message}`
|
|
3889
3890
|
};
|
|
3890
3891
|
}
|
|
3891
3892
|
return {
|
|
@@ -3903,7 +3904,11 @@ var CreatedTool = class extends BaseTool {
|
|
|
3903
3904
|
* Builds the function declaration from the Zod schema
|
|
3904
3905
|
*/
|
|
3905
3906
|
buildDeclaration() {
|
|
3906
|
-
const
|
|
3907
|
+
const rawParameters = _zodtojsonschema.zodToJsonSchema.call(void 0, this.schema, {
|
|
3908
|
+
target: "jsonSchema7",
|
|
3909
|
+
$refStrategy: "none"
|
|
3910
|
+
});
|
|
3911
|
+
const { $schema, ...parameters } = rawParameters;
|
|
3907
3912
|
return {
|
|
3908
3913
|
name: this.name,
|
|
3909
3914
|
description: this.description,
|
|
@@ -4846,6 +4851,7 @@ var GetUserChoiceTool = (_class18 = class extends BaseTool {
|
|
|
4846
4851
|
// src/tools/common/transfer-to-agent-tool.ts
|
|
4847
4852
|
init_logger();
|
|
4848
4853
|
init_base_tool();
|
|
4854
|
+
|
|
4849
4855
|
var TransferToAgentTool = (_class19 = class extends BaseTool {
|
|
4850
4856
|
__init29() {this.logger = new Logger({ name: "TransferToAgentTool" })}
|
|
4851
4857
|
/**
|
|
@@ -4854,9 +4860,28 @@ var TransferToAgentTool = (_class19 = class extends BaseTool {
|
|
|
4854
4860
|
constructor() {
|
|
4855
4861
|
super({
|
|
4856
4862
|
name: "transfer_to_agent",
|
|
4857
|
-
description: "Transfer the question to another agent."
|
|
4863
|
+
description: "Transfer the question to another agent when it's more suitable to answer the user's question according to the agent's description. Use this function when you determine that another agent in the system would be better equipped to handle the user's request based on their specialized capabilities and expertise areas."
|
|
4858
4864
|
});_class19.prototype.__init29.call(this);;
|
|
4859
4865
|
}
|
|
4866
|
+
/**
|
|
4867
|
+
* Get the function declaration for the tool
|
|
4868
|
+
*/
|
|
4869
|
+
getDeclaration() {
|
|
4870
|
+
return {
|
|
4871
|
+
name: this.name,
|
|
4872
|
+
description: this.description,
|
|
4873
|
+
parameters: {
|
|
4874
|
+
type: _genai.Type.OBJECT,
|
|
4875
|
+
properties: {
|
|
4876
|
+
agent_name: {
|
|
4877
|
+
type: _genai.Type.STRING,
|
|
4878
|
+
description: "The name of the agent to transfer control to"
|
|
4879
|
+
}
|
|
4880
|
+
},
|
|
4881
|
+
required: ["agent_name"]
|
|
4882
|
+
}
|
|
4883
|
+
};
|
|
4884
|
+
}
|
|
4860
4885
|
/**
|
|
4861
4886
|
* Execute the transfer to agent action
|
|
4862
4887
|
*/
|
|
@@ -8464,12 +8489,12 @@ var SingleFlow = class extends BaseLlmFlow {
|
|
|
8464
8489
|
};
|
|
8465
8490
|
|
|
8466
8491
|
// src/flows/llm-flows/agent-transfer.ts
|
|
8492
|
+
var _dedent = require('dedent'); var _dedent2 = _interopRequireDefault(_dedent);
|
|
8467
8493
|
var AgentTransferLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
8468
8494
|
/**
|
|
8469
8495
|
* Processes agent transfer by adding transfer instructions and tools
|
|
8470
8496
|
* if the agent has transfer targets available
|
|
8471
8497
|
*/
|
|
8472
|
-
// eslint-disable-next-line @typescript-eslint/require-yield
|
|
8473
8498
|
async *runAsync(invocationContext, llmRequest) {
|
|
8474
8499
|
const agent = invocationContext.agent;
|
|
8475
8500
|
if (!("subAgents" in agent) || typeof agent.subAgents !== "object") {
|
|
@@ -8487,60 +8512,61 @@ var AgentTransferLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
8487
8512
|
const transferToAgentTool = new TransferToAgentTool();
|
|
8488
8513
|
const toolContext = new ToolContext(invocationContext);
|
|
8489
8514
|
await transferToAgentTool.processLlmRequest(toolContext, llmRequest);
|
|
8490
|
-
|
|
8491
|
-
|
|
8515
|
+
const shouldYield = false;
|
|
8516
|
+
if (shouldYield) {
|
|
8517
|
+
yield {};
|
|
8492
8518
|
}
|
|
8493
8519
|
}
|
|
8494
8520
|
};
|
|
8495
8521
|
function buildTargetAgentsInfo(targetAgent) {
|
|
8496
|
-
return `
|
|
8497
|
-
Agent name: ${targetAgent.name}
|
|
8498
|
-
Agent description: ${targetAgent.description}
|
|
8499
|
-
`;
|
|
8522
|
+
return _dedent2.default`
|
|
8523
|
+
Agent name: ${targetAgent.name}
|
|
8524
|
+
Agent description: ${targetAgent.description}
|
|
8525
|
+
`;
|
|
8500
8526
|
}
|
|
8501
8527
|
function buildTargetAgentsInstructions(agent, targetAgents) {
|
|
8502
8528
|
const lineBreak = "\n";
|
|
8503
8529
|
const transferFunctionName = "transfer_to_agent";
|
|
8504
|
-
let instructions = `
|
|
8505
|
-
You have a list of other agents to transfer to:
|
|
8530
|
+
let instructions = _dedent2.default`
|
|
8531
|
+
You have a list of other agents to transfer to:
|
|
8506
8532
|
|
|
8507
|
-
${targetAgents.map((targetAgent) => buildTargetAgentsInfo(targetAgent)).join(lineBreak)}
|
|
8533
|
+
${targetAgents.map((targetAgent) => buildTargetAgentsInfo(targetAgent)).join(lineBreak)}
|
|
8508
8534
|
|
|
8509
|
-
If you are the best to answer the question according to your description, you
|
|
8510
|
-
can answer it.
|
|
8535
|
+
If you are the best to answer the question according to your description, you
|
|
8536
|
+
can answer it.
|
|
8511
8537
|
|
|
8512
|
-
If another agent is better for answering the question according to its
|
|
8513
|
-
description, call \`${transferFunctionName}\` function to transfer the
|
|
8514
|
-
question to that agent. When transferring, do not generate any text other than
|
|
8515
|
-
the function call.
|
|
8538
|
+
If another agent is better for answering the question according to its
|
|
8539
|
+
description, call \`${transferFunctionName}\` function to transfer the
|
|
8540
|
+
question to that agent. When transferring, do not generate any text other than
|
|
8541
|
+
the function call.
|
|
8516
8542
|
`;
|
|
8517
8543
|
if (agent.parentAgent && !agent.disallowTransferToParent) {
|
|
8518
|
-
instructions += `
|
|
8519
|
-
Your parent agent is ${agent.parentAgent.name}. If neither the other agents nor
|
|
8520
|
-
you are best for answering the question according to the descriptions, transfer
|
|
8521
|
-
to your parent agent.
|
|
8522
|
-
`;
|
|
8544
|
+
instructions += _dedent2.default`
|
|
8545
|
+
Your parent agent is ${agent.parentAgent.name}. If neither the other agents nor
|
|
8546
|
+
you are best for answering the question according to the descriptions, transfer
|
|
8547
|
+
to your parent agent.
|
|
8548
|
+
`;
|
|
8523
8549
|
}
|
|
8524
8550
|
return instructions;
|
|
8525
8551
|
}
|
|
8526
8552
|
function getTransferTargets(agent) {
|
|
8527
|
-
const
|
|
8553
|
+
const targets = [];
|
|
8528
8554
|
if (agent.subAgents && Array.isArray(agent.subAgents)) {
|
|
8529
|
-
|
|
8555
|
+
targets.push(...agent.subAgents);
|
|
8530
8556
|
}
|
|
8531
8557
|
if (!agent.parentAgent || !("subAgents" in agent.parentAgent)) {
|
|
8532
|
-
return
|
|
8558
|
+
return targets;
|
|
8533
8559
|
}
|
|
8534
8560
|
if (!agent.disallowTransferToParent) {
|
|
8535
|
-
|
|
8561
|
+
targets.push(agent.parentAgent);
|
|
8536
8562
|
}
|
|
8537
8563
|
if (!agent.disallowTransferToPeers && agent.parentAgent.subAgents) {
|
|
8538
8564
|
const peerAgents = agent.parentAgent.subAgents.filter(
|
|
8539
8565
|
(peerAgent) => peerAgent.name !== agent.name
|
|
8540
8566
|
);
|
|
8541
|
-
|
|
8567
|
+
targets.push(...peerAgents);
|
|
8542
8568
|
}
|
|
8543
|
-
return
|
|
8569
|
+
return targets;
|
|
8544
8570
|
}
|
|
8545
8571
|
var requestProcessor8 = new AgentTransferLlmRequestProcessor();
|
|
8546
8572
|
|
|
@@ -8642,7 +8668,10 @@ var LlmAgent = (_class26 = class _LlmAgent extends BaseAgent {
|
|
|
8642
8668
|
constructor(config) {
|
|
8643
8669
|
super({
|
|
8644
8670
|
name: config.name,
|
|
8645
|
-
description: config.description
|
|
8671
|
+
description: config.description,
|
|
8672
|
+
subAgents: config.subAgents,
|
|
8673
|
+
beforeAgentCallback: config.beforeAgentCallback,
|
|
8674
|
+
afterAgentCallback: config.afterAgentCallback
|
|
8646
8675
|
});_class26.prototype.__init46.call(this);;
|
|
8647
8676
|
this.model = config.model || "";
|
|
8648
8677
|
this.instruction = config.instruction || "";
|
|
@@ -10119,6 +10148,33 @@ var AgentBuilder = (_class32 = class _AgentBuilder {
|
|
|
10119
10148
|
this.config.outputKey = outputKey;
|
|
10120
10149
|
return this;
|
|
10121
10150
|
}
|
|
10151
|
+
/**
|
|
10152
|
+
* Add sub-agents to the agent
|
|
10153
|
+
* @param subAgents Sub-agents to add to the agent
|
|
10154
|
+
* @returns This builder instance for chaining
|
|
10155
|
+
*/
|
|
10156
|
+
withSubAgents(subAgents) {
|
|
10157
|
+
this.config.subAgents = subAgents;
|
|
10158
|
+
return this;
|
|
10159
|
+
}
|
|
10160
|
+
/**
|
|
10161
|
+
* Set the before agent callback
|
|
10162
|
+
* @param callback Callback to invoke before agent execution
|
|
10163
|
+
* @returns This builder instance for chaining
|
|
10164
|
+
*/
|
|
10165
|
+
withBeforeAgentCallback(callback) {
|
|
10166
|
+
this.config.beforeAgentCallback = callback;
|
|
10167
|
+
return this;
|
|
10168
|
+
}
|
|
10169
|
+
/**
|
|
10170
|
+
* Set the after agent callback
|
|
10171
|
+
* @param callback Callback to invoke after agent execution
|
|
10172
|
+
* @returns This builder instance for chaining
|
|
10173
|
+
*/
|
|
10174
|
+
withAfterAgentCallback(callback) {
|
|
10175
|
+
this.config.afterAgentCallback = callback;
|
|
10176
|
+
return this;
|
|
10177
|
+
}
|
|
10122
10178
|
/**
|
|
10123
10179
|
* Configure as a sequential agent
|
|
10124
10180
|
* @param subAgents Sub-agents to execute in sequence
|
|
@@ -10290,6 +10346,9 @@ var AgentBuilder = (_class32 = class _AgentBuilder {
|
|
|
10290
10346
|
tools: this.config.tools,
|
|
10291
10347
|
planner: this.config.planner,
|
|
10292
10348
|
codeExecutor: this.config.codeExecutor,
|
|
10349
|
+
subAgents: this.config.subAgents,
|
|
10350
|
+
beforeAgentCallback: this.config.beforeAgentCallback,
|
|
10351
|
+
afterAgentCallback: this.config.afterAgentCallback,
|
|
10293
10352
|
memoryService: this.memoryService,
|
|
10294
10353
|
artifactService: this.artifactService,
|
|
10295
10354
|
outputKey: this.config.outputKey,
|
|
@@ -11122,7 +11181,7 @@ var DatabaseSessionService = (_class33 = class extends BaseSessionService {
|
|
|
11122
11181
|
}, _class33);
|
|
11123
11182
|
|
|
11124
11183
|
// src/sessions/database-factories.ts
|
|
11125
|
-
|
|
11184
|
+
|
|
11126
11185
|
|
|
11127
11186
|
function createDependencyError(packageName, dbType) {
|
|
11128
11187
|
return new Error(
|
package/dist/index.mjs
CHANGED
|
@@ -3855,7 +3855,8 @@ init_base_tool();
|
|
|
3855
3855
|
|
|
3856
3856
|
// src/tools/base/create-tool.ts
|
|
3857
3857
|
init_base_tool();
|
|
3858
|
-
import * as z from "zod
|
|
3858
|
+
import * as z from "zod";
|
|
3859
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
3859
3860
|
var CreatedTool = class extends BaseTool {
|
|
3860
3861
|
func;
|
|
3861
3862
|
schema;
|
|
@@ -3885,7 +3886,7 @@ var CreatedTool = class extends BaseTool {
|
|
|
3885
3886
|
} catch (error) {
|
|
3886
3887
|
if (error instanceof z.ZodError) {
|
|
3887
3888
|
return {
|
|
3888
|
-
error: `Invalid arguments for ${this.name}: ${
|
|
3889
|
+
error: `Invalid arguments for ${this.name}: ${error.message}`
|
|
3889
3890
|
};
|
|
3890
3891
|
}
|
|
3891
3892
|
return {
|
|
@@ -3903,7 +3904,11 @@ var CreatedTool = class extends BaseTool {
|
|
|
3903
3904
|
* Builds the function declaration from the Zod schema
|
|
3904
3905
|
*/
|
|
3905
3906
|
buildDeclaration() {
|
|
3906
|
-
const
|
|
3907
|
+
const rawParameters = zodToJsonSchema(this.schema, {
|
|
3908
|
+
target: "jsonSchema7",
|
|
3909
|
+
$refStrategy: "none"
|
|
3910
|
+
});
|
|
3911
|
+
const { $schema, ...parameters } = rawParameters;
|
|
3907
3912
|
return {
|
|
3908
3913
|
name: this.name,
|
|
3909
3914
|
description: this.description,
|
|
@@ -4846,6 +4851,7 @@ var GetUserChoiceTool = class extends BaseTool {
|
|
|
4846
4851
|
// src/tools/common/transfer-to-agent-tool.ts
|
|
4847
4852
|
init_logger();
|
|
4848
4853
|
init_base_tool();
|
|
4854
|
+
import { Type as Type8 } from "@google/genai";
|
|
4849
4855
|
var TransferToAgentTool = class extends BaseTool {
|
|
4850
4856
|
logger = new Logger({ name: "TransferToAgentTool" });
|
|
4851
4857
|
/**
|
|
@@ -4854,9 +4860,28 @@ var TransferToAgentTool = class extends BaseTool {
|
|
|
4854
4860
|
constructor() {
|
|
4855
4861
|
super({
|
|
4856
4862
|
name: "transfer_to_agent",
|
|
4857
|
-
description: "Transfer the question to another agent."
|
|
4863
|
+
description: "Transfer the question to another agent when it's more suitable to answer the user's question according to the agent's description. Use this function when you determine that another agent in the system would be better equipped to handle the user's request based on their specialized capabilities and expertise areas."
|
|
4858
4864
|
});
|
|
4859
4865
|
}
|
|
4866
|
+
/**
|
|
4867
|
+
* Get the function declaration for the tool
|
|
4868
|
+
*/
|
|
4869
|
+
getDeclaration() {
|
|
4870
|
+
return {
|
|
4871
|
+
name: this.name,
|
|
4872
|
+
description: this.description,
|
|
4873
|
+
parameters: {
|
|
4874
|
+
type: Type8.OBJECT,
|
|
4875
|
+
properties: {
|
|
4876
|
+
agent_name: {
|
|
4877
|
+
type: Type8.STRING,
|
|
4878
|
+
description: "The name of the agent to transfer control to"
|
|
4879
|
+
}
|
|
4880
|
+
},
|
|
4881
|
+
required: ["agent_name"]
|
|
4882
|
+
}
|
|
4883
|
+
};
|
|
4884
|
+
}
|
|
4860
4885
|
/**
|
|
4861
4886
|
* Execute the transfer to agent action
|
|
4862
4887
|
*/
|
|
@@ -4869,7 +4894,7 @@ var TransferToAgentTool = class extends BaseTool {
|
|
|
4869
4894
|
// src/tools/common/load-memory-tool.ts
|
|
4870
4895
|
init_logger();
|
|
4871
4896
|
init_base_tool();
|
|
4872
|
-
import { Type as
|
|
4897
|
+
import { Type as Type9 } from "@google/genai";
|
|
4873
4898
|
var LoadMemoryTool = class extends BaseTool {
|
|
4874
4899
|
logger = new Logger({ name: "LoadMemoryTool" });
|
|
4875
4900
|
/**
|
|
@@ -4889,10 +4914,10 @@ var LoadMemoryTool = class extends BaseTool {
|
|
|
4889
4914
|
name: this.name,
|
|
4890
4915
|
description: this.description,
|
|
4891
4916
|
parameters: {
|
|
4892
|
-
type:
|
|
4917
|
+
type: Type9.OBJECT,
|
|
4893
4918
|
properties: {
|
|
4894
4919
|
query: {
|
|
4895
|
-
type:
|
|
4920
|
+
type: Type9.STRING,
|
|
4896
4921
|
description: "The query to load memories for"
|
|
4897
4922
|
}
|
|
4898
4923
|
},
|
|
@@ -4923,7 +4948,7 @@ var LoadMemoryTool = class extends BaseTool {
|
|
|
4923
4948
|
|
|
4924
4949
|
// src/tools/common/load-artifacts-tool.ts
|
|
4925
4950
|
init_base_tool();
|
|
4926
|
-
import { Type as
|
|
4951
|
+
import { Type as Type10 } from "@google/genai";
|
|
4927
4952
|
var LoadArtifactsTool = class extends BaseTool {
|
|
4928
4953
|
constructor() {
|
|
4929
4954
|
super({
|
|
@@ -4939,12 +4964,12 @@ var LoadArtifactsTool = class extends BaseTool {
|
|
|
4939
4964
|
name: this.name,
|
|
4940
4965
|
description: this.description,
|
|
4941
4966
|
parameters: {
|
|
4942
|
-
type:
|
|
4967
|
+
type: Type10.OBJECT,
|
|
4943
4968
|
properties: {
|
|
4944
4969
|
artifact_names: {
|
|
4945
|
-
type:
|
|
4970
|
+
type: Type10.ARRAY,
|
|
4946
4971
|
items: {
|
|
4947
|
-
type:
|
|
4972
|
+
type: Type10.STRING
|
|
4948
4973
|
},
|
|
4949
4974
|
description: "List of artifact names to load"
|
|
4950
4975
|
}
|
|
@@ -5563,7 +5588,7 @@ init_logger();
|
|
|
5563
5588
|
init_base_tool();
|
|
5564
5589
|
|
|
5565
5590
|
// src/tools/mcp/schema-conversion.ts
|
|
5566
|
-
import { Type as
|
|
5591
|
+
import { Type as Type11 } from "@google/genai";
|
|
5567
5592
|
function adkToMcpToolType(tool) {
|
|
5568
5593
|
const declaration = tool.getDeclaration();
|
|
5569
5594
|
const params = declarationToJsonSchema(declaration);
|
|
@@ -5592,13 +5617,13 @@ function jsonSchemaToDeclaration(name, description, schema) {
|
|
|
5592
5617
|
parameters = schema;
|
|
5593
5618
|
} else {
|
|
5594
5619
|
parameters = {
|
|
5595
|
-
type:
|
|
5620
|
+
type: Type11.OBJECT,
|
|
5596
5621
|
properties: schema
|
|
5597
5622
|
};
|
|
5598
5623
|
}
|
|
5599
5624
|
} else {
|
|
5600
5625
|
parameters = {
|
|
5601
|
-
type:
|
|
5626
|
+
type: Type11.OBJECT,
|
|
5602
5627
|
properties: {}
|
|
5603
5628
|
};
|
|
5604
5629
|
}
|
|
@@ -5610,7 +5635,7 @@ function jsonSchemaToDeclaration(name, description, schema) {
|
|
|
5610
5635
|
}
|
|
5611
5636
|
function normalizeJsonSchema(schema) {
|
|
5612
5637
|
if (!schema) {
|
|
5613
|
-
return { type:
|
|
5638
|
+
return { type: Type11.OBJECT, properties: {} };
|
|
5614
5639
|
}
|
|
5615
5640
|
const normalizedSchema = { ...schema };
|
|
5616
5641
|
if (!normalizedSchema.type) {
|
|
@@ -5627,39 +5652,39 @@ function normalizeJsonSchema(schema) {
|
|
|
5627
5652
|
case "integer":
|
|
5628
5653
|
return normalizeNumberSchema(normalizedSchema);
|
|
5629
5654
|
case "boolean":
|
|
5630
|
-
return { type:
|
|
5655
|
+
return { type: Type11.BOOLEAN };
|
|
5631
5656
|
case "null":
|
|
5632
|
-
return { type:
|
|
5657
|
+
return { type: Type11.NULL };
|
|
5633
5658
|
default:
|
|
5634
5659
|
return normalizedSchema;
|
|
5635
5660
|
}
|
|
5636
5661
|
}
|
|
5637
5662
|
function determineSchemaType(schema) {
|
|
5638
5663
|
if (schema.properties || schema.required || schema.additionalProperties !== void 0) {
|
|
5639
|
-
return
|
|
5664
|
+
return Type11.OBJECT;
|
|
5640
5665
|
}
|
|
5641
5666
|
if (schema.items) {
|
|
5642
|
-
return
|
|
5667
|
+
return Type11.ARRAY;
|
|
5643
5668
|
}
|
|
5644
5669
|
if (schema.enum !== void 0) {
|
|
5645
|
-
if (schema.enum.length === 0) return
|
|
5670
|
+
if (schema.enum.length === 0) return Type11.STRING;
|
|
5646
5671
|
const firstItem = schema.enum[0];
|
|
5647
|
-
if (typeof firstItem === "string") return
|
|
5648
|
-
if (typeof firstItem === "number") return
|
|
5649
|
-
if (typeof firstItem === "boolean") return
|
|
5650
|
-
return
|
|
5672
|
+
if (typeof firstItem === "string") return Type11.STRING;
|
|
5673
|
+
if (typeof firstItem === "number") return Type11.NUMBER;
|
|
5674
|
+
if (typeof firstItem === "boolean") return Type11.BOOLEAN;
|
|
5675
|
+
return Type11.STRING;
|
|
5651
5676
|
}
|
|
5652
5677
|
if (schema.minLength !== void 0 || schema.maxLength !== void 0 || schema.pattern) {
|
|
5653
|
-
return
|
|
5678
|
+
return Type11.STRING;
|
|
5654
5679
|
}
|
|
5655
5680
|
if (schema.minimum !== void 0 || schema.maximum !== void 0 || schema.exclusiveMinimum !== void 0 || schema.exclusiveMaximum !== void 0) {
|
|
5656
|
-
return schema.multipleOf === void 0 || schema.multipleOf % 1 === 0 ?
|
|
5681
|
+
return schema.multipleOf === void 0 || schema.multipleOf % 1 === 0 ? Type11.INTEGER : Type11.NUMBER;
|
|
5657
5682
|
}
|
|
5658
|
-
return
|
|
5683
|
+
return Type11.OBJECT;
|
|
5659
5684
|
}
|
|
5660
5685
|
function normalizeObjectSchema(schema) {
|
|
5661
5686
|
const normalizedSchema = {
|
|
5662
|
-
type:
|
|
5687
|
+
type: Type11.OBJECT,
|
|
5663
5688
|
properties: {}
|
|
5664
5689
|
};
|
|
5665
5690
|
if (schema.properties) {
|
|
@@ -5677,7 +5702,7 @@ function normalizeObjectSchema(schema) {
|
|
|
5677
5702
|
}
|
|
5678
5703
|
function normalizeArraySchema(schema) {
|
|
5679
5704
|
const normalizedSchema = {
|
|
5680
|
-
type:
|
|
5705
|
+
type: Type11.ARRAY
|
|
5681
5706
|
};
|
|
5682
5707
|
if (schema.items) {
|
|
5683
5708
|
normalizedSchema.items = normalizeJsonSchema(
|
|
@@ -5694,7 +5719,7 @@ function normalizeArraySchema(schema) {
|
|
|
5694
5719
|
}
|
|
5695
5720
|
function normalizeStringSchema(schema) {
|
|
5696
5721
|
const normalizedSchema = {
|
|
5697
|
-
type:
|
|
5722
|
+
type: Type11.STRING
|
|
5698
5723
|
};
|
|
5699
5724
|
if (schema.minLength !== void 0)
|
|
5700
5725
|
normalizedSchema.minLength = schema.minLength;
|
|
@@ -5727,7 +5752,7 @@ function mcpSchemaToParameters(mcpTool) {
|
|
|
5727
5752
|
}
|
|
5728
5753
|
if (!schema) {
|
|
5729
5754
|
return {
|
|
5730
|
-
type:
|
|
5755
|
+
type: Type11.OBJECT,
|
|
5731
5756
|
properties: {}
|
|
5732
5757
|
};
|
|
5733
5758
|
}
|
|
@@ -8464,12 +8489,12 @@ var SingleFlow = class extends BaseLlmFlow {
|
|
|
8464
8489
|
};
|
|
8465
8490
|
|
|
8466
8491
|
// src/flows/llm-flows/agent-transfer.ts
|
|
8492
|
+
import dedent from "dedent";
|
|
8467
8493
|
var AgentTransferLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
8468
8494
|
/**
|
|
8469
8495
|
* Processes agent transfer by adding transfer instructions and tools
|
|
8470
8496
|
* if the agent has transfer targets available
|
|
8471
8497
|
*/
|
|
8472
|
-
// eslint-disable-next-line @typescript-eslint/require-yield
|
|
8473
8498
|
async *runAsync(invocationContext, llmRequest) {
|
|
8474
8499
|
const agent = invocationContext.agent;
|
|
8475
8500
|
if (!("subAgents" in agent) || typeof agent.subAgents !== "object") {
|
|
@@ -8487,60 +8512,61 @@ var AgentTransferLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
8487
8512
|
const transferToAgentTool = new TransferToAgentTool();
|
|
8488
8513
|
const toolContext = new ToolContext(invocationContext);
|
|
8489
8514
|
await transferToAgentTool.processLlmRequest(toolContext, llmRequest);
|
|
8490
|
-
|
|
8491
|
-
|
|
8515
|
+
const shouldYield = false;
|
|
8516
|
+
if (shouldYield) {
|
|
8517
|
+
yield {};
|
|
8492
8518
|
}
|
|
8493
8519
|
}
|
|
8494
8520
|
};
|
|
8495
8521
|
function buildTargetAgentsInfo(targetAgent) {
|
|
8496
|
-
return `
|
|
8497
|
-
Agent name: ${targetAgent.name}
|
|
8498
|
-
Agent description: ${targetAgent.description}
|
|
8499
|
-
`;
|
|
8522
|
+
return dedent`
|
|
8523
|
+
Agent name: ${targetAgent.name}
|
|
8524
|
+
Agent description: ${targetAgent.description}
|
|
8525
|
+
`;
|
|
8500
8526
|
}
|
|
8501
8527
|
function buildTargetAgentsInstructions(agent, targetAgents) {
|
|
8502
8528
|
const lineBreak = "\n";
|
|
8503
8529
|
const transferFunctionName = "transfer_to_agent";
|
|
8504
|
-
let instructions = `
|
|
8505
|
-
You have a list of other agents to transfer to:
|
|
8530
|
+
let instructions = dedent`
|
|
8531
|
+
You have a list of other agents to transfer to:
|
|
8506
8532
|
|
|
8507
|
-
${targetAgents.map((targetAgent) => buildTargetAgentsInfo(targetAgent)).join(lineBreak)}
|
|
8533
|
+
${targetAgents.map((targetAgent) => buildTargetAgentsInfo(targetAgent)).join(lineBreak)}
|
|
8508
8534
|
|
|
8509
|
-
If you are the best to answer the question according to your description, you
|
|
8510
|
-
can answer it.
|
|
8535
|
+
If you are the best to answer the question according to your description, you
|
|
8536
|
+
can answer it.
|
|
8511
8537
|
|
|
8512
|
-
If another agent is better for answering the question according to its
|
|
8513
|
-
description, call \`${transferFunctionName}\` function to transfer the
|
|
8514
|
-
question to that agent. When transferring, do not generate any text other than
|
|
8515
|
-
the function call.
|
|
8538
|
+
If another agent is better for answering the question according to its
|
|
8539
|
+
description, call \`${transferFunctionName}\` function to transfer the
|
|
8540
|
+
question to that agent. When transferring, do not generate any text other than
|
|
8541
|
+
the function call.
|
|
8516
8542
|
`;
|
|
8517
8543
|
if (agent.parentAgent && !agent.disallowTransferToParent) {
|
|
8518
|
-
instructions += `
|
|
8519
|
-
Your parent agent is ${agent.parentAgent.name}. If neither the other agents nor
|
|
8520
|
-
you are best for answering the question according to the descriptions, transfer
|
|
8521
|
-
to your parent agent.
|
|
8522
|
-
`;
|
|
8544
|
+
instructions += dedent`
|
|
8545
|
+
Your parent agent is ${agent.parentAgent.name}. If neither the other agents nor
|
|
8546
|
+
you are best for answering the question according to the descriptions, transfer
|
|
8547
|
+
to your parent agent.
|
|
8548
|
+
`;
|
|
8523
8549
|
}
|
|
8524
8550
|
return instructions;
|
|
8525
8551
|
}
|
|
8526
8552
|
function getTransferTargets(agent) {
|
|
8527
|
-
const
|
|
8553
|
+
const targets = [];
|
|
8528
8554
|
if (agent.subAgents && Array.isArray(agent.subAgents)) {
|
|
8529
|
-
|
|
8555
|
+
targets.push(...agent.subAgents);
|
|
8530
8556
|
}
|
|
8531
8557
|
if (!agent.parentAgent || !("subAgents" in agent.parentAgent)) {
|
|
8532
|
-
return
|
|
8558
|
+
return targets;
|
|
8533
8559
|
}
|
|
8534
8560
|
if (!agent.disallowTransferToParent) {
|
|
8535
|
-
|
|
8561
|
+
targets.push(agent.parentAgent);
|
|
8536
8562
|
}
|
|
8537
8563
|
if (!agent.disallowTransferToPeers && agent.parentAgent.subAgents) {
|
|
8538
8564
|
const peerAgents = agent.parentAgent.subAgents.filter(
|
|
8539
8565
|
(peerAgent) => peerAgent.name !== agent.name
|
|
8540
8566
|
);
|
|
8541
|
-
|
|
8567
|
+
targets.push(...peerAgents);
|
|
8542
8568
|
}
|
|
8543
|
-
return
|
|
8569
|
+
return targets;
|
|
8544
8570
|
}
|
|
8545
8571
|
var requestProcessor8 = new AgentTransferLlmRequestProcessor();
|
|
8546
8572
|
|
|
@@ -8642,7 +8668,10 @@ var LlmAgent = class _LlmAgent extends BaseAgent {
|
|
|
8642
8668
|
constructor(config) {
|
|
8643
8669
|
super({
|
|
8644
8670
|
name: config.name,
|
|
8645
|
-
description: config.description
|
|
8671
|
+
description: config.description,
|
|
8672
|
+
subAgents: config.subAgents,
|
|
8673
|
+
beforeAgentCallback: config.beforeAgentCallback,
|
|
8674
|
+
afterAgentCallback: config.afterAgentCallback
|
|
8646
8675
|
});
|
|
8647
8676
|
this.model = config.model || "";
|
|
8648
8677
|
this.instruction = config.instruction || "";
|
|
@@ -10119,6 +10148,33 @@ var AgentBuilder = class _AgentBuilder {
|
|
|
10119
10148
|
this.config.outputKey = outputKey;
|
|
10120
10149
|
return this;
|
|
10121
10150
|
}
|
|
10151
|
+
/**
|
|
10152
|
+
* Add sub-agents to the agent
|
|
10153
|
+
* @param subAgents Sub-agents to add to the agent
|
|
10154
|
+
* @returns This builder instance for chaining
|
|
10155
|
+
*/
|
|
10156
|
+
withSubAgents(subAgents) {
|
|
10157
|
+
this.config.subAgents = subAgents;
|
|
10158
|
+
return this;
|
|
10159
|
+
}
|
|
10160
|
+
/**
|
|
10161
|
+
* Set the before agent callback
|
|
10162
|
+
* @param callback Callback to invoke before agent execution
|
|
10163
|
+
* @returns This builder instance for chaining
|
|
10164
|
+
*/
|
|
10165
|
+
withBeforeAgentCallback(callback) {
|
|
10166
|
+
this.config.beforeAgentCallback = callback;
|
|
10167
|
+
return this;
|
|
10168
|
+
}
|
|
10169
|
+
/**
|
|
10170
|
+
* Set the after agent callback
|
|
10171
|
+
* @param callback Callback to invoke after agent execution
|
|
10172
|
+
* @returns This builder instance for chaining
|
|
10173
|
+
*/
|
|
10174
|
+
withAfterAgentCallback(callback) {
|
|
10175
|
+
this.config.afterAgentCallback = callback;
|
|
10176
|
+
return this;
|
|
10177
|
+
}
|
|
10122
10178
|
/**
|
|
10123
10179
|
* Configure as a sequential agent
|
|
10124
10180
|
* @param subAgents Sub-agents to execute in sequence
|
|
@@ -10290,6 +10346,9 @@ var AgentBuilder = class _AgentBuilder {
|
|
|
10290
10346
|
tools: this.config.tools,
|
|
10291
10347
|
planner: this.config.planner,
|
|
10292
10348
|
codeExecutor: this.config.codeExecutor,
|
|
10349
|
+
subAgents: this.config.subAgents,
|
|
10350
|
+
beforeAgentCallback: this.config.beforeAgentCallback,
|
|
10351
|
+
afterAgentCallback: this.config.afterAgentCallback,
|
|
10293
10352
|
memoryService: this.memoryService,
|
|
10294
10353
|
artifactService: this.artifactService,
|
|
10295
10354
|
outputKey: this.config.outputKey,
|
|
@@ -11122,11 +11181,11 @@ var DatabaseSessionService = class extends BaseSessionService {
|
|
|
11122
11181
|
};
|
|
11123
11182
|
|
|
11124
11183
|
// src/sessions/database-factories.ts
|
|
11125
|
-
import
|
|
11184
|
+
import dedent2 from "dedent";
|
|
11126
11185
|
import { Kysely, MysqlDialect, PostgresDialect, SqliteDialect } from "kysely";
|
|
11127
11186
|
function createDependencyError(packageName, dbType) {
|
|
11128
11187
|
return new Error(
|
|
11129
|
-
|
|
11188
|
+
dedent2`
|
|
11130
11189
|
Missing required peer dependency: ${packageName}
|
|
11131
11190
|
To use ${dbType} sessions, install the required package:
|
|
11132
11191
|
npm install ${packageName}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iqai/adk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"description": "Agent Development Kit for TypeScript with multi-provider LLM support",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -44,7 +44,8 @@
|
|
|
44
44
|
"kysely": "^0.28.2",
|
|
45
45
|
"openai": "^4.93.0",
|
|
46
46
|
"uuid": "^11.1.0",
|
|
47
|
-
"zod": "^3.25.67"
|
|
47
|
+
"zod": "^3.25.67",
|
|
48
|
+
"zod-to-json-schema": "^3.24.6"
|
|
48
49
|
},
|
|
49
50
|
"peerDependencies": {
|
|
50
51
|
"better-sqlite3": "^11.10.0",
|