@google/adk 0.4.0 → 0.5.0
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/dist/cjs/a2a/a2a_event.js +290 -0
- package/dist/cjs/a2a/event_converter_utils.js +201 -0
- package/dist/cjs/a2a/executor_context.js +53 -0
- package/dist/cjs/a2a/metadata_converter_utils.js +125 -0
- package/dist/cjs/a2a/part_converter_utils.js +23 -21
- package/dist/cjs/agents/base_agent.js +3 -3
- package/dist/cjs/{tools/tool_context.js → agents/context.js} +70 -15
- package/dist/cjs/agents/functions.js +2 -2
- package/dist/cjs/agents/llm_agent.js +21 -674
- package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +132 -0
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +68 -0
- package/dist/cjs/agents/processors/code_execution_request_processor.js +389 -0
- package/dist/cjs/agents/processors/content_request_processor.js +66 -0
- package/dist/cjs/agents/processors/identity_llm_request_processor.js +54 -0
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +85 -0
- package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +165 -0
- package/dist/cjs/common.js +11 -7
- package/dist/cjs/index.js +89 -53
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/models/llm_response.js +2 -0
- package/dist/cjs/plugins/base_plugin.js +1 -1
- package/dist/cjs/runner/runner.js +1 -1
- package/dist/cjs/sessions/database_session_service.js +4 -1
- package/dist/cjs/sessions/db/operations.js +24 -12
- package/dist/cjs/tools/base_tool.js +3 -0
- package/dist/cjs/tools/base_toolset.js +13 -3
- package/dist/cjs/tools/exit_loop_tool.js +63 -0
- package/dist/cjs/tools/mcp/mcp_toolset.js +9 -5
- package/dist/cjs/utils/logger.js +61 -54
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_event.js +243 -0
- package/dist/esm/a2a/event_converter_utils.js +187 -0
- package/dist/esm/a2a/executor_context.js +23 -0
- package/dist/esm/a2a/metadata_converter_utils.js +90 -0
- package/dist/esm/a2a/part_converter_utils.js +25 -21
- package/dist/esm/agents/base_agent.js +3 -3
- package/dist/esm/{tools/tool_context.js → agents/context.js} +66 -11
- package/dist/esm/agents/functions.js +2 -2
- package/dist/esm/agents/llm_agent.js +14 -683
- package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +101 -0
- package/dist/esm/agents/processors/basic_llm_request_processor.js +37 -0
- package/dist/esm/agents/processors/code_execution_request_processor.js +363 -0
- package/dist/esm/agents/processors/content_request_processor.js +38 -0
- package/dist/esm/agents/processors/identity_llm_request_processor.js +23 -0
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +54 -0
- package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +140 -0
- package/dist/esm/common.js +11 -9
- package/dist/esm/index.js +95 -18
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/models/llm_response.js +2 -0
- package/dist/esm/plugins/base_plugin.js +1 -1
- package/dist/esm/runner/runner.js +1 -1
- package/dist/esm/sessions/database_session_service.js +4 -1
- package/dist/esm/sessions/db/operations.js +31 -7
- package/dist/esm/tools/base_tool.js +3 -0
- package/dist/esm/tools/base_toolset.js +11 -2
- package/dist/esm/tools/exit_loop_tool.js +32 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +9 -5
- package/dist/esm/utils/logger.js +51 -54
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_event.d.ts +122 -0
- package/dist/types/a2a/event_converter_utils.d.ts +20 -0
- package/dist/types/a2a/executor_context.d.ts +33 -0
- package/dist/types/a2a/metadata_converter_utils.d.ts +62 -0
- package/dist/types/a2a/part_converter_utils.d.ts +4 -3
- package/dist/types/agents/base_agent.d.ts +2 -2
- package/dist/types/{tools/tool_context.d.ts → agents/context.d.ts} +43 -8
- package/dist/types/agents/llm_agent.d.ts +8 -31
- package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +18 -0
- package/dist/types/agents/{base_llm_processor.d.ts → processors/base_llm_processor.d.ts} +4 -4
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/code_execution_request_processor.d.ts +34 -0
- package/dist/types/agents/processors/content_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/instructions_llm_request_processor.d.ts +16 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +13 -0
- package/dist/types/auth/credential_service/base_credential_service.d.ts +3 -3
- package/dist/types/auth/credential_service/in_memory_credential_service.d.ts +3 -3
- package/dist/types/common.d.ts +4 -4
- package/dist/types/models/llm_response.d.ts +5 -1
- package/dist/types/plugins/base_plugin.d.ts +12 -13
- package/dist/types/plugins/logging_plugin.d.ts +9 -10
- package/dist/types/plugins/plugin_manager.d.ts +9 -10
- package/dist/types/plugins/security_plugin.d.ts +2 -2
- package/dist/types/sessions/database_session_service.d.ts +2 -1
- package/dist/types/sessions/db/operations.d.ts +1 -1
- package/dist/types/tools/base_tool.d.ts +3 -3
- package/dist/types/tools/base_toolset.d.ts +12 -3
- package/dist/types/tools/exit_loop_tool.d.ts +24 -0
- package/dist/types/tools/forwarding_artifact_service.d.ts +2 -2
- package/dist/types/tools/function_tool.d.ts +2 -2
- package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -1
- package/dist/types/utils/logger.d.ts +5 -9
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/a2a_event.js +243 -0
- package/dist/web/a2a/event_converter_utils.js +201 -0
- package/dist/web/a2a/executor_context.js +23 -0
- package/dist/web/a2a/metadata_converter_utils.js +107 -0
- package/dist/web/a2a/part_converter_utils.js +25 -21
- package/dist/web/agents/base_agent.js +3 -3
- package/dist/web/{tools/tool_context.js → agents/context.js} +66 -11
- package/dist/web/agents/functions.js +2 -2
- package/dist/web/agents/llm_agent.js +14 -661
- package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +100 -0
- package/dist/web/agents/processors/basic_llm_request_processor.js +71 -0
- package/dist/web/agents/processors/code_execution_request_processor.js +365 -0
- package/dist/web/agents/processors/content_request_processor.js +56 -0
- package/dist/web/agents/processors/identity_llm_request_processor.js +41 -0
- package/dist/web/agents/processors/instructions_llm_request_processor.js +72 -0
- package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +158 -0
- package/dist/web/common.js +11 -9
- package/dist/web/index.js +13 -18
- package/dist/web/index.js.map +7 -0
- package/dist/web/models/llm_response.js +2 -0
- package/dist/web/plugins/base_plugin.js +1 -1
- package/dist/web/runner/runner.js +1 -1
- package/dist/web/sessions/database_session_service.js +4 -1
- package/dist/web/sessions/db/operations.js +31 -7
- package/dist/web/tools/base_tool.js +3 -0
- package/dist/web/tools/base_toolset.js +11 -2
- package/dist/web/tools/exit_loop_tool.js +32 -0
- package/dist/web/tools/mcp/mcp_toolset.js +27 -5
- package/dist/web/utils/logger.js +51 -54
- package/dist/web/version.js +1 -1
- package/package.json +3 -2
- package/dist/cjs/agents/callback_context.js +0 -101
- package/dist/esm/agents/callback_context.js +0 -71
- package/dist/types/agents/callback_context.d.ts +0 -42
- package/dist/web/agents/callback_context.js +0 -71
- /package/dist/cjs/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
- /package/dist/esm/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
- /package/dist/web/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
|
@@ -3,29 +3,84 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { CallbackContext } from "../agents/callback_context.js";
|
|
7
6
|
import { AuthHandler } from "../auth/auth_handler.js";
|
|
7
|
+
import { createEventActions } from "../events/event_actions.js";
|
|
8
|
+
import { State } from "../sessions/state.js";
|
|
8
9
|
import { ToolConfirmation } from "../tools/tool_confirmation.js";
|
|
9
|
-
|
|
10
|
+
import { ReadonlyContext } from "./readonly_context.js";
|
|
11
|
+
class Context extends ReadonlyContext {
|
|
10
12
|
/**
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
13
|
+
* @param options The configuration options for the Context.
|
|
14
|
+
* @param options.invocationContext The invocation context.
|
|
15
|
+
* @param options.eventActions The event actions of the current call.
|
|
16
|
+
* @param options.functionCallId The function call id of the current tool call.
|
|
14
17
|
* This id was returned in the function call event from LLM to identify a
|
|
15
18
|
* function call. If LLM didn't return this id, ADK will assign one to it.
|
|
16
19
|
* This id is used to map function call response to the original function
|
|
17
20
|
* call.
|
|
18
|
-
* @param
|
|
21
|
+
* @param options.toolConfirmation The tool confirmation of the current tool
|
|
19
22
|
* call.
|
|
20
23
|
*/
|
|
21
|
-
constructor(
|
|
22
|
-
super(
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
24
|
+
constructor(options) {
|
|
25
|
+
super(options.invocationContext);
|
|
26
|
+
this.eventActions = options.eventActions || createEventActions();
|
|
27
|
+
this._state = new State(
|
|
28
|
+
options.invocationContext.session.state,
|
|
29
|
+
this.eventActions.stateDelta
|
|
30
|
+
);
|
|
31
|
+
this.functionCallId = options.functionCallId;
|
|
32
|
+
this.toolConfirmation = options.toolConfirmation;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The delta-aware state of the current session.
|
|
36
|
+
*/
|
|
37
|
+
get state() {
|
|
38
|
+
return this._state;
|
|
25
39
|
}
|
|
26
40
|
get actions() {
|
|
27
41
|
return this.eventActions;
|
|
28
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Loads an artifact attached to the current session.
|
|
45
|
+
*
|
|
46
|
+
* @param filename The filename of the artifact.
|
|
47
|
+
* @param version The version of the artifact. If not provided, the latest
|
|
48
|
+
* version will be used.
|
|
49
|
+
* @return A promise that resolves to the loaded artifact.
|
|
50
|
+
*/
|
|
51
|
+
loadArtifact(filename, version) {
|
|
52
|
+
if (!this.invocationContext.artifactService) {
|
|
53
|
+
throw new Error("Artifact service is not initialized.");
|
|
54
|
+
}
|
|
55
|
+
return this.invocationContext.artifactService.loadArtifact({
|
|
56
|
+
appName: this.invocationContext.appName,
|
|
57
|
+
userId: this.invocationContext.userId,
|
|
58
|
+
sessionId: this.invocationContext.session.id,
|
|
59
|
+
filename,
|
|
60
|
+
version
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Saves an artifact attached to the current session.
|
|
65
|
+
*
|
|
66
|
+
* @param filename The filename of the artifact.
|
|
67
|
+
* @param artifact The artifact to save.
|
|
68
|
+
* @return A promise that resolves to the version of the saved artifact.
|
|
69
|
+
*/
|
|
70
|
+
async saveArtifact(filename, artifact) {
|
|
71
|
+
if (!this.invocationContext.artifactService) {
|
|
72
|
+
throw new Error("Artifact service is not initialized.");
|
|
73
|
+
}
|
|
74
|
+
const version = await this.invocationContext.artifactService.saveArtifact({
|
|
75
|
+
appName: this.invocationContext.appName,
|
|
76
|
+
userId: this.invocationContext.userId,
|
|
77
|
+
sessionId: this.invocationContext.session.id,
|
|
78
|
+
filename,
|
|
79
|
+
artifact
|
|
80
|
+
});
|
|
81
|
+
this.eventActions.artifactDelta[filename] = version;
|
|
82
|
+
return version;
|
|
83
|
+
}
|
|
29
84
|
requestCredential(authConfig) {
|
|
30
85
|
if (!this.functionCallId) {
|
|
31
86
|
throw new Error("functionCallId is not set.");
|
|
@@ -90,5 +145,5 @@ class ToolContext extends CallbackContext {
|
|
|
90
145
|
}
|
|
91
146
|
}
|
|
92
147
|
export {
|
|
93
|
-
|
|
148
|
+
Context
|
|
94
149
|
};
|
|
@@ -7,9 +7,9 @@ import { createUserContent } from "@google/genai";
|
|
|
7
7
|
import { isEmpty } from "lodash-es";
|
|
8
8
|
import { createEvent, getFunctionCalls } from "../events/event.js";
|
|
9
9
|
import { mergeEventActions } from "../events/event_actions.js";
|
|
10
|
-
import { ToolContext } from "../tools/tool_context.js";
|
|
11
10
|
import { randomUUID } from "../utils/env_aware_utils.js";
|
|
12
11
|
import { logger } from "../utils/logger.js";
|
|
12
|
+
import { Context } from "./context.js";
|
|
13
13
|
import {
|
|
14
14
|
traceMergedToolCalls,
|
|
15
15
|
tracer,
|
|
@@ -352,7 +352,7 @@ function getToolAndContext({
|
|
|
352
352
|
`Function ${functionCall.name} is not found in the toolsDict.`
|
|
353
353
|
);
|
|
354
354
|
}
|
|
355
|
-
const toolContext = new
|
|
355
|
+
const toolContext = new Context({
|
|
356
356
|
invocationContext,
|
|
357
357
|
functionCallId: functionCall.id || void 0,
|
|
358
358
|
toolConfirmation
|