@iqai/adk 0.1.5 → 0.1.7
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/README.md +113 -20
- package/dist/index.d.mts +189 -127
- package/dist/index.d.ts +189 -127
- package/dist/index.js +96 -46
- package/dist/index.mjs +95 -45
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -674,6 +674,8 @@ __export(agents_exports, {
|
|
|
674
674
|
RunConfig: () => RunConfig,
|
|
675
675
|
SequentialAgent: () => SequentialAgent,
|
|
676
676
|
StreamingMode: () => StreamingMode,
|
|
677
|
+
createBranchContextForSubAgent: () => createBranchContextForSubAgent,
|
|
678
|
+
mergeAgentRun: () => mergeAgentRun,
|
|
677
679
|
newInvocationContextId: () => newInvocationContextId
|
|
678
680
|
});
|
|
679
681
|
|
|
@@ -3698,6 +3700,7 @@ __export(tools_exports, {
|
|
|
3698
3700
|
McpAbi: () => McpAbi,
|
|
3699
3701
|
McpAtp: () => McpAtp,
|
|
3700
3702
|
McpBamm: () => McpBamm,
|
|
3703
|
+
McpCoinGecko: () => McpCoinGecko,
|
|
3701
3704
|
McpError: () => McpError,
|
|
3702
3705
|
McpErrorType: () => McpErrorType,
|
|
3703
3706
|
McpFilesystem: () => McpFilesystem,
|
|
@@ -5470,6 +5473,14 @@ function McpTelegram(config = {}) {
|
|
|
5470
5473
|
);
|
|
5471
5474
|
return new McpToolset(mcpConfig);
|
|
5472
5475
|
}
|
|
5476
|
+
function McpCoinGecko(config = {}) {
|
|
5477
|
+
const mcpConfig = createMcpConfig(
|
|
5478
|
+
"CoinGecko MCP Client",
|
|
5479
|
+
"@coingecko/coingecko-mcp",
|
|
5480
|
+
config
|
|
5481
|
+
);
|
|
5482
|
+
return new McpToolset(mcpConfig);
|
|
5483
|
+
}
|
|
5473
5484
|
function McpFilesystem(config = {}) {
|
|
5474
5485
|
const mcpConfig = createMcpConfig(
|
|
5475
5486
|
"Filesystem MCP Client",
|
|
@@ -8861,6 +8872,9 @@ var LangGraphAgent = (_class26 = class extends BaseAgent {
|
|
|
8861
8872
|
}
|
|
8862
8873
|
}, _class26);
|
|
8863
8874
|
|
|
8875
|
+
// src/agents/agent-builder.ts
|
|
8876
|
+
|
|
8877
|
+
|
|
8864
8878
|
// src/runners.ts
|
|
8865
8879
|
|
|
8866
8880
|
|
|
@@ -9803,10 +9817,10 @@ var AgentBuilder = (_class31 = class _AgentBuilder {
|
|
|
9803
9817
|
return this;
|
|
9804
9818
|
}
|
|
9805
9819
|
/**
|
|
9806
|
-
* Configure session management
|
|
9820
|
+
* Configure session management with optional smart defaults
|
|
9807
9821
|
* @param service Session service to use
|
|
9808
|
-
* @param userId User identifier
|
|
9809
|
-
* @param appName Application name
|
|
9822
|
+
* @param userId User identifier (optional, defaults to agent-based ID)
|
|
9823
|
+
* @param appName Application name (optional, defaults to agent-based name)
|
|
9810
9824
|
* @param memoryService Optional memory service
|
|
9811
9825
|
* @param artifactService Optional artifact service
|
|
9812
9826
|
* @returns This builder instance for chaining
|
|
@@ -9814,17 +9828,18 @@ var AgentBuilder = (_class31 = class _AgentBuilder {
|
|
|
9814
9828
|
withSession(service, userId, appName, memoryService, artifactService) {
|
|
9815
9829
|
this.sessionConfig = {
|
|
9816
9830
|
service,
|
|
9817
|
-
userId,
|
|
9818
|
-
appName,
|
|
9831
|
+
userId: userId || this.generateDefaultUserId(),
|
|
9832
|
+
appName: appName || this.generateDefaultAppName(),
|
|
9819
9833
|
memoryService,
|
|
9820
9834
|
artifactService
|
|
9821
9835
|
};
|
|
9822
9836
|
return this;
|
|
9823
9837
|
}
|
|
9824
9838
|
/**
|
|
9825
|
-
* Configure with an in-memory session
|
|
9826
|
-
*
|
|
9827
|
-
* @param
|
|
9839
|
+
* Configure with an in-memory session with custom IDs
|
|
9840
|
+
* Note: In-memory sessions are created automatically by default, use this only if you need custom appName/userId
|
|
9841
|
+
* @param appName Application name (optional, defaults to agent-based name)
|
|
9842
|
+
* @param userId User identifier (optional, defaults to agent-based ID)
|
|
9828
9843
|
* @returns This builder instance for chaining
|
|
9829
9844
|
*/
|
|
9830
9845
|
withQuickSession(appName, userId) {
|
|
@@ -9838,6 +9853,9 @@ var AgentBuilder = (_class31 = class _AgentBuilder {
|
|
|
9838
9853
|
const agent = this.createAgent();
|
|
9839
9854
|
let runner;
|
|
9840
9855
|
let session;
|
|
9856
|
+
if (!this.sessionConfig) {
|
|
9857
|
+
this.withQuickSession();
|
|
9858
|
+
}
|
|
9841
9859
|
if (this.sessionConfig) {
|
|
9842
9860
|
session = await this.sessionConfig.service.createSession(
|
|
9843
9861
|
this.sessionConfig.appName,
|
|
@@ -9846,49 +9864,26 @@ var AgentBuilder = (_class31 = class _AgentBuilder {
|
|
|
9846
9864
|
const runnerConfig = {
|
|
9847
9865
|
appName: this.sessionConfig.appName,
|
|
9848
9866
|
agent,
|
|
9849
|
-
sessionService: this.sessionConfig.service
|
|
9867
|
+
sessionService: this.sessionConfig.service,
|
|
9868
|
+
memoryService: this.sessionConfig.memoryService,
|
|
9869
|
+
artifactService: this.sessionConfig.artifactService
|
|
9850
9870
|
};
|
|
9851
|
-
|
|
9852
|
-
|
|
9853
|
-
}
|
|
9854
|
-
if (this.sessionConfig.artifactService) {
|
|
9855
|
-
runnerConfig.artifactService = this.sessionConfig.artifactService;
|
|
9856
|
-
}
|
|
9857
|
-
runner = new Runner(runnerConfig);
|
|
9871
|
+
const baseRunner = new Runner(runnerConfig);
|
|
9872
|
+
runner = this.createEnhancedRunner(baseRunner, session);
|
|
9858
9873
|
}
|
|
9859
9874
|
return { agent, runner, session };
|
|
9860
9875
|
}
|
|
9861
9876
|
/**
|
|
9862
9877
|
* Quick execution helper - build and run a message
|
|
9863
|
-
* @param message Message to send to the agent
|
|
9878
|
+
* @param message Message to send to the agent (string or full message object)
|
|
9864
9879
|
* @returns Agent response
|
|
9865
9880
|
*/
|
|
9866
9881
|
async ask(message) {
|
|
9867
|
-
|
|
9868
|
-
|
|
9869
|
-
|
|
9870
|
-
this.withQuickSession(appName, userId);
|
|
9871
|
-
}
|
|
9872
|
-
const { runner, session } = await this.build();
|
|
9873
|
-
if (!runner || !session) {
|
|
9874
|
-
throw new Error("Failed to create runner and session");
|
|
9875
|
-
}
|
|
9876
|
-
let response = "";
|
|
9877
|
-
for await (const event of runner.runAsync({
|
|
9878
|
-
userId: this.sessionConfig.userId,
|
|
9879
|
-
sessionId: session.id,
|
|
9880
|
-
newMessage: {
|
|
9881
|
-
parts: [{ text: message }]
|
|
9882
|
-
}
|
|
9883
|
-
})) {
|
|
9884
|
-
if (_optionalChain([event, 'access', _273 => _273.content, 'optionalAccess', _274 => _274.parts])) {
|
|
9885
|
-
const content = event.content.parts.map((part) => part.text || "").join("");
|
|
9886
|
-
if (content) {
|
|
9887
|
-
response += content;
|
|
9888
|
-
}
|
|
9889
|
-
}
|
|
9882
|
+
const { runner } = await this.build();
|
|
9883
|
+
if (!runner) {
|
|
9884
|
+
throw new Error("Failed to create runner");
|
|
9890
9885
|
}
|
|
9891
|
-
return
|
|
9886
|
+
return runner.ask(message);
|
|
9892
9887
|
}
|
|
9893
9888
|
/**
|
|
9894
9889
|
* Create the appropriate agent type based on configuration
|
|
@@ -9911,7 +9906,7 @@ var AgentBuilder = (_class31 = class _AgentBuilder {
|
|
|
9911
9906
|
});
|
|
9912
9907
|
}
|
|
9913
9908
|
case "sequential":
|
|
9914
|
-
if (!this.config.subAgents) {
|
|
9909
|
+
if (!this.config.subAgents || !Array.isArray(this.config.subAgents) || this.config.subAgents.length === 0) {
|
|
9915
9910
|
throw new Error("Sub-agents required for sequential agent");
|
|
9916
9911
|
}
|
|
9917
9912
|
return new SequentialAgent({
|
|
@@ -9920,7 +9915,7 @@ var AgentBuilder = (_class31 = class _AgentBuilder {
|
|
|
9920
9915
|
subAgents: this.config.subAgents
|
|
9921
9916
|
});
|
|
9922
9917
|
case "parallel":
|
|
9923
|
-
if (!this.config.subAgents) {
|
|
9918
|
+
if (!this.config.subAgents || !Array.isArray(this.config.subAgents) || this.config.subAgents.length === 0) {
|
|
9924
9919
|
throw new Error("Sub-agents required for parallel agent");
|
|
9925
9920
|
}
|
|
9926
9921
|
return new ParallelAgent({
|
|
@@ -9929,7 +9924,7 @@ var AgentBuilder = (_class31 = class _AgentBuilder {
|
|
|
9929
9924
|
subAgents: this.config.subAgents
|
|
9930
9925
|
});
|
|
9931
9926
|
case "loop":
|
|
9932
|
-
if (!this.config.subAgents) {
|
|
9927
|
+
if (!this.config.subAgents || !Array.isArray(this.config.subAgents) || this.config.subAgents.length === 0) {
|
|
9933
9928
|
throw new Error("Sub-agents required for loop agent");
|
|
9934
9929
|
}
|
|
9935
9930
|
return new LoopAgent({
|
|
@@ -9939,7 +9934,7 @@ var AgentBuilder = (_class31 = class _AgentBuilder {
|
|
|
9939
9934
|
maxIterations: this.config.maxIterations || 3
|
|
9940
9935
|
});
|
|
9941
9936
|
case "langgraph":
|
|
9942
|
-
if (!this.config.nodes || !this.config.rootNode) {
|
|
9937
|
+
if (!this.config.nodes || !Array.isArray(this.config.nodes) || this.config.nodes.length === 0 || !this.config.rootNode || typeof this.config.rootNode !== "string") {
|
|
9943
9938
|
throw new Error("Nodes and root node required for LangGraph agent");
|
|
9944
9939
|
}
|
|
9945
9940
|
return new LangGraphAgent({
|
|
@@ -9950,6 +9945,57 @@ var AgentBuilder = (_class31 = class _AgentBuilder {
|
|
|
9950
9945
|
});
|
|
9951
9946
|
}
|
|
9952
9947
|
}
|
|
9948
|
+
/**
|
|
9949
|
+
* Generate default user ID based on agent name and id
|
|
9950
|
+
* @returns Generated user ID
|
|
9951
|
+
*/
|
|
9952
|
+
generateDefaultUserId() {
|
|
9953
|
+
const id = _ai.generateId.call(void 0, );
|
|
9954
|
+
return `user-${this.config.name}-${id}`;
|
|
9955
|
+
}
|
|
9956
|
+
/**
|
|
9957
|
+
* Generate default app name based on agent name
|
|
9958
|
+
* @returns Generated app name
|
|
9959
|
+
*/
|
|
9960
|
+
generateDefaultAppName() {
|
|
9961
|
+
return `app-${this.config.name}`;
|
|
9962
|
+
}
|
|
9963
|
+
/**
|
|
9964
|
+
* Create enhanced runner with simplified API
|
|
9965
|
+
* @param baseRunner The base runner instance
|
|
9966
|
+
* @param session The session instance
|
|
9967
|
+
* @returns Enhanced runner with simplified API
|
|
9968
|
+
*/
|
|
9969
|
+
createEnhancedRunner(baseRunner, session) {
|
|
9970
|
+
const sessionConfig = this.sessionConfig;
|
|
9971
|
+
return {
|
|
9972
|
+
async ask(message) {
|
|
9973
|
+
const fullMessage = typeof message === "string" ? { parts: [{ text: message }] } : message;
|
|
9974
|
+
let response = "";
|
|
9975
|
+
if (!sessionConfig) {
|
|
9976
|
+
throw new Error("Session configuration is required");
|
|
9977
|
+
}
|
|
9978
|
+
for await (const event of baseRunner.runAsync({
|
|
9979
|
+
userId: sessionConfig.userId,
|
|
9980
|
+
sessionId: session.id,
|
|
9981
|
+
newMessage: fullMessage
|
|
9982
|
+
})) {
|
|
9983
|
+
if (_optionalChain([event, 'access', _273 => _273.content, 'optionalAccess', _274 => _274.parts]) && Array.isArray(event.content.parts)) {
|
|
9984
|
+
const content = event.content.parts.map(
|
|
9985
|
+
(part) => (part && typeof part === "object" && "text" in part ? part.text : "") || ""
|
|
9986
|
+
).join("");
|
|
9987
|
+
if (content) {
|
|
9988
|
+
response += content;
|
|
9989
|
+
}
|
|
9990
|
+
}
|
|
9991
|
+
}
|
|
9992
|
+
return response;
|
|
9993
|
+
},
|
|
9994
|
+
runAsync(params) {
|
|
9995
|
+
return baseRunner.runAsync(params);
|
|
9996
|
+
}
|
|
9997
|
+
};
|
|
9998
|
+
}
|
|
9953
9999
|
}, _class31);
|
|
9954
10000
|
|
|
9955
10001
|
// src/memory/index.ts
|
|
@@ -11083,4 +11129,8 @@ var VERSION = "0.1.0";
|
|
|
11083
11129
|
|
|
11084
11130
|
|
|
11085
11131
|
|
|
11086
|
-
|
|
11132
|
+
|
|
11133
|
+
|
|
11134
|
+
|
|
11135
|
+
|
|
11136
|
+
exports.AF_FUNCTION_CALL_ID_PREFIX = AF_FUNCTION_CALL_ID_PREFIX; exports.Agent = LlmAgent; exports.AgentBuilder = AgentBuilder; exports.Agents = agents_exports; exports.AiSdkLlm = AiSdkLlm; exports.AnthropicLlm = AnthropicLlm; exports.ApiKeyCredential = ApiKeyCredential; exports.ApiKeyScheme = ApiKeyScheme; exports.AuthConfig = AuthConfig; exports.AuthCredential = AuthCredential; exports.AuthCredentialType = AuthCredentialType; exports.AuthHandler = AuthHandler; exports.AuthScheme = AuthScheme; exports.AuthSchemeType = AuthSchemeType; exports.AuthTool = AuthTool; exports.AutoFlow = AutoFlow; exports.BaseAgent = BaseAgent; exports.BaseCodeExecutor = BaseCodeExecutor; exports.BaseLLMConnection = BaseLLMConnection; exports.BaseLlm = BaseLlm; exports.BaseLlmFlow = BaseLlmFlow; exports.BaseLlmRequestProcessor = BaseLlmRequestProcessor; exports.BaseLlmResponseProcessor = BaseLlmResponseProcessor; exports.BasePlanner = BasePlanner; exports.BaseSessionService = BaseSessionService; exports.BaseTool = BaseTool; exports.BasicAuthCredential = BasicAuthCredential; exports.BearerTokenCredential = BearerTokenCredential; exports.BuiltInCodeExecutor = BuiltInCodeExecutor; exports.BuiltInPlanner = BuiltInPlanner; exports.CallbackContext = CallbackContext; exports.CodeExecutionUtils = CodeExecutionUtils; exports.CodeExecutorContext = CodeExecutorContext; exports.DatabaseSessionService = DatabaseSessionService; exports.EnhancedAuthConfig = EnhancedAuthConfig; exports.Event = Event; exports.EventActions = EventActions; exports.Events = events_exports; exports.ExitLoopTool = ExitLoopTool; exports.FileOperationsTool = FileOperationsTool; exports.Flows = flows_exports; exports.FunctionTool = FunctionTool; exports.GcsArtifactService = GcsArtifactService; exports.GetUserChoiceTool = GetUserChoiceTool; exports.GoogleLlm = GoogleLlm; exports.GoogleSearch = GoogleSearch; exports.HttpRequestTool = HttpRequestTool; exports.HttpScheme = HttpScheme; exports.InMemoryArtifactService = InMemoryArtifactService; exports.InMemoryMemoryService = InMemoryMemoryService; exports.InMemoryRunner = InMemoryRunner; exports.InMemorySessionService = InMemorySessionService; exports.InvocationContext = InvocationContext; exports.LLMRegistry = LLMRegistry; exports.LangGraphAgent = LangGraphAgent; exports.LlmAgent = LlmAgent; exports.LlmCallsLimitExceededError = LlmCallsLimitExceededError; exports.LlmRequest = LlmRequest; exports.LlmResponse = LlmResponse; exports.LoadArtifactsTool = LoadArtifactsTool; exports.LoadMemoryTool = LoadMemoryTool; exports.LoopAgent = LoopAgent; exports.McpAbi = McpAbi; exports.McpAtp = McpAtp; exports.McpBamm = McpBamm; exports.McpCoinGecko = McpCoinGecko; exports.McpError = McpError; exports.McpErrorType = McpErrorType; exports.McpFilesystem = McpFilesystem; exports.McpFraxlend = McpFraxlend; exports.McpGeneric = McpGeneric; exports.McpIqWiki = McpIqWiki; exports.McpMemory = McpMemory; exports.McpNearAgent = McpNearAgent; exports.McpNearIntentSwaps = McpNearIntentSwaps; exports.McpOdos = McpOdos; exports.McpSamplingHandler = McpSamplingHandler; exports.McpTelegram = McpTelegram; exports.McpToolset = McpToolset; exports.Memory = memory_exports; exports.Models = models_exports; exports.OAuth2Credential = OAuth2Credential; exports.OAuth2Scheme = OAuth2Scheme; exports.OpenAiLlm = OpenAiLlm; exports.OpenIdConnectScheme = OpenIdConnectScheme; exports.ParallelAgent = ParallelAgent; exports.PlanReActPlanner = PlanReActPlanner; exports.REQUEST_EUC_FUNCTION_CALL_NAME = REQUEST_EUC_FUNCTION_CALL_NAME; exports.ReadonlyContext = ReadonlyContext; exports.RunConfig = RunConfig; exports.Runner = Runner; exports.SequentialAgent = SequentialAgent; exports.Sessions = sessions_exports; exports.SingleFlow = SingleFlow; exports.State = State; exports.StreamingMode = StreamingMode; exports.TelemetryService = TelemetryService; exports.ToolContext = ToolContext; exports.Tools = tools_exports; exports.TransferToAgentTool = TransferToAgentTool; exports.UserInteractionTool = UserInteractionTool; exports.VERSION = VERSION; exports.VertexAiSessionService = VertexAiSessionService; exports._findFunctionCallEventIfLastEventIsFunctionResponse = _findFunctionCallEventIfLastEventIsFunctionResponse; exports.adkToMcpToolType = adkToMcpToolType; exports.agentTransferRequestProcessor = requestProcessor8; exports.basicRequestProcessor = requestProcessor2; exports.buildFunctionDeclaration = buildFunctionDeclaration; exports.codeExecutionRequestProcessor = requestProcessor3; exports.codeExecutionResponseProcessor = responseProcessor; exports.contentRequestProcessor = requestProcessor4; exports.createAuthToolArguments = createAuthToolArguments; exports.createBranchContextForSubAgent = createBranchContextForSubAgent; exports.createDatabaseSessionService = createDatabaseSessionService; exports.createFunctionTool = createFunctionTool; exports.createMysqlSessionService = createMysqlSessionService; exports.createPostgresSessionService = createPostgresSessionService; exports.createSamplingHandler = createSamplingHandler; exports.createSqliteSessionService = createSqliteSessionService; exports.generateAuthEvent = generateAuthEvent; exports.generateClientFunctionCallId = generateClientFunctionCallId; exports.getLongRunningFunctionCalls = getLongRunningFunctionCalls; exports.getMcpTools = getMcpTools; exports.handleFunctionCallsAsync = handleFunctionCallsAsync; exports.handleFunctionCallsLive = handleFunctionCallsLive; exports.identityRequestProcessor = requestProcessor5; exports.initializeTelemetry = initializeTelemetry; exports.injectSessionState = injectSessionState; exports.instructionsRequestProcessor = requestProcessor6; exports.isEnhancedAuthConfig = isEnhancedAuthConfig; exports.jsonSchemaToDeclaration = jsonSchemaToDeclaration; exports.mcpSchemaToParameters = mcpSchemaToParameters; exports.mergeAgentRun = mergeAgentRun; exports.mergeParallelFunctionResponseEvents = mergeParallelFunctionResponseEvents; exports.newInvocationContextId = newInvocationContextId; exports.nlPlanningRequestProcessor = requestProcessor7; exports.nlPlanningResponseProcessor = responseProcessor2; exports.normalizeJsonSchema = normalizeJsonSchema; exports.populateClientFunctionCallId = populateClientFunctionCallId; exports.registerProviders = registerProviders; exports.removeClientFunctionCallId = removeClientFunctionCallId; exports.requestProcessor = requestProcessor; exports.shutdownTelemetry = shutdownTelemetry; exports.telemetryService = telemetryService; exports.traceLlmCall = traceLlmCall; exports.traceToolCall = traceToolCall; exports.tracer = tracer;
|
package/dist/index.mjs
CHANGED
|
@@ -674,6 +674,8 @@ __export(agents_exports, {
|
|
|
674
674
|
RunConfig: () => RunConfig,
|
|
675
675
|
SequentialAgent: () => SequentialAgent,
|
|
676
676
|
StreamingMode: () => StreamingMode,
|
|
677
|
+
createBranchContextForSubAgent: () => createBranchContextForSubAgent,
|
|
678
|
+
mergeAgentRun: () => mergeAgentRun,
|
|
677
679
|
newInvocationContextId: () => newInvocationContextId
|
|
678
680
|
});
|
|
679
681
|
|
|
@@ -3698,6 +3700,7 @@ __export(tools_exports, {
|
|
|
3698
3700
|
McpAbi: () => McpAbi,
|
|
3699
3701
|
McpAtp: () => McpAtp,
|
|
3700
3702
|
McpBamm: () => McpBamm,
|
|
3703
|
+
McpCoinGecko: () => McpCoinGecko,
|
|
3701
3704
|
McpError: () => McpError,
|
|
3702
3705
|
McpErrorType: () => McpErrorType,
|
|
3703
3706
|
McpFilesystem: () => McpFilesystem,
|
|
@@ -5470,6 +5473,14 @@ function McpTelegram(config = {}) {
|
|
|
5470
5473
|
);
|
|
5471
5474
|
return new McpToolset(mcpConfig);
|
|
5472
5475
|
}
|
|
5476
|
+
function McpCoinGecko(config = {}) {
|
|
5477
|
+
const mcpConfig = createMcpConfig(
|
|
5478
|
+
"CoinGecko MCP Client",
|
|
5479
|
+
"@coingecko/coingecko-mcp",
|
|
5480
|
+
config
|
|
5481
|
+
);
|
|
5482
|
+
return new McpToolset(mcpConfig);
|
|
5483
|
+
}
|
|
5473
5484
|
function McpFilesystem(config = {}) {
|
|
5474
5485
|
const mcpConfig = createMcpConfig(
|
|
5475
5486
|
"Filesystem MCP Client",
|
|
@@ -8861,6 +8872,9 @@ var LangGraphAgent = class extends BaseAgent {
|
|
|
8861
8872
|
}
|
|
8862
8873
|
};
|
|
8863
8874
|
|
|
8875
|
+
// src/agents/agent-builder.ts
|
|
8876
|
+
import { generateId } from "ai";
|
|
8877
|
+
|
|
8864
8878
|
// src/runners.ts
|
|
8865
8879
|
import { SpanStatusCode } from "@opentelemetry/api";
|
|
8866
8880
|
|
|
@@ -9803,10 +9817,10 @@ var AgentBuilder = class _AgentBuilder {
|
|
|
9803
9817
|
return this;
|
|
9804
9818
|
}
|
|
9805
9819
|
/**
|
|
9806
|
-
* Configure session management
|
|
9820
|
+
* Configure session management with optional smart defaults
|
|
9807
9821
|
* @param service Session service to use
|
|
9808
|
-
* @param userId User identifier
|
|
9809
|
-
* @param appName Application name
|
|
9822
|
+
* @param userId User identifier (optional, defaults to agent-based ID)
|
|
9823
|
+
* @param appName Application name (optional, defaults to agent-based name)
|
|
9810
9824
|
* @param memoryService Optional memory service
|
|
9811
9825
|
* @param artifactService Optional artifact service
|
|
9812
9826
|
* @returns This builder instance for chaining
|
|
@@ -9814,17 +9828,18 @@ var AgentBuilder = class _AgentBuilder {
|
|
|
9814
9828
|
withSession(service, userId, appName, memoryService, artifactService) {
|
|
9815
9829
|
this.sessionConfig = {
|
|
9816
9830
|
service,
|
|
9817
|
-
userId,
|
|
9818
|
-
appName,
|
|
9831
|
+
userId: userId || this.generateDefaultUserId(),
|
|
9832
|
+
appName: appName || this.generateDefaultAppName(),
|
|
9819
9833
|
memoryService,
|
|
9820
9834
|
artifactService
|
|
9821
9835
|
};
|
|
9822
9836
|
return this;
|
|
9823
9837
|
}
|
|
9824
9838
|
/**
|
|
9825
|
-
* Configure with an in-memory session
|
|
9826
|
-
*
|
|
9827
|
-
* @param
|
|
9839
|
+
* Configure with an in-memory session with custom IDs
|
|
9840
|
+
* Note: In-memory sessions are created automatically by default, use this only if you need custom appName/userId
|
|
9841
|
+
* @param appName Application name (optional, defaults to agent-based name)
|
|
9842
|
+
* @param userId User identifier (optional, defaults to agent-based ID)
|
|
9828
9843
|
* @returns This builder instance for chaining
|
|
9829
9844
|
*/
|
|
9830
9845
|
withQuickSession(appName, userId) {
|
|
@@ -9838,6 +9853,9 @@ var AgentBuilder = class _AgentBuilder {
|
|
|
9838
9853
|
const agent = this.createAgent();
|
|
9839
9854
|
let runner;
|
|
9840
9855
|
let session;
|
|
9856
|
+
if (!this.sessionConfig) {
|
|
9857
|
+
this.withQuickSession();
|
|
9858
|
+
}
|
|
9841
9859
|
if (this.sessionConfig) {
|
|
9842
9860
|
session = await this.sessionConfig.service.createSession(
|
|
9843
9861
|
this.sessionConfig.appName,
|
|
@@ -9846,49 +9864,26 @@ var AgentBuilder = class _AgentBuilder {
|
|
|
9846
9864
|
const runnerConfig = {
|
|
9847
9865
|
appName: this.sessionConfig.appName,
|
|
9848
9866
|
agent,
|
|
9849
|
-
sessionService: this.sessionConfig.service
|
|
9867
|
+
sessionService: this.sessionConfig.service,
|
|
9868
|
+
memoryService: this.sessionConfig.memoryService,
|
|
9869
|
+
artifactService: this.sessionConfig.artifactService
|
|
9850
9870
|
};
|
|
9851
|
-
|
|
9852
|
-
|
|
9853
|
-
}
|
|
9854
|
-
if (this.sessionConfig.artifactService) {
|
|
9855
|
-
runnerConfig.artifactService = this.sessionConfig.artifactService;
|
|
9856
|
-
}
|
|
9857
|
-
runner = new Runner(runnerConfig);
|
|
9871
|
+
const baseRunner = new Runner(runnerConfig);
|
|
9872
|
+
runner = this.createEnhancedRunner(baseRunner, session);
|
|
9858
9873
|
}
|
|
9859
9874
|
return { agent, runner, session };
|
|
9860
9875
|
}
|
|
9861
9876
|
/**
|
|
9862
9877
|
* Quick execution helper - build and run a message
|
|
9863
|
-
* @param message Message to send to the agent
|
|
9878
|
+
* @param message Message to send to the agent (string or full message object)
|
|
9864
9879
|
* @returns Agent response
|
|
9865
9880
|
*/
|
|
9866
9881
|
async ask(message) {
|
|
9867
|
-
|
|
9868
|
-
|
|
9869
|
-
|
|
9870
|
-
this.withQuickSession(appName, userId);
|
|
9871
|
-
}
|
|
9872
|
-
const { runner, session } = await this.build();
|
|
9873
|
-
if (!runner || !session) {
|
|
9874
|
-
throw new Error("Failed to create runner and session");
|
|
9875
|
-
}
|
|
9876
|
-
let response = "";
|
|
9877
|
-
for await (const event of runner.runAsync({
|
|
9878
|
-
userId: this.sessionConfig.userId,
|
|
9879
|
-
sessionId: session.id,
|
|
9880
|
-
newMessage: {
|
|
9881
|
-
parts: [{ text: message }]
|
|
9882
|
-
}
|
|
9883
|
-
})) {
|
|
9884
|
-
if (event.content?.parts) {
|
|
9885
|
-
const content = event.content.parts.map((part) => part.text || "").join("");
|
|
9886
|
-
if (content) {
|
|
9887
|
-
response += content;
|
|
9888
|
-
}
|
|
9889
|
-
}
|
|
9882
|
+
const { runner } = await this.build();
|
|
9883
|
+
if (!runner) {
|
|
9884
|
+
throw new Error("Failed to create runner");
|
|
9890
9885
|
}
|
|
9891
|
-
return
|
|
9886
|
+
return runner.ask(message);
|
|
9892
9887
|
}
|
|
9893
9888
|
/**
|
|
9894
9889
|
* Create the appropriate agent type based on configuration
|
|
@@ -9911,7 +9906,7 @@ var AgentBuilder = class _AgentBuilder {
|
|
|
9911
9906
|
});
|
|
9912
9907
|
}
|
|
9913
9908
|
case "sequential":
|
|
9914
|
-
if (!this.config.subAgents) {
|
|
9909
|
+
if (!this.config.subAgents || !Array.isArray(this.config.subAgents) || this.config.subAgents.length === 0) {
|
|
9915
9910
|
throw new Error("Sub-agents required for sequential agent");
|
|
9916
9911
|
}
|
|
9917
9912
|
return new SequentialAgent({
|
|
@@ -9920,7 +9915,7 @@ var AgentBuilder = class _AgentBuilder {
|
|
|
9920
9915
|
subAgents: this.config.subAgents
|
|
9921
9916
|
});
|
|
9922
9917
|
case "parallel":
|
|
9923
|
-
if (!this.config.subAgents) {
|
|
9918
|
+
if (!this.config.subAgents || !Array.isArray(this.config.subAgents) || this.config.subAgents.length === 0) {
|
|
9924
9919
|
throw new Error("Sub-agents required for parallel agent");
|
|
9925
9920
|
}
|
|
9926
9921
|
return new ParallelAgent({
|
|
@@ -9929,7 +9924,7 @@ var AgentBuilder = class _AgentBuilder {
|
|
|
9929
9924
|
subAgents: this.config.subAgents
|
|
9930
9925
|
});
|
|
9931
9926
|
case "loop":
|
|
9932
|
-
if (!this.config.subAgents) {
|
|
9927
|
+
if (!this.config.subAgents || !Array.isArray(this.config.subAgents) || this.config.subAgents.length === 0) {
|
|
9933
9928
|
throw new Error("Sub-agents required for loop agent");
|
|
9934
9929
|
}
|
|
9935
9930
|
return new LoopAgent({
|
|
@@ -9939,7 +9934,7 @@ var AgentBuilder = class _AgentBuilder {
|
|
|
9939
9934
|
maxIterations: this.config.maxIterations || 3
|
|
9940
9935
|
});
|
|
9941
9936
|
case "langgraph":
|
|
9942
|
-
if (!this.config.nodes || !this.config.rootNode) {
|
|
9937
|
+
if (!this.config.nodes || !Array.isArray(this.config.nodes) || this.config.nodes.length === 0 || !this.config.rootNode || typeof this.config.rootNode !== "string") {
|
|
9943
9938
|
throw new Error("Nodes and root node required for LangGraph agent");
|
|
9944
9939
|
}
|
|
9945
9940
|
return new LangGraphAgent({
|
|
@@ -9950,6 +9945,57 @@ var AgentBuilder = class _AgentBuilder {
|
|
|
9950
9945
|
});
|
|
9951
9946
|
}
|
|
9952
9947
|
}
|
|
9948
|
+
/**
|
|
9949
|
+
* Generate default user ID based on agent name and id
|
|
9950
|
+
* @returns Generated user ID
|
|
9951
|
+
*/
|
|
9952
|
+
generateDefaultUserId() {
|
|
9953
|
+
const id = generateId();
|
|
9954
|
+
return `user-${this.config.name}-${id}`;
|
|
9955
|
+
}
|
|
9956
|
+
/**
|
|
9957
|
+
* Generate default app name based on agent name
|
|
9958
|
+
* @returns Generated app name
|
|
9959
|
+
*/
|
|
9960
|
+
generateDefaultAppName() {
|
|
9961
|
+
return `app-${this.config.name}`;
|
|
9962
|
+
}
|
|
9963
|
+
/**
|
|
9964
|
+
* Create enhanced runner with simplified API
|
|
9965
|
+
* @param baseRunner The base runner instance
|
|
9966
|
+
* @param session The session instance
|
|
9967
|
+
* @returns Enhanced runner with simplified API
|
|
9968
|
+
*/
|
|
9969
|
+
createEnhancedRunner(baseRunner, session) {
|
|
9970
|
+
const sessionConfig = this.sessionConfig;
|
|
9971
|
+
return {
|
|
9972
|
+
async ask(message) {
|
|
9973
|
+
const fullMessage = typeof message === "string" ? { parts: [{ text: message }] } : message;
|
|
9974
|
+
let response = "";
|
|
9975
|
+
if (!sessionConfig) {
|
|
9976
|
+
throw new Error("Session configuration is required");
|
|
9977
|
+
}
|
|
9978
|
+
for await (const event of baseRunner.runAsync({
|
|
9979
|
+
userId: sessionConfig.userId,
|
|
9980
|
+
sessionId: session.id,
|
|
9981
|
+
newMessage: fullMessage
|
|
9982
|
+
})) {
|
|
9983
|
+
if (event.content?.parts && Array.isArray(event.content.parts)) {
|
|
9984
|
+
const content = event.content.parts.map(
|
|
9985
|
+
(part) => (part && typeof part === "object" && "text" in part ? part.text : "") || ""
|
|
9986
|
+
).join("");
|
|
9987
|
+
if (content) {
|
|
9988
|
+
response += content;
|
|
9989
|
+
}
|
|
9990
|
+
}
|
|
9991
|
+
}
|
|
9992
|
+
return response;
|
|
9993
|
+
},
|
|
9994
|
+
runAsync(params) {
|
|
9995
|
+
return baseRunner.runAsync(params);
|
|
9996
|
+
}
|
|
9997
|
+
};
|
|
9998
|
+
}
|
|
9953
9999
|
};
|
|
9954
10000
|
|
|
9955
10001
|
// src/memory/index.ts
|
|
@@ -11005,6 +11051,7 @@ export {
|
|
|
11005
11051
|
McpAbi,
|
|
11006
11052
|
McpAtp,
|
|
11007
11053
|
McpBamm,
|
|
11054
|
+
McpCoinGecko,
|
|
11008
11055
|
McpError,
|
|
11009
11056
|
McpErrorType,
|
|
11010
11057
|
McpFilesystem,
|
|
@@ -11042,6 +11089,7 @@ export {
|
|
|
11042
11089
|
UserInteractionTool,
|
|
11043
11090
|
VERSION,
|
|
11044
11091
|
VertexAiSessionService,
|
|
11092
|
+
_findFunctionCallEventIfLastEventIsFunctionResponse,
|
|
11045
11093
|
adkToMcpToolType,
|
|
11046
11094
|
requestProcessor8 as agentTransferRequestProcessor,
|
|
11047
11095
|
requestProcessor2 as basicRequestProcessor,
|
|
@@ -11050,6 +11098,7 @@ export {
|
|
|
11050
11098
|
responseProcessor as codeExecutionResponseProcessor,
|
|
11051
11099
|
requestProcessor4 as contentRequestProcessor,
|
|
11052
11100
|
createAuthToolArguments,
|
|
11101
|
+
createBranchContextForSubAgent,
|
|
11053
11102
|
createDatabaseSessionService,
|
|
11054
11103
|
createFunctionTool,
|
|
11055
11104
|
createMysqlSessionService,
|
|
@@ -11069,6 +11118,7 @@ export {
|
|
|
11069
11118
|
isEnhancedAuthConfig,
|
|
11070
11119
|
jsonSchemaToDeclaration,
|
|
11071
11120
|
mcpSchemaToParameters,
|
|
11121
|
+
mergeAgentRun,
|
|
11072
11122
|
mergeParallelFunctionResponseEvents,
|
|
11073
11123
|
newInvocationContextId,
|
|
11074
11124
|
requestProcessor7 as nlPlanningRequestProcessor,
|