@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.
Files changed (132) hide show
  1. package/dist/cjs/a2a/a2a_event.js +290 -0
  2. package/dist/cjs/a2a/event_converter_utils.js +201 -0
  3. package/dist/cjs/a2a/executor_context.js +53 -0
  4. package/dist/cjs/a2a/metadata_converter_utils.js +125 -0
  5. package/dist/cjs/a2a/part_converter_utils.js +23 -21
  6. package/dist/cjs/agents/base_agent.js +3 -3
  7. package/dist/cjs/{tools/tool_context.js → agents/context.js} +70 -15
  8. package/dist/cjs/agents/functions.js +2 -2
  9. package/dist/cjs/agents/llm_agent.js +21 -674
  10. package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +132 -0
  11. package/dist/cjs/agents/processors/basic_llm_request_processor.js +68 -0
  12. package/dist/cjs/agents/processors/code_execution_request_processor.js +389 -0
  13. package/dist/cjs/agents/processors/content_request_processor.js +66 -0
  14. package/dist/cjs/agents/processors/identity_llm_request_processor.js +54 -0
  15. package/dist/cjs/agents/processors/instructions_llm_request_processor.js +85 -0
  16. package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +165 -0
  17. package/dist/cjs/common.js +11 -7
  18. package/dist/cjs/index.js +89 -53
  19. package/dist/cjs/index.js.map +7 -0
  20. package/dist/cjs/models/llm_response.js +2 -0
  21. package/dist/cjs/plugins/base_plugin.js +1 -1
  22. package/dist/cjs/runner/runner.js +1 -1
  23. package/dist/cjs/sessions/database_session_service.js +4 -1
  24. package/dist/cjs/sessions/db/operations.js +24 -12
  25. package/dist/cjs/tools/base_tool.js +3 -0
  26. package/dist/cjs/tools/base_toolset.js +13 -3
  27. package/dist/cjs/tools/exit_loop_tool.js +63 -0
  28. package/dist/cjs/tools/mcp/mcp_toolset.js +9 -5
  29. package/dist/cjs/utils/logger.js +61 -54
  30. package/dist/cjs/version.js +1 -1
  31. package/dist/esm/a2a/a2a_event.js +243 -0
  32. package/dist/esm/a2a/event_converter_utils.js +187 -0
  33. package/dist/esm/a2a/executor_context.js +23 -0
  34. package/dist/esm/a2a/metadata_converter_utils.js +90 -0
  35. package/dist/esm/a2a/part_converter_utils.js +25 -21
  36. package/dist/esm/agents/base_agent.js +3 -3
  37. package/dist/esm/{tools/tool_context.js → agents/context.js} +66 -11
  38. package/dist/esm/agents/functions.js +2 -2
  39. package/dist/esm/agents/llm_agent.js +14 -683
  40. package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +101 -0
  41. package/dist/esm/agents/processors/basic_llm_request_processor.js +37 -0
  42. package/dist/esm/agents/processors/code_execution_request_processor.js +363 -0
  43. package/dist/esm/agents/processors/content_request_processor.js +38 -0
  44. package/dist/esm/agents/processors/identity_llm_request_processor.js +23 -0
  45. package/dist/esm/agents/processors/instructions_llm_request_processor.js +54 -0
  46. package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +140 -0
  47. package/dist/esm/common.js +11 -9
  48. package/dist/esm/index.js +95 -18
  49. package/dist/esm/index.js.map +7 -0
  50. package/dist/esm/models/llm_response.js +2 -0
  51. package/dist/esm/plugins/base_plugin.js +1 -1
  52. package/dist/esm/runner/runner.js +1 -1
  53. package/dist/esm/sessions/database_session_service.js +4 -1
  54. package/dist/esm/sessions/db/operations.js +31 -7
  55. package/dist/esm/tools/base_tool.js +3 -0
  56. package/dist/esm/tools/base_toolset.js +11 -2
  57. package/dist/esm/tools/exit_loop_tool.js +32 -0
  58. package/dist/esm/tools/mcp/mcp_toolset.js +9 -5
  59. package/dist/esm/utils/logger.js +51 -54
  60. package/dist/esm/version.js +1 -1
  61. package/dist/types/a2a/a2a_event.d.ts +122 -0
  62. package/dist/types/a2a/event_converter_utils.d.ts +20 -0
  63. package/dist/types/a2a/executor_context.d.ts +33 -0
  64. package/dist/types/a2a/metadata_converter_utils.d.ts +62 -0
  65. package/dist/types/a2a/part_converter_utils.d.ts +4 -3
  66. package/dist/types/agents/base_agent.d.ts +2 -2
  67. package/dist/types/{tools/tool_context.d.ts → agents/context.d.ts} +43 -8
  68. package/dist/types/agents/llm_agent.d.ts +8 -31
  69. package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +18 -0
  70. package/dist/types/agents/{base_llm_processor.d.ts → processors/base_llm_processor.d.ts} +4 -4
  71. package/dist/types/agents/processors/basic_llm_request_processor.d.ts +13 -0
  72. package/dist/types/agents/processors/code_execution_request_processor.d.ts +34 -0
  73. package/dist/types/agents/processors/content_request_processor.d.ts +13 -0
  74. package/dist/types/agents/processors/identity_llm_request_processor.d.ts +13 -0
  75. package/dist/types/agents/processors/instructions_llm_request_processor.d.ts +16 -0
  76. package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +13 -0
  77. package/dist/types/auth/credential_service/base_credential_service.d.ts +3 -3
  78. package/dist/types/auth/credential_service/in_memory_credential_service.d.ts +3 -3
  79. package/dist/types/common.d.ts +4 -4
  80. package/dist/types/models/llm_response.d.ts +5 -1
  81. package/dist/types/plugins/base_plugin.d.ts +12 -13
  82. package/dist/types/plugins/logging_plugin.d.ts +9 -10
  83. package/dist/types/plugins/plugin_manager.d.ts +9 -10
  84. package/dist/types/plugins/security_plugin.d.ts +2 -2
  85. package/dist/types/sessions/database_session_service.d.ts +2 -1
  86. package/dist/types/sessions/db/operations.d.ts +1 -1
  87. package/dist/types/tools/base_tool.d.ts +3 -3
  88. package/dist/types/tools/base_toolset.d.ts +12 -3
  89. package/dist/types/tools/exit_loop_tool.d.ts +24 -0
  90. package/dist/types/tools/forwarding_artifact_service.d.ts +2 -2
  91. package/dist/types/tools/function_tool.d.ts +2 -2
  92. package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -1
  93. package/dist/types/utils/logger.d.ts +5 -9
  94. package/dist/types/version.d.ts +1 -1
  95. package/dist/web/a2a/a2a_event.js +243 -0
  96. package/dist/web/a2a/event_converter_utils.js +201 -0
  97. package/dist/web/a2a/executor_context.js +23 -0
  98. package/dist/web/a2a/metadata_converter_utils.js +107 -0
  99. package/dist/web/a2a/part_converter_utils.js +25 -21
  100. package/dist/web/agents/base_agent.js +3 -3
  101. package/dist/web/{tools/tool_context.js → agents/context.js} +66 -11
  102. package/dist/web/agents/functions.js +2 -2
  103. package/dist/web/agents/llm_agent.js +14 -661
  104. package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +100 -0
  105. package/dist/web/agents/processors/basic_llm_request_processor.js +71 -0
  106. package/dist/web/agents/processors/code_execution_request_processor.js +365 -0
  107. package/dist/web/agents/processors/content_request_processor.js +56 -0
  108. package/dist/web/agents/processors/identity_llm_request_processor.js +41 -0
  109. package/dist/web/agents/processors/instructions_llm_request_processor.js +72 -0
  110. package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +158 -0
  111. package/dist/web/common.js +11 -9
  112. package/dist/web/index.js +13 -18
  113. package/dist/web/index.js.map +7 -0
  114. package/dist/web/models/llm_response.js +2 -0
  115. package/dist/web/plugins/base_plugin.js +1 -1
  116. package/dist/web/runner/runner.js +1 -1
  117. package/dist/web/sessions/database_session_service.js +4 -1
  118. package/dist/web/sessions/db/operations.js +31 -7
  119. package/dist/web/tools/base_tool.js +3 -0
  120. package/dist/web/tools/base_toolset.js +11 -2
  121. package/dist/web/tools/exit_loop_tool.js +32 -0
  122. package/dist/web/tools/mcp/mcp_toolset.js +27 -5
  123. package/dist/web/utils/logger.js +51 -54
  124. package/dist/web/version.js +1 -1
  125. package/package.json +3 -2
  126. package/dist/cjs/agents/callback_context.js +0 -101
  127. package/dist/esm/agents/callback_context.js +0 -71
  128. package/dist/types/agents/callback_context.d.ts +0 -42
  129. package/dist/web/agents/callback_context.js +0 -71
  130. /package/dist/cjs/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
  131. /package/dist/esm/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
  132. /package/dist/web/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
