@iqai/adk 0.1.14 → 0.1.15
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 +6 -0
- package/dist/index.d.mts +36 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +84 -30
- package/dist/index.mjs +112 -58
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -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
|
@@ -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
|
@@ -4846,6 +4846,7 @@ var GetUserChoiceTool = (_class18 = class extends BaseTool {
|
|
|
4846
4846
|
// src/tools/common/transfer-to-agent-tool.ts
|
|
4847
4847
|
init_logger();
|
|
4848
4848
|
init_base_tool();
|
|
4849
|
+
|
|
4849
4850
|
var TransferToAgentTool = (_class19 = class extends BaseTool {
|
|
4850
4851
|
__init29() {this.logger = new Logger({ name: "TransferToAgentTool" })}
|
|
4851
4852
|
/**
|
|
@@ -4854,9 +4855,28 @@ var TransferToAgentTool = (_class19 = class extends BaseTool {
|
|
|
4854
4855
|
constructor() {
|
|
4855
4856
|
super({
|
|
4856
4857
|
name: "transfer_to_agent",
|
|
4857
|
-
description: "Transfer the question to another agent."
|
|
4858
|
+
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
4859
|
});_class19.prototype.__init29.call(this);;
|
|
4859
4860
|
}
|
|
4861
|
+
/**
|
|
4862
|
+
* Get the function declaration for the tool
|
|
4863
|
+
*/
|
|
4864
|
+
getDeclaration() {
|
|
4865
|
+
return {
|
|
4866
|
+
name: this.name,
|
|
4867
|
+
description: this.description,
|
|
4868
|
+
parameters: {
|
|
4869
|
+
type: _genai.Type.OBJECT,
|
|
4870
|
+
properties: {
|
|
4871
|
+
agent_name: {
|
|
4872
|
+
type: _genai.Type.STRING,
|
|
4873
|
+
description: "The name of the agent to transfer control to"
|
|
4874
|
+
}
|
|
4875
|
+
},
|
|
4876
|
+
required: ["agent_name"]
|
|
4877
|
+
}
|
|
4878
|
+
};
|
|
4879
|
+
}
|
|
4860
4880
|
/**
|
|
4861
4881
|
* Execute the transfer to agent action
|
|
4862
4882
|
*/
|
|
@@ -8464,12 +8484,12 @@ var SingleFlow = class extends BaseLlmFlow {
|
|
|
8464
8484
|
};
|
|
8465
8485
|
|
|
8466
8486
|
// src/flows/llm-flows/agent-transfer.ts
|
|
8487
|
+
var _dedent = require('dedent'); var _dedent2 = _interopRequireDefault(_dedent);
|
|
8467
8488
|
var AgentTransferLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
8468
8489
|
/**
|
|
8469
8490
|
* Processes agent transfer by adding transfer instructions and tools
|
|
8470
8491
|
* if the agent has transfer targets available
|
|
8471
8492
|
*/
|
|
8472
|
-
// eslint-disable-next-line @typescript-eslint/require-yield
|
|
8473
8493
|
async *runAsync(invocationContext, llmRequest) {
|
|
8474
8494
|
const agent = invocationContext.agent;
|
|
8475
8495
|
if (!("subAgents" in agent) || typeof agent.subAgents !== "object") {
|
|
@@ -8487,60 +8507,61 @@ var AgentTransferLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
8487
8507
|
const transferToAgentTool = new TransferToAgentTool();
|
|
8488
8508
|
const toolContext = new ToolContext(invocationContext);
|
|
8489
8509
|
await transferToAgentTool.processLlmRequest(toolContext, llmRequest);
|
|
8490
|
-
|
|
8491
|
-
|
|
8510
|
+
const shouldYield = false;
|
|
8511
|
+
if (shouldYield) {
|
|
8512
|
+
yield {};
|
|
8492
8513
|
}
|
|
8493
8514
|
}
|
|
8494
8515
|
};
|
|
8495
8516
|
function buildTargetAgentsInfo(targetAgent) {
|
|
8496
|
-
return `
|
|
8497
|
-
Agent name: ${targetAgent.name}
|
|
8498
|
-
Agent description: ${targetAgent.description}
|
|
8499
|
-
`;
|
|
8517
|
+
return _dedent2.default`
|
|
8518
|
+
Agent name: ${targetAgent.name}
|
|
8519
|
+
Agent description: ${targetAgent.description}
|
|
8520
|
+
`;
|
|
8500
8521
|
}
|
|
8501
8522
|
function buildTargetAgentsInstructions(agent, targetAgents) {
|
|
8502
8523
|
const lineBreak = "\n";
|
|
8503
8524
|
const transferFunctionName = "transfer_to_agent";
|
|
8504
|
-
let instructions = `
|
|
8505
|
-
You have a list of other agents to transfer to:
|
|
8525
|
+
let instructions = _dedent2.default`
|
|
8526
|
+
You have a list of other agents to transfer to:
|
|
8506
8527
|
|
|
8507
|
-
${targetAgents.map((targetAgent) => buildTargetAgentsInfo(targetAgent)).join(lineBreak)}
|
|
8528
|
+
${targetAgents.map((targetAgent) => buildTargetAgentsInfo(targetAgent)).join(lineBreak)}
|
|
8508
8529
|
|
|
8509
|
-
If you are the best to answer the question according to your description, you
|
|
8510
|
-
can answer it.
|
|
8530
|
+
If you are the best to answer the question according to your description, you
|
|
8531
|
+
can answer it.
|
|
8511
8532
|
|
|
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.
|
|
8533
|
+
If another agent is better for answering the question according to its
|
|
8534
|
+
description, call \`${transferFunctionName}\` function to transfer the
|
|
8535
|
+
question to that agent. When transferring, do not generate any text other than
|
|
8536
|
+
the function call.
|
|
8516
8537
|
`;
|
|
8517
8538
|
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
|
-
`;
|
|
8539
|
+
instructions += _dedent2.default`
|
|
8540
|
+
Your parent agent is ${agent.parentAgent.name}. If neither the other agents nor
|
|
8541
|
+
you are best for answering the question according to the descriptions, transfer
|
|
8542
|
+
to your parent agent.
|
|
8543
|
+
`;
|
|
8523
8544
|
}
|
|
8524
8545
|
return instructions;
|
|
8525
8546
|
}
|
|
8526
8547
|
function getTransferTargets(agent) {
|
|
8527
|
-
const
|
|
8548
|
+
const targets = [];
|
|
8528
8549
|
if (agent.subAgents && Array.isArray(agent.subAgents)) {
|
|
8529
|
-
|
|
8550
|
+
targets.push(...agent.subAgents);
|
|
8530
8551
|
}
|
|
8531
8552
|
if (!agent.parentAgent || !("subAgents" in agent.parentAgent)) {
|
|
8532
|
-
return
|
|
8553
|
+
return targets;
|
|
8533
8554
|
}
|
|
8534
8555
|
if (!agent.disallowTransferToParent) {
|
|
8535
|
-
|
|
8556
|
+
targets.push(agent.parentAgent);
|
|
8536
8557
|
}
|
|
8537
8558
|
if (!agent.disallowTransferToPeers && agent.parentAgent.subAgents) {
|
|
8538
8559
|
const peerAgents = agent.parentAgent.subAgents.filter(
|
|
8539
8560
|
(peerAgent) => peerAgent.name !== agent.name
|
|
8540
8561
|
);
|
|
8541
|
-
|
|
8562
|
+
targets.push(...peerAgents);
|
|
8542
8563
|
}
|
|
8543
|
-
return
|
|
8564
|
+
return targets;
|
|
8544
8565
|
}
|
|
8545
8566
|
var requestProcessor8 = new AgentTransferLlmRequestProcessor();
|
|
8546
8567
|
|
|
@@ -8642,7 +8663,10 @@ var LlmAgent = (_class26 = class _LlmAgent extends BaseAgent {
|
|
|
8642
8663
|
constructor(config) {
|
|
8643
8664
|
super({
|
|
8644
8665
|
name: config.name,
|
|
8645
|
-
description: config.description
|
|
8666
|
+
description: config.description,
|
|
8667
|
+
subAgents: config.subAgents,
|
|
8668
|
+
beforeAgentCallback: config.beforeAgentCallback,
|
|
8669
|
+
afterAgentCallback: config.afterAgentCallback
|
|
8646
8670
|
});_class26.prototype.__init46.call(this);;
|
|
8647
8671
|
this.model = config.model || "";
|
|
8648
8672
|
this.instruction = config.instruction || "";
|
|
@@ -10119,6 +10143,33 @@ var AgentBuilder = (_class32 = class _AgentBuilder {
|
|
|
10119
10143
|
this.config.outputKey = outputKey;
|
|
10120
10144
|
return this;
|
|
10121
10145
|
}
|
|
10146
|
+
/**
|
|
10147
|
+
* Add sub-agents to the agent
|
|
10148
|
+
* @param subAgents Sub-agents to add to the agent
|
|
10149
|
+
* @returns This builder instance for chaining
|
|
10150
|
+
*/
|
|
10151
|
+
withSubAgents(subAgents) {
|
|
10152
|
+
this.config.subAgents = subAgents;
|
|
10153
|
+
return this;
|
|
10154
|
+
}
|
|
10155
|
+
/**
|
|
10156
|
+
* Set the before agent callback
|
|
10157
|
+
* @param callback Callback to invoke before agent execution
|
|
10158
|
+
* @returns This builder instance for chaining
|
|
10159
|
+
*/
|
|
10160
|
+
withBeforeAgentCallback(callback) {
|
|
10161
|
+
this.config.beforeAgentCallback = callback;
|
|
10162
|
+
return this;
|
|
10163
|
+
}
|
|
10164
|
+
/**
|
|
10165
|
+
* Set the after agent callback
|
|
10166
|
+
* @param callback Callback to invoke after agent execution
|
|
10167
|
+
* @returns This builder instance for chaining
|
|
10168
|
+
*/
|
|
10169
|
+
withAfterAgentCallback(callback) {
|
|
10170
|
+
this.config.afterAgentCallback = callback;
|
|
10171
|
+
return this;
|
|
10172
|
+
}
|
|
10122
10173
|
/**
|
|
10123
10174
|
* Configure as a sequential agent
|
|
10124
10175
|
* @param subAgents Sub-agents to execute in sequence
|
|
@@ -10290,6 +10341,9 @@ var AgentBuilder = (_class32 = class _AgentBuilder {
|
|
|
10290
10341
|
tools: this.config.tools,
|
|
10291
10342
|
planner: this.config.planner,
|
|
10292
10343
|
codeExecutor: this.config.codeExecutor,
|
|
10344
|
+
subAgents: this.config.subAgents,
|
|
10345
|
+
beforeAgentCallback: this.config.beforeAgentCallback,
|
|
10346
|
+
afterAgentCallback: this.config.afterAgentCallback,
|
|
10293
10347
|
memoryService: this.memoryService,
|
|
10294
10348
|
artifactService: this.artifactService,
|
|
10295
10349
|
outputKey: this.config.outputKey,
|
|
@@ -11122,7 +11176,7 @@ var DatabaseSessionService = (_class33 = class extends BaseSessionService {
|
|
|
11122
11176
|
}, _class33);
|
|
11123
11177
|
|
|
11124
11178
|
// src/sessions/database-factories.ts
|
|
11125
|
-
|
|
11179
|
+
|
|
11126
11180
|
|
|
11127
11181
|
function createDependencyError(packageName, dbType) {
|
|
11128
11182
|
return new Error(
|
package/dist/index.mjs
CHANGED
|
@@ -4846,6 +4846,7 @@ var GetUserChoiceTool = class extends BaseTool {
|
|
|
4846
4846
|
// src/tools/common/transfer-to-agent-tool.ts
|
|
4847
4847
|
init_logger();
|
|
4848
4848
|
init_base_tool();
|
|
4849
|
+
import { Type as Type8 } from "@google/genai";
|
|
4849
4850
|
var TransferToAgentTool = class extends BaseTool {
|
|
4850
4851
|
logger = new Logger({ name: "TransferToAgentTool" });
|
|
4851
4852
|
/**
|
|
@@ -4854,9 +4855,28 @@ var TransferToAgentTool = class extends BaseTool {
|
|
|
4854
4855
|
constructor() {
|
|
4855
4856
|
super({
|
|
4856
4857
|
name: "transfer_to_agent",
|
|
4857
|
-
description: "Transfer the question to another agent."
|
|
4858
|
+
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
4859
|
});
|
|
4859
4860
|
}
|
|
4861
|
+
/**
|
|
4862
|
+
* Get the function declaration for the tool
|
|
4863
|
+
*/
|
|
4864
|
+
getDeclaration() {
|
|
4865
|
+
return {
|
|
4866
|
+
name: this.name,
|
|
4867
|
+
description: this.description,
|
|
4868
|
+
parameters: {
|
|
4869
|
+
type: Type8.OBJECT,
|
|
4870
|
+
properties: {
|
|
4871
|
+
agent_name: {
|
|
4872
|
+
type: Type8.STRING,
|
|
4873
|
+
description: "The name of the agent to transfer control to"
|
|
4874
|
+
}
|
|
4875
|
+
},
|
|
4876
|
+
required: ["agent_name"]
|
|
4877
|
+
}
|
|
4878
|
+
};
|
|
4879
|
+
}
|
|
4860
4880
|
/**
|
|
4861
4881
|
* Execute the transfer to agent action
|
|
4862
4882
|
*/
|
|
@@ -4869,7 +4889,7 @@ var TransferToAgentTool = class extends BaseTool {
|
|
|
4869
4889
|
// src/tools/common/load-memory-tool.ts
|
|
4870
4890
|
init_logger();
|
|
4871
4891
|
init_base_tool();
|
|
4872
|
-
import { Type as
|
|
4892
|
+
import { Type as Type9 } from "@google/genai";
|
|
4873
4893
|
var LoadMemoryTool = class extends BaseTool {
|
|
4874
4894
|
logger = new Logger({ name: "LoadMemoryTool" });
|
|
4875
4895
|
/**
|
|
@@ -4889,10 +4909,10 @@ var LoadMemoryTool = class extends BaseTool {
|
|
|
4889
4909
|
name: this.name,
|
|
4890
4910
|
description: this.description,
|
|
4891
4911
|
parameters: {
|
|
4892
|
-
type:
|
|
4912
|
+
type: Type9.OBJECT,
|
|
4893
4913
|
properties: {
|
|
4894
4914
|
query: {
|
|
4895
|
-
type:
|
|
4915
|
+
type: Type9.STRING,
|
|
4896
4916
|
description: "The query to load memories for"
|
|
4897
4917
|
}
|
|
4898
4918
|
},
|
|
@@ -4923,7 +4943,7 @@ var LoadMemoryTool = class extends BaseTool {
|
|
|
4923
4943
|
|
|
4924
4944
|
// src/tools/common/load-artifacts-tool.ts
|
|
4925
4945
|
init_base_tool();
|
|
4926
|
-
import { Type as
|
|
4946
|
+
import { Type as Type10 } from "@google/genai";
|
|
4927
4947
|
var LoadArtifactsTool = class extends BaseTool {
|
|
4928
4948
|
constructor() {
|
|
4929
4949
|
super({
|
|
@@ -4939,12 +4959,12 @@ var LoadArtifactsTool = class extends BaseTool {
|
|
|
4939
4959
|
name: this.name,
|
|
4940
4960
|
description: this.description,
|
|
4941
4961
|
parameters: {
|
|
4942
|
-
type:
|
|
4962
|
+
type: Type10.OBJECT,
|
|
4943
4963
|
properties: {
|
|
4944
4964
|
artifact_names: {
|
|
4945
|
-
type:
|
|
4965
|
+
type: Type10.ARRAY,
|
|
4946
4966
|
items: {
|
|
4947
|
-
type:
|
|
4967
|
+
type: Type10.STRING
|
|
4948
4968
|
},
|
|
4949
4969
|
description: "List of artifact names to load"
|
|
4950
4970
|
}
|
|
@@ -5563,7 +5583,7 @@ init_logger();
|
|
|
5563
5583
|
init_base_tool();
|
|
5564
5584
|
|
|
5565
5585
|
// src/tools/mcp/schema-conversion.ts
|
|
5566
|
-
import { Type as
|
|
5586
|
+
import { Type as Type11 } from "@google/genai";
|
|
5567
5587
|
function adkToMcpToolType(tool) {
|
|
5568
5588
|
const declaration = tool.getDeclaration();
|
|
5569
5589
|
const params = declarationToJsonSchema(declaration);
|
|
@@ -5592,13 +5612,13 @@ function jsonSchemaToDeclaration(name, description, schema) {
|
|
|
5592
5612
|
parameters = schema;
|
|
5593
5613
|
} else {
|
|
5594
5614
|
parameters = {
|
|
5595
|
-
type:
|
|
5615
|
+
type: Type11.OBJECT,
|
|
5596
5616
|
properties: schema
|
|
5597
5617
|
};
|
|
5598
5618
|
}
|
|
5599
5619
|
} else {
|
|
5600
5620
|
parameters = {
|
|
5601
|
-
type:
|
|
5621
|
+
type: Type11.OBJECT,
|
|
5602
5622
|
properties: {}
|
|
5603
5623
|
};
|
|
5604
5624
|
}
|
|
@@ -5610,7 +5630,7 @@ function jsonSchemaToDeclaration(name, description, schema) {
|
|
|
5610
5630
|
}
|
|
5611
5631
|
function normalizeJsonSchema(schema) {
|
|
5612
5632
|
if (!schema) {
|
|
5613
|
-
return { type:
|
|
5633
|
+
return { type: Type11.OBJECT, properties: {} };
|
|
5614
5634
|
}
|
|
5615
5635
|
const normalizedSchema = { ...schema };
|
|
5616
5636
|
if (!normalizedSchema.type) {
|
|
@@ -5627,39 +5647,39 @@ function normalizeJsonSchema(schema) {
|
|
|
5627
5647
|
case "integer":
|
|
5628
5648
|
return normalizeNumberSchema(normalizedSchema);
|
|
5629
5649
|
case "boolean":
|
|
5630
|
-
return { type:
|
|
5650
|
+
return { type: Type11.BOOLEAN };
|
|
5631
5651
|
case "null":
|
|
5632
|
-
return { type:
|
|
5652
|
+
return { type: Type11.NULL };
|
|
5633
5653
|
default:
|
|
5634
5654
|
return normalizedSchema;
|
|
5635
5655
|
}
|
|
5636
5656
|
}
|
|
5637
5657
|
function determineSchemaType(schema) {
|
|
5638
5658
|
if (schema.properties || schema.required || schema.additionalProperties !== void 0) {
|
|
5639
|
-
return
|
|
5659
|
+
return Type11.OBJECT;
|
|
5640
5660
|
}
|
|
5641
5661
|
if (schema.items) {
|
|
5642
|
-
return
|
|
5662
|
+
return Type11.ARRAY;
|
|
5643
5663
|
}
|
|
5644
5664
|
if (schema.enum !== void 0) {
|
|
5645
|
-
if (schema.enum.length === 0) return
|
|
5665
|
+
if (schema.enum.length === 0) return Type11.STRING;
|
|
5646
5666
|
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
|
|
5667
|
+
if (typeof firstItem === "string") return Type11.STRING;
|
|
5668
|
+
if (typeof firstItem === "number") return Type11.NUMBER;
|
|
5669
|
+
if (typeof firstItem === "boolean") return Type11.BOOLEAN;
|
|
5670
|
+
return Type11.STRING;
|
|
5651
5671
|
}
|
|
5652
5672
|
if (schema.minLength !== void 0 || schema.maxLength !== void 0 || schema.pattern) {
|
|
5653
|
-
return
|
|
5673
|
+
return Type11.STRING;
|
|
5654
5674
|
}
|
|
5655
5675
|
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 ?
|
|
5676
|
+
return schema.multipleOf === void 0 || schema.multipleOf % 1 === 0 ? Type11.INTEGER : Type11.NUMBER;
|
|
5657
5677
|
}
|
|
5658
|
-
return
|
|
5678
|
+
return Type11.OBJECT;
|
|
5659
5679
|
}
|
|
5660
5680
|
function normalizeObjectSchema(schema) {
|
|
5661
5681
|
const normalizedSchema = {
|
|
5662
|
-
type:
|
|
5682
|
+
type: Type11.OBJECT,
|
|
5663
5683
|
properties: {}
|
|
5664
5684
|
};
|
|
5665
5685
|
if (schema.properties) {
|
|
@@ -5677,7 +5697,7 @@ function normalizeObjectSchema(schema) {
|
|
|
5677
5697
|
}
|
|
5678
5698
|
function normalizeArraySchema(schema) {
|
|
5679
5699
|
const normalizedSchema = {
|
|
5680
|
-
type:
|
|
5700
|
+
type: Type11.ARRAY
|
|
5681
5701
|
};
|
|
5682
5702
|
if (schema.items) {
|
|
5683
5703
|
normalizedSchema.items = normalizeJsonSchema(
|
|
@@ -5694,7 +5714,7 @@ function normalizeArraySchema(schema) {
|
|
|
5694
5714
|
}
|
|
5695
5715
|
function normalizeStringSchema(schema) {
|
|
5696
5716
|
const normalizedSchema = {
|
|
5697
|
-
type:
|
|
5717
|
+
type: Type11.STRING
|
|
5698
5718
|
};
|
|
5699
5719
|
if (schema.minLength !== void 0)
|
|
5700
5720
|
normalizedSchema.minLength = schema.minLength;
|
|
@@ -5727,7 +5747,7 @@ function mcpSchemaToParameters(mcpTool) {
|
|
|
5727
5747
|
}
|
|
5728
5748
|
if (!schema) {
|
|
5729
5749
|
return {
|
|
5730
|
-
type:
|
|
5750
|
+
type: Type11.OBJECT,
|
|
5731
5751
|
properties: {}
|
|
5732
5752
|
};
|
|
5733
5753
|
}
|
|
@@ -8464,12 +8484,12 @@ var SingleFlow = class extends BaseLlmFlow {
|
|
|
8464
8484
|
};
|
|
8465
8485
|
|
|
8466
8486
|
// src/flows/llm-flows/agent-transfer.ts
|
|
8487
|
+
import dedent from "dedent";
|
|
8467
8488
|
var AgentTransferLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
8468
8489
|
/**
|
|
8469
8490
|
* Processes agent transfer by adding transfer instructions and tools
|
|
8470
8491
|
* if the agent has transfer targets available
|
|
8471
8492
|
*/
|
|
8472
|
-
// eslint-disable-next-line @typescript-eslint/require-yield
|
|
8473
8493
|
async *runAsync(invocationContext, llmRequest) {
|
|
8474
8494
|
const agent = invocationContext.agent;
|
|
8475
8495
|
if (!("subAgents" in agent) || typeof agent.subAgents !== "object") {
|
|
@@ -8487,60 +8507,61 @@ var AgentTransferLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
8487
8507
|
const transferToAgentTool = new TransferToAgentTool();
|
|
8488
8508
|
const toolContext = new ToolContext(invocationContext);
|
|
8489
8509
|
await transferToAgentTool.processLlmRequest(toolContext, llmRequest);
|
|
8490
|
-
|
|
8491
|
-
|
|
8510
|
+
const shouldYield = false;
|
|
8511
|
+
if (shouldYield) {
|
|
8512
|
+
yield {};
|
|
8492
8513
|
}
|
|
8493
8514
|
}
|
|
8494
8515
|
};
|
|
8495
8516
|
function buildTargetAgentsInfo(targetAgent) {
|
|
8496
|
-
return `
|
|
8497
|
-
Agent name: ${targetAgent.name}
|
|
8498
|
-
Agent description: ${targetAgent.description}
|
|
8499
|
-
`;
|
|
8517
|
+
return dedent`
|
|
8518
|
+
Agent name: ${targetAgent.name}
|
|
8519
|
+
Agent description: ${targetAgent.description}
|
|
8520
|
+
`;
|
|
8500
8521
|
}
|
|
8501
8522
|
function buildTargetAgentsInstructions(agent, targetAgents) {
|
|
8502
8523
|
const lineBreak = "\n";
|
|
8503
8524
|
const transferFunctionName = "transfer_to_agent";
|
|
8504
|
-
let instructions = `
|
|
8505
|
-
You have a list of other agents to transfer to:
|
|
8525
|
+
let instructions = dedent`
|
|
8526
|
+
You have a list of other agents to transfer to:
|
|
8506
8527
|
|
|
8507
|
-
${targetAgents.map((targetAgent) => buildTargetAgentsInfo(targetAgent)).join(lineBreak)}
|
|
8528
|
+
${targetAgents.map((targetAgent) => buildTargetAgentsInfo(targetAgent)).join(lineBreak)}
|
|
8508
8529
|
|
|
8509
|
-
If you are the best to answer the question according to your description, you
|
|
8510
|
-
can answer it.
|
|
8530
|
+
If you are the best to answer the question according to your description, you
|
|
8531
|
+
can answer it.
|
|
8511
8532
|
|
|
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.
|
|
8533
|
+
If another agent is better for answering the question according to its
|
|
8534
|
+
description, call \`${transferFunctionName}\` function to transfer the
|
|
8535
|
+
question to that agent. When transferring, do not generate any text other than
|
|
8536
|
+
the function call.
|
|
8516
8537
|
`;
|
|
8517
8538
|
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
|
-
`;
|
|
8539
|
+
instructions += dedent`
|
|
8540
|
+
Your parent agent is ${agent.parentAgent.name}. If neither the other agents nor
|
|
8541
|
+
you are best for answering the question according to the descriptions, transfer
|
|
8542
|
+
to your parent agent.
|
|
8543
|
+
`;
|
|
8523
8544
|
}
|
|
8524
8545
|
return instructions;
|
|
8525
8546
|
}
|
|
8526
8547
|
function getTransferTargets(agent) {
|
|
8527
|
-
const
|
|
8548
|
+
const targets = [];
|
|
8528
8549
|
if (agent.subAgents && Array.isArray(agent.subAgents)) {
|
|
8529
|
-
|
|
8550
|
+
targets.push(...agent.subAgents);
|
|
8530
8551
|
}
|
|
8531
8552
|
if (!agent.parentAgent || !("subAgents" in agent.parentAgent)) {
|
|
8532
|
-
return
|
|
8553
|
+
return targets;
|
|
8533
8554
|
}
|
|
8534
8555
|
if (!agent.disallowTransferToParent) {
|
|
8535
|
-
|
|
8556
|
+
targets.push(agent.parentAgent);
|
|
8536
8557
|
}
|
|
8537
8558
|
if (!agent.disallowTransferToPeers && agent.parentAgent.subAgents) {
|
|
8538
8559
|
const peerAgents = agent.parentAgent.subAgents.filter(
|
|
8539
8560
|
(peerAgent) => peerAgent.name !== agent.name
|
|
8540
8561
|
);
|
|
8541
|
-
|
|
8562
|
+
targets.push(...peerAgents);
|
|
8542
8563
|
}
|
|
8543
|
-
return
|
|
8564
|
+
return targets;
|
|
8544
8565
|
}
|
|
8545
8566
|
var requestProcessor8 = new AgentTransferLlmRequestProcessor();
|
|
8546
8567
|
|
|
@@ -8642,7 +8663,10 @@ var LlmAgent = class _LlmAgent extends BaseAgent {
|
|
|
8642
8663
|
constructor(config) {
|
|
8643
8664
|
super({
|
|
8644
8665
|
name: config.name,
|
|
8645
|
-
description: config.description
|
|
8666
|
+
description: config.description,
|
|
8667
|
+
subAgents: config.subAgents,
|
|
8668
|
+
beforeAgentCallback: config.beforeAgentCallback,
|
|
8669
|
+
afterAgentCallback: config.afterAgentCallback
|
|
8646
8670
|
});
|
|
8647
8671
|
this.model = config.model || "";
|
|
8648
8672
|
this.instruction = config.instruction || "";
|
|
@@ -10119,6 +10143,33 @@ var AgentBuilder = class _AgentBuilder {
|
|
|
10119
10143
|
this.config.outputKey = outputKey;
|
|
10120
10144
|
return this;
|
|
10121
10145
|
}
|
|
10146
|
+
/**
|
|
10147
|
+
* Add sub-agents to the agent
|
|
10148
|
+
* @param subAgents Sub-agents to add to the agent
|
|
10149
|
+
* @returns This builder instance for chaining
|
|
10150
|
+
*/
|
|
10151
|
+
withSubAgents(subAgents) {
|
|
10152
|
+
this.config.subAgents = subAgents;
|
|
10153
|
+
return this;
|
|
10154
|
+
}
|
|
10155
|
+
/**
|
|
10156
|
+
* Set the before agent callback
|
|
10157
|
+
* @param callback Callback to invoke before agent execution
|
|
10158
|
+
* @returns This builder instance for chaining
|
|
10159
|
+
*/
|
|
10160
|
+
withBeforeAgentCallback(callback) {
|
|
10161
|
+
this.config.beforeAgentCallback = callback;
|
|
10162
|
+
return this;
|
|
10163
|
+
}
|
|
10164
|
+
/**
|
|
10165
|
+
* Set the after agent callback
|
|
10166
|
+
* @param callback Callback to invoke after agent execution
|
|
10167
|
+
* @returns This builder instance for chaining
|
|
10168
|
+
*/
|
|
10169
|
+
withAfterAgentCallback(callback) {
|
|
10170
|
+
this.config.afterAgentCallback = callback;
|
|
10171
|
+
return this;
|
|
10172
|
+
}
|
|
10122
10173
|
/**
|
|
10123
10174
|
* Configure as a sequential agent
|
|
10124
10175
|
* @param subAgents Sub-agents to execute in sequence
|
|
@@ -10290,6 +10341,9 @@ var AgentBuilder = class _AgentBuilder {
|
|
|
10290
10341
|
tools: this.config.tools,
|
|
10291
10342
|
planner: this.config.planner,
|
|
10292
10343
|
codeExecutor: this.config.codeExecutor,
|
|
10344
|
+
subAgents: this.config.subAgents,
|
|
10345
|
+
beforeAgentCallback: this.config.beforeAgentCallback,
|
|
10346
|
+
afterAgentCallback: this.config.afterAgentCallback,
|
|
10293
10347
|
memoryService: this.memoryService,
|
|
10294
10348
|
artifactService: this.artifactService,
|
|
10295
10349
|
outputKey: this.config.outputKey,
|
|
@@ -11122,11 +11176,11 @@ var DatabaseSessionService = class extends BaseSessionService {
|
|
|
11122
11176
|
};
|
|
11123
11177
|
|
|
11124
11178
|
// src/sessions/database-factories.ts
|
|
11125
|
-
import
|
|
11179
|
+
import dedent2 from "dedent";
|
|
11126
11180
|
import { Kysely, MysqlDialect, PostgresDialect, SqliteDialect } from "kysely";
|
|
11127
11181
|
function createDependencyError(packageName, dbType) {
|
|
11128
11182
|
return new Error(
|
|
11129
|
-
|
|
11183
|
+
dedent2`
|
|
11130
11184
|
Missing required peer dependency: ${packageName}
|
|
11131
11185
|
To use ${dbType} sessions, install the required package:
|
|
11132
11186
|
npm install ${packageName}
|