@@ -3,34 +3,69 @@
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
- import { InvocationContext } from '../agents/invocation_context.js';
6
+ import { Part } from '@google/genai';
8
7
  import { AuthCredential } from '../auth/auth_credential.js';
9
8
  import { AuthConfig } from '../auth/auth_tool.js';
10
9
  import { EventActions } from '../events/event_actions.js';
11
10
  import { SearchMemoryResponse } from '../memory/base_memory_service.js';
11
+ import { State } from '../sessions/state.js';
12
12
  import { ToolConfirmation } from '../tools/tool_confirmation.js';
13
- export declare class ToolContext extends CallbackContext {
13
+ import { InvocationContext } from './invocation_context.js';
14
+ import { ReadonlyContext } from './readonly_context.js';
15
+ /**
16
+ * The context of various callbacks within an agent run.
17
+ *
18
+ * This class provides the context for callbacks and tool invocations, including
19
+ * access to the invocation context, function call ID, event actions, and
20
+ * authentication response. It also provides methods for requesting credentials,
21
+ * retrieving authentication responses, loading and saving artifacts, and
22
+ * searching memory.
23
+ */
24
+ export declare class Context extends ReadonlyContext {
25
+ private readonly _state;
26
+ readonly eventActions: EventActions;
14
27
  readonly functionCallId?: string;
15
28
  toolConfirmation?: ToolConfirmation;
16
29
  /**
17
- * @param params.invocationContext The invocation context of the tool.
18
- * @param params.eventActions The event actions of the current tool call.
19
- * @param params.functionCallId The function call id of the current tool call.
30
+ * @param options The configuration options for the Context.
31
+ * @param options.invocationContext The invocation context.
32
+ * @param options.eventActions The event actions of the current call.
33
+ * @param options.functionCallId The function call id of the current tool call.
20
34
  * This id was returned in the function call event from LLM to identify a
21
35
  * function call. If LLM didn't return this id, ADK will assign one to it.
22
36
  * This id is used to map function call response to the original function
23
37
  * call.
24
- * @param params.toolConfirmation The tool confirmation of the current tool
38
+ * @param options.toolConfirmation The tool confirmation of the current tool
25
39
  * call.
26
40
  */
27
- constructor(params: {
41
+ constructor(options: {
28
42
  invocationContext: InvocationContext;
29
43
  eventActions?: EventActions;
30
44
  functionCallId?: string;
31
45
  toolConfirmation?: ToolConfirmation;
32
46
  });
47
+ /**
48
+ * The delta-aware state of the current session.
49
+ */
50
+ get state(): State;
33
51
  get actions(): EventActions;
52
+ /**
53
+ * Loads an artifact attached to the current session.
54
+ *
55
+ * @param filename The filename of the artifact.
56
+ * @param version The version of the artifact. If not provided, the latest
57
+ * version will be used.
58
+ * @return A promise that resolves to the loaded artifact.
59
+ */
60
+ loadArtifact(filename: string, version?: number): Promise<Part | undefined>;
61
+ /**
62
+ * Saves an artifact attached to the current session.
63
+ *
64
+ * @param filename The filename of the artifact.
65
+ * @param artifact The artifact to save.
66
+ * @return A promise that resolves to the version of the saved artifact.
67
+ */
68
+ saveArtifact(filename: string, artifact: Part): Promise<number>;
34
69
  requestCredential(authConfig: AuthConfig): void;
35
70
  /**
36
71
  * Gets the auth credential for the given auth config.
@@ -15,10 +15,9 @@ import { LlmRequest } from '../models/llm_request.js';
15
15
  import { LlmResponse } from '../models/llm_response.js';
16
16
  import { BaseTool } from '../tools/base_tool.js';
17
17
  import { BaseToolset } from '../tools/base_toolset.js';
18
- import { ToolContext } from '../tools/tool_context.js';
18
+ import { Context } from './context.js';
19
19
  import { BaseAgent, BaseAgentConfig } from './base_agent.js';
20
- import { BaseLlmRequestProcessor, BaseLlmResponseProcessor } from './base_llm_processor.js';
21
- import { CallbackContext } from './callback_context.js';
20
+ import { BaseLlmRequestProcessor, BaseLlmResponseProcessor } from './processors/base_llm_processor.js';
22
21
  import { InvocationContext } from './invocation_context.js';
23
22
  import { ReadonlyContext } from './readonly_context.js';
24
23
  /**
@@ -36,7 +35,7 @@ export type InstructionProvider = (context: ReadonlyContext) => string | Promise
36
35
  * will be skipped and the provided content will be returned to user.
37
36
  */
38
37
  export type SingleBeforeModelCallback = (params: {
39
- context: CallbackContext;
38
+ context: Context;
40
39
  request: LlmRequest;
41
40
  }) => LlmResponse | undefined | Promise<LlmResponse | undefined>;
42
41
  /**
@@ -56,7 +55,7 @@ export type BeforeModelCallback = SingleBeforeModelCallback | SingleBeforeModelC
56
55
  * user.
57
56
  */
58
57
  export type SingleAfterModelCallback = (params: {
59
- context: CallbackContext;
58
+ context: Context;
60
59
  response: LlmResponse;
61
60
  }) => LlmResponse | undefined | Promise<LlmResponse | undefined>;
62
61
  /**
@@ -71,14 +70,14 @@ export type AfterModelCallback = SingleAfterModelCallback | SingleAfterModelCall
71
70
  *
72
71
  * @param params.tool The tool to be called.
73
72
  * @param params.args The arguments to the tool.
74
- * @param params.context ToolContext for the tool call.
73
+ * @param params.context Context for the tool call.
75
74
  * @returns The tool response. When present, the returned tool response will
76
75
  * be used and the framework will skip calling the actual tool.
77
76
  */
78
77
  export type SingleBeforeToolCallback = (params: {
79
78
  tool: BaseTool;
80
79
  args: Record<string, unknown>;
81
- context: ToolContext;
80
+ context: Context;
82
81
  }) => Record<string, unknown> | undefined | Promise<Record<string, unknown> | undefined>;
83
82
  /**
84
83
  * A single callback or a list of callbacks.
@@ -92,14 +91,14 @@ export type BeforeToolCallback = SingleBeforeToolCallback | SingleBeforeToolCall
92
91
  *
93
92
  * @param params.tool The tool to be called.
94
93
  * @param params.args The arguments to the tool.
95
- * @param params.context ToolContext for the tool call.
94
+ * @param params.context Context for the tool call.
96
95
  * @param params.response The response from the tool.
97
96
  * @returns When present, the returned record will be used as tool result.
98
97
  */
99
98
  export type SingleAfterToolCallback = (params: {
100
99
  tool: BaseTool;
101
100
  args: Record<string, unknown>;
102
- context: ToolContext;
101
+ context: Context;
103
102
  response: Record<string, unknown>;
104
103
  }) => Record<string, unknown> | undefined | Promise<Record<string, unknown> | undefined>;
105
104
  /**
@@ -205,28 +204,6 @@ export interface LlmAgentConfig extends BaseAgentConfig {
205
204
  */
206
205
  codeExecutor?: BaseCodeExecutor;
207
206
  }
208
- declare class RequestConfirmationLlmRequestProcessor extends BaseLlmRequestProcessor {
209
- /** Handles tool confirmation information to build the LLM request. */
210
- runAsync(invocationContext: InvocationContext): AsyncGenerator<Event, void, void>;
211
- }
212
- export declare const REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR: RequestConfirmationLlmRequestProcessor;
213
- /**
214
- * Processor for code execution responses.
215
- */
216
- declare class CodeExecutionResponseProcessor implements BaseLlmResponseProcessor {
217
- /**
218
- * Processes the LLM response asynchronously.
219
- *
220
- * @param invocationContext The invocation context
221
- * @param llmResponse The LLM response to process
222
- * @returns An async generator yielding events
223
- */
224
- runAsync(invocationContext: InvocationContext, llmResponse: LlmResponse): AsyncGenerator<Event, void, unknown>;
225
- }
226
- /**
227
- * The exported response processor instance.
228
- */
229
- export declare const responseProcessor: CodeExecutionResponseProcessor;
230
207
  /**
231
208
  * A unique symbol to identify ADK agent classes.
232
209
  * Defined once and shared by all LlmAgent instances.
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Event } from '../../events/event.js';
7
+ import { LlmRequest } from '../../models/llm_request.js';
8
+ import { InvocationContext } from '../invocation_context.js';
9
+ import { BaseLlmRequestProcessor } from './base_llm_processor.js';
10
+ export declare class AgentTransferLlmRequestProcessor extends BaseLlmRequestProcessor {
11
+ private readonly toolName;
12
+ private readonly tool;
13
+ runAsync(invocationContext: InvocationContext, llmRequest: LlmRequest): AsyncGenerator<Event, void, void>;
14
+ private buildTargetAgentsInfo;
15
+ private buildTargetAgentsInstructions;
16
+ private getTransferTargets;
17
+ }
18
+ export declare const AGENT_TRANSFER_LLM_REQUEST_PROCESSOR: AgentTransferLlmRequestProcessor;
@@ -3,10 +3,10 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { InvocationContext } from '../agents/invocation_context.js';
7
- import { Event } from '../events/event.js';
8
- import { LlmRequest } from '../models/llm_request.js';
9
- import { LlmResponse } from '../models/llm_response.js';
6
+ import { Event } from '../../events/event.js';
7
+ import { LlmRequest } from '../../models/llm_request.js';
8
+ import { LlmResponse } from '../../models/llm_response.js';
9
+ import { InvocationContext } from '../invocation_context.js';
10
10
  /**
11
11
  * Base class for LLM request processor.
12
12
  */
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Event } from '../../events/event.js';
7
+ import { LlmRequest } from '../../models/llm_request.js';
8
+ import { InvocationContext } from '../invocation_context.js';
9
+ import { BaseLlmRequestProcessor } from './base_llm_processor.js';
10
+ export declare class BasicLlmRequestProcessor extends BaseLlmRequestProcessor {
11
+ runAsync(invocationContext: InvocationContext, llmRequest: LlmRequest): AsyncGenerator<Event, void, void>;
12
+ }
13
+ export declare const BASIC_LLM_REQUEST_PROCESSOR: BasicLlmRequestProcessor;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Event } from '../../events/event.js';
7
+ import { LlmRequest } from '../../models/llm_request.js';
8
+ import { LlmResponse } from '../../models/llm_response.js';
9
+ import { InvocationContext } from '../invocation_context.js';
10
+ import { BaseLlmRequestProcessor, BaseLlmResponseProcessor } from './base_llm_processor.js';
11
+ /**
12
+ * Processes code execution requests.
13
+ */
14
+ export declare class CodeExecutionRequestProcessor extends BaseLlmRequestProcessor {
15
+ runAsync(invocationContext: InvocationContext, llmRequest: LlmRequest): AsyncGenerator<Event, void, void>;
16
+ }
17
+ /**
18
+ * Processor for code execution responses.
19
+ */
20
+ export declare class CodeExecutionResponseProcessor implements BaseLlmResponseProcessor {
21
+ /**
22
+ * Processes the LLM response asynchronously.
23
+ *
24
+ * @param invocationContext The invocation context
25
+ * @param llmResponse The LLM response to process
26
+ * @returns An async generator yielding events
27
+ */
28
+ runAsync(invocationContext: InvocationContext, llmResponse: LlmResponse): AsyncGenerator<Event, void, unknown>;
29
+ }
30
+ /**
31
+ * The exported response processor instance.
32
+ */
33
+ export declare const responseProcessor: CodeExecutionResponseProcessor;
34
+ export declare const CODE_EXECUTION_REQUEST_PROCESSOR: CodeExecutionRequestProcessor;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Event } from '../../events/event.js';
7
+ import { LlmRequest } from '../../models/llm_request.js';
8
+ import { InvocationContext } from '../invocation_context.js';
9
+ import { BaseLlmRequestProcessor } from './base_llm_processor.js';
10
+ export declare class ContentRequestProcessor implements BaseLlmRequestProcessor {
11
+ runAsync(invocationContext: InvocationContext, llmRequest: LlmRequest): AsyncGenerator<Event, void, void>;
12
+ }
13
+ export declare const CONTENT_REQUEST_PROCESSOR: ContentRequestProcessor;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Event } from '../../events/event.js';
7
+ import { LlmRequest } from '../../models/llm_request.js';
8
+ import { InvocationContext } from '../invocation_context.js';
9
+ import { BaseLlmRequestProcessor } from './base_llm_processor.js';
10
+ export declare class IdentityLlmRequestProcessor extends BaseLlmRequestProcessor {
11
+ runAsync(invocationContext: InvocationContext, llmRequest: LlmRequest): AsyncGenerator<Event, void, undefined>;
12
+ }
13
+ export declare const IDENTITY_LLM_REQUEST_PROCESSOR: IdentityLlmRequestProcessor;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Event } from '../../events/event.js';
7
+ import { LlmRequest } from '../../models/llm_request.js';
8
+ import { InvocationContext } from '../invocation_context.js';
9
+ import { BaseLlmRequestProcessor } from './base_llm_processor.js';
10
+ export declare class InstructionsLlmRequestProcessor extends BaseLlmRequestProcessor {
11
+ /**
12
+ * Handles instructions and global instructions for LLM flow.
13
+ */
14
+ runAsync(invocationContext: InvocationContext, llmRequest: LlmRequest): AsyncGenerator<Event, void, void>;
15
+ }
16
+ export declare const INSTRUCTIONS_LLM_REQUEST_PROCESSOR: InstructionsLlmRequestProcessor;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Event } from '../../events/event.js';
7
+ import { InvocationContext } from '../invocation_context.js';
8
+ import { BaseLlmRequestProcessor } from './base_llm_processor.js';
9
+ export declare class RequestConfirmationLlmRequestProcessor extends BaseLlmRequestProcessor {
10
+ /** Handles tool confirmation information to build the LLM request. */
11
+ runAsync(invocationContext: InvocationContext): AsyncGenerator<Event, void, void>;
12
+ }
13
+ export declare const REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR: RequestConfirmationLlmRequestProcessor;
@@ -3,7 +3,7 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { ToolContext } from '../../tools/tool_context.js';
6
+ import { Context } from '../../agents/context.js';
7
7
  import { AuthCredential } from '../auth_credential.js';
8
8
  import { AuthConfig } from '../auth_tool.js';
9
9
  /**
@@ -22,6 +22,6 @@ export interface BaseCredentialService {
22
22
  * trying to load the credential.
23
23
  * @return A promise that resolves to the credential saved in the store.
24
24
  */
25
- loadCredential(authConfig: AuthConfig, toolContext: ToolContext): Promise<AuthCredential | undefined>;
26
- saveCredential(authConfig: AuthConfig, toolContext: ToolContext): Promise<void>;
25
+ loadCredential(authConfig: AuthConfig, toolContext: Context): Promise<AuthCredential | undefined>;
26
+ saveCredential(authConfig: AuthConfig, toolContext: Context): Promise<void>;
27
27
  }
@@ -3,7 +3,7 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { ToolContext } from '../../tools/tool_context.js';
6
+ import { Context } from '../../agents/context.js';
7
7
  import { AuthCredential } from '../auth_credential.js';
8
8
  import { AuthConfig } from '../auth_tool.js';
9
9
  import { BaseCredentialService } from './base_credential_service.js';
@@ -13,7 +13,7 @@ import { BaseCredentialService } from './base_credential_service.js';
13
13
  */
14
14
  export declare class InMemoryCredentialService implements BaseCredentialService {
15
15
  private readonly credentials;
16
- loadCredential(authConfig: AuthConfig, toolContext: ToolContext): Promise<AuthCredential | undefined>;
17
- saveCredential(authConfig: AuthConfig, toolContext: ToolContext): Promise<void>;
16
+ loadCredential(authConfig: AuthConfig, toolContext: Context): Promise<AuthCredential | undefined>;
17
+ saveCredential(authConfig: AuthConfig, toolContext: Context): Promise<void>;
18
18
  private getBucketForCurrentContext;
19
19
  }
@@ -7,8 +7,7 @@ export { ActiveStreamingTool } from './agents/active_streaming_tool.js';
7
7
  export type { ActiveStreamingToolParams } from './agents/active_streaming_tool.js';
8
8
  export { BaseAgent, isBaseAgent } from './agents/base_agent.js';
9
9
  export type { AfterAgentCallback, BaseAgentConfig, BeforeAgentCallback, SingleAgentCallback, } from './agents/base_agent.js';
10
- export { BaseLlmRequestProcessor, BaseLlmResponseProcessor, } from './agents/base_llm_processor.js';
11
- export { CallbackContext } from './agents/callback_context.js';
10
+ export { Context } from './agents/context.js';
12
11
  export { functionsExportedForTestingOnly } from './agents/functions.js';
13
12
  export { InvocationContext } from './agents/invocation_context.js';
14
13
  export type { InvocationContextParams } from './agents/invocation_context.js';
@@ -19,6 +18,7 @@ export type { AfterModelCallback, AfterToolCallback, BeforeModelCallback, Before
19
18
  export { LoopAgent, isLoopAgent } from './agents/loop_agent.js';
20
19
  export type { LoopAgentConfig } from './agents/loop_agent.js';
21
20
  export { ParallelAgent, isParallelAgent } from './agents/parallel_agent.js';
21
+ export { BaseLlmRequestProcessor, BaseLlmResponseProcessor, } from './agents/processors/base_llm_processor.js';
22
22
  export { ReadonlyContext } from './agents/readonly_context.js';
23
23
  export { StreamingMode } from './agents/run_config.js';
24
24
  export type { RunConfig } from './agents/run_config.js';
@@ -74,14 +74,14 @@ export { AgentTool, isAgentTool } from './tools/agent_tool.js';
74
74
  export type { AgentToolConfig } from './tools/agent_tool.js';
75
75
  export { BaseTool, isBaseTool } from './tools/base_tool.js';
76
76
  export type { BaseToolParams, RunAsyncToolRequest, ToolProcessLlmRequest, } from './tools/base_tool.js';
77
- export { BaseToolset } from './tools/base_toolset.js';
77
+ export { BaseToolset, isBaseToolset } from './tools/base_toolset.js';
78
78
  export type { ToolPredicate } from './tools/base_toolset.js';
79
+ export { EXIT_LOOP, ExitLoopTool } from './tools/exit_loop_tool.js';
79
80
  export { FunctionTool, isFunctionTool } from './tools/function_tool.js';
80
81
  export type { ToolExecuteArgument, ToolExecuteFunction, ToolInputParameters, ToolOptions, } from './tools/function_tool.js';
81
82
  export { GOOGLE_SEARCH, GoogleSearchTool } from './tools/google_search_tool.js';
82
83
  export { LongRunningFunctionTool } from './tools/long_running_tool.js';
83
84
  export { ToolConfirmation } from './tools/tool_confirmation.js';
84
- export { ToolContext } from './tools/tool_context.js';
85
85
  export { LogLevel, getLogger, setLogLevel, setLogger } from './utils/logger.js';
86
86
  export type { Logger } from './utils/logger.js';
87
87
  export { isGemini2OrAbove } from './utils/model_name.js';
@@ -3,7 +3,7 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { Content, FinishReason, GenerateContentResponse, GenerateContentResponseUsageMetadata, GroundingMetadata, LiveServerSessionResumptionUpdate, Transcription } from '@google/genai';
6
+ import { CitationMetadata, Content, FinishReason, GenerateContentResponse, GenerateContentResponseUsageMetadata, GroundingMetadata, LiveServerSessionResumptionUpdate, Transcription } from '@google/genai';
7
7
  /**
8
8
  * LLM response class that provides the first candidate response from the
9
9
  * model if available. Otherwise, returns error code and message.
@@ -17,6 +17,10 @@ export interface LlmResponse {
17
17
  * The grounding metadata of the response.
18
18
  */
19
19
  groundingMetadata?: GroundingMetadata;
20
+ /**
21
+ * The citation metadata of the response.
22
+ */
23
+ citationMetadata?: CitationMetadata;
20
24
  /**
21
25
  * Indicates whether the text content is part of a unfinished text stream.
22
26
  * Only used for streaming mode and when the content is plain text.
@@ -5,13 +5,12 @@
5
5
  */
6
6
  import { Content } from '@google/genai';
7
7
  import { BaseAgent } from '../agents/base_agent.js';
8
- import { CallbackContext } from '../agents/callback_context.js';
8
+ import { Context } from '../agents/context.js';
9
9
  import { InvocationContext } from '../agents/invocation_context.js';
10
10
  import { Event } from '../events/event.js';
11
11
  import { LlmRequest } from '../models/llm_request.js';
12
12
  import { LlmResponse } from '../models/llm_response.js';
13
13
  import { BaseTool } from '../tools/base_tool.js';
14
- import { ToolContext } from '../tools/tool_context.js';
15
14
  /**
16
15
  * Base class for creating plugins.
17
16
  *
@@ -60,7 +59,7 @@ import { ToolContext } from '../tools/tool_context.js';
60
59
  * {tool, toolArgs, toolContext}: {
61
60
  * tool: BaseTool,
62
61
  * toolArgs: Record<string, unknown>,
63
- * toolContext: ToolContext,
62
+ * toolContext: Context,
64
63
  * },
65
64
  * ): Promise<Record<string, unknown> | undefined> {
66
65
  * this.logger.info(
@@ -75,7 +74,7 @@ import { ToolContext } from '../tools/tool_context.js';
75
74
  * {tool, toolArgs, toolContext, result}: {
76
75
  * tool: BaseTool,
77
76
  * toolArgs: Record<string, unknown>,
78
- * toolContext: ToolContext,
77
+ * toolContext: Context,
79
78
  * result: Record<string, unknown>,
80
79
  * },
81
80
  * ): Promise<Record<string, unknown> | undefined> {
@@ -177,7 +176,7 @@ export declare abstract class BasePlugin {
177
176
  */
178
177
  beforeAgentCallback(params: {
179
178
  agent: BaseAgent;
180
- callbackContext: CallbackContext;
179
+ callbackContext: Context;
181
180
  }): Promise<Content | undefined>;
182
181
  /**
183
182
  * Callback executed after an agent's primary logic has completed.
@@ -193,7 +192,7 @@ export declare abstract class BasePlugin {
193
192
  */
194
193
  afterAgentCallback(params: {
195
194
  agent: BaseAgent;
196
- callbackContext: CallbackContext;
195
+ callbackContext: Context;
197
196
  }): Promise<Content | undefined>;
198
197
  /**
199
198
  * Callback executed before a request is sent to the model.
@@ -209,7 +208,7 @@ export declare abstract class BasePlugin {
209
208
  * `undefined` allows the LLM request to proceed normally.
210
209
  */
211
210
  beforeModelCallback(params: {
212
- callbackContext: CallbackContext;
211
+ callbackContext: Context;
213
212
  llmRequest: LlmRequest;
214
213
  }): Promise<LlmResponse | undefined>;
215
214
  /**
@@ -225,7 +224,7 @@ export declare abstract class BasePlugin {
225
224
  * allows the original response to be used.
226
225
  */
227
226
  afterModelCallback(params: {
228
- callbackContext: CallbackContext;
227
+ callbackContext: Context;
229
228
  llmResponse: LlmResponse;
230
229
  }): Promise<LlmResponse | undefined>;
231
230
  /**
@@ -243,7 +242,7 @@ export declare abstract class BasePlugin {
243
242
  * the original error to be raised.
244
243
  */
245
244
  onModelErrorCallback(params: {
246
- callbackContext: CallbackContext;
245
+ callbackContext: Context;
247
246
  llmRequest: LlmRequest;
248
247
  error: Error;
249
248
  }): Promise<LlmResponse | undefined>;
@@ -264,7 +263,7 @@ export declare abstract class BasePlugin {
264
263
  beforeToolCallback(params: {
265
264
  tool: BaseTool;
266
265
  toolArgs: Record<string, unknown>;
267
- toolContext: ToolContext;
266
+ toolContext: Context;
268
267
  }): Promise<Record<string, unknown> | undefined>;
269
268
  /**
270
269
  * Callback executed after a tool has been called.
@@ -284,14 +283,14 @@ export declare abstract class BasePlugin {
284
283
  afterToolCallback(params: {
285
284
  tool: BaseTool;
286
285
  toolArgs: Record<string, unknown>;
287
- toolContext: ToolContext;
286
+ toolContext: Context;
288
287
  result: Record<string, unknown>;
289
288
  }): Promise<Record<string, unknown> | undefined>;
290
289
  /**
291
290
  * Callback executed when a tool call encounters an error.
292
291
  tool: BaseTool;
293
292
  toolArgs: Record<string, unknown>;
294
- toolContext: ToolContext;
293
+ toolContext: Context;
295
294
  result: Record<string, unknown>;
296
295
  }): Promise<Record<string, unknown> | undefined> {
297
296
  return;
@@ -314,7 +313,7 @@ export declare abstract class BasePlugin {
314
313
  onToolErrorCallback(params: {
315
314
  tool: BaseTool;
316
315
  toolArgs: Record<string, unknown>;
317
- toolContext: ToolContext;
316
+ toolContext: Context;
318
317
  error: Error;
319
318
  }): Promise<Record<string, unknown> | undefined>;
320
319
  }
@@ -5,13 +5,12 @@
5
5
  */
6
6
  import { Content } from '@google/genai';
7
7
  import { BaseAgent } from '../agents/base_agent.js';
8
- import { CallbackContext } from '../agents/callback_context.js';
8
+ import { Context } from '../agents/context.js';
9
9
  import { InvocationContext } from '../agents/invocation_context.js';
10
10
  import { Event } from '../events/event.js';
11
11
  import { LlmRequest } from '../models/llm_request.js';
12
12
  import { LlmResponse } from '../models/llm_response.js';
13
13
  import { BaseTool } from '../tools/base_tool.js';
14
- import { ToolContext } from '../tools/tool_context.js';
15
14
  import { BasePlugin } from './base_plugin.js';
16
15
  /**
17
16
  * A plugin that logs important information at each callback point.
@@ -62,40 +61,40 @@ export declare class LoggingPlugin extends BasePlugin {
62
61
  }): Promise<void>;
63
62
  beforeAgentCallback({ callbackContext, }: {
64
63
  agent: BaseAgent;
65
- callbackContext: CallbackContext;
64
+ callbackContext: Context;
66
65
  }): Promise<Content | undefined>;
67
66
  afterAgentCallback({ callbackContext, }: {
68
67
  agent: BaseAgent;
69
- callbackContext: CallbackContext;
68
+ callbackContext: Context;
70
69
  }): Promise<Content | undefined>;
71
70
  beforeModelCallback({ callbackContext, llmRequest, }: {
72
- callbackContext: CallbackContext;
71
+ callbackContext: Context;
73
72
  llmRequest: LlmRequest;
74
73
  }): Promise<LlmResponse | undefined>;
75
74
  afterModelCallback({ callbackContext, llmResponse, }: {
76
- callbackContext: CallbackContext;
75
+ callbackContext: Context;
77
76
  llmResponse: LlmResponse;
78
77
  }): Promise<LlmResponse | undefined>;
79
78
  beforeToolCallback({ tool, toolArgs, toolContext, }: {
80
79
  tool: BaseTool;
81
80
  toolArgs: Record<string, unknown>;
82
- toolContext: ToolContext;
81
+ toolContext: Context;
83
82
  }): Promise<Record<string, unknown> | undefined>;
84
83
  afterToolCallback({ tool, toolContext, result, }: {
85
84
  tool: BaseTool;
86
85
  toolArgs: Record<string, unknown>;
87
- toolContext: ToolContext;
86
+ toolContext: Context;
88
87
  result: Record<string, unknown>;
89
88
  }): Promise<Record<string, unknown> | undefined>;
90
89
  onModelErrorCallback({ callbackContext, error, }: {
91
- callbackContext: CallbackContext;
90
+ callbackContext: Context;
92
91
  llmRequest: LlmRequest;
93
92
  error: Error;
94
93
  }): Promise<LlmResponse | undefined>;
95
94
  onToolErrorCallback({ tool, toolArgs, toolContext, error, }: {
96
95
  tool: BaseTool;
97
96
  toolArgs: Record<string, unknown>;
98
- toolContext: ToolContext;
97
+ toolContext: Context;
99
98
  error: Error;
100
99
  }): Promise<Record<string, unknown> | undefined>;
101
100
  private log;