@google/adk 0.2.1 → 0.2.2
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/agents/base_agent.js +14 -2
- package/dist/cjs/agents/content_processor_utils.js +2 -2
- package/dist/cjs/agents/functions.js +6 -3
- package/dist/cjs/agents/llm_agent.js +331 -4
- package/dist/cjs/auth/exchanger/base_credential_exchanger.js +40 -0
- package/dist/cjs/auth/exchanger/credential_exchanger_registry.js +59 -0
- package/dist/cjs/code_executors/code_execution_utils.js +2 -2
- package/dist/cjs/code_executors/code_executor_context.js +2 -2
- package/dist/cjs/common.js +7 -0
- package/dist/cjs/index.js +63 -5
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/models/base_llm.js +16 -4
- package/dist/cjs/runner/runner.js +10 -1
- package/dist/cjs/sessions/in_memory_session_service.js +3 -3
- package/dist/cjs/sessions/state.js +1 -1
- package/dist/cjs/tools/agent_tool.js +2 -2
- package/dist/cjs/tools/mcp/mcp_session_manager.js +7 -1
- package/dist/cjs/utils/gemini_schema_util.js +16 -0
- package/dist/cjs/version.js +2 -2
- package/dist/esm/agents/base_agent.js +12 -1
- package/dist/esm/agents/content_processor_utils.js +2 -2
- package/dist/esm/agents/functions.js +6 -3
- package/dist/esm/agents/llm_agent.js +330 -4
- package/dist/esm/auth/exchanger/base_credential_exchanger.js +10 -0
- package/dist/esm/auth/exchanger/credential_exchanger_registry.js +29 -0
- package/dist/esm/code_executors/code_execution_utils.js +2 -2
- package/dist/esm/code_executors/code_executor_context.js +2 -2
- package/dist/esm/common.js +6 -2
- package/dist/esm/index.js +63 -5
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/models/base_llm.js +14 -3
- package/dist/esm/runner/runner.js +10 -1
- package/dist/esm/sessions/in_memory_session_service.js +3 -3
- package/dist/esm/sessions/state.js +1 -1
- package/dist/esm/tools/agent_tool.js +2 -2
- package/dist/esm/tools/function_tool.js +3 -1
- package/dist/esm/tools/mcp/mcp_session_manager.js +7 -1
- package/dist/esm/utils/gemini_schema_util.js +16 -0
- package/dist/esm/version.js +2 -2
- package/dist/types/agents/base_agent.d.ts +15 -0
- package/dist/types/agents/functions.d.ts +2 -0
- package/dist/types/agents/llm_agent.d.ts +23 -0
- package/dist/types/auth/exchanger/base_credential_exchanger.d.ts +32 -0
- package/dist/types/auth/exchanger/credential_exchanger_registry.d.ts +28 -0
- package/dist/types/code_executors/code_executor_context.d.ts +0 -5
- package/dist/types/common.d.ts +3 -2
- package/dist/types/models/base_llm.d.ts +16 -0
- package/dist/types/sessions/in_memory_session_service.d.ts +0 -5
- package/dist/types/sessions/state.d.ts +2 -2
- package/dist/types/tools/function_tool.d.ts +3 -3
- package/dist/types/tools/tool_confirmation.d.ts +1 -1
- package/dist/types/utils/gemini_schema_util.d.ts +2 -2
- package/dist/types/version.d.ts +2 -2
- package/dist/web/agents/base_agent.js +12 -1
- package/dist/web/agents/content_processor_utils.js +2 -2
- package/dist/web/agents/functions.js +6 -3
- package/dist/web/agents/llm_agent.js +315 -4
- package/dist/web/auth/exchanger/base_credential_exchanger.js +10 -0
- package/dist/web/auth/exchanger/credential_exchanger_registry.js +29 -0
- package/dist/web/code_executors/code_execution_utils.js +2 -2
- package/dist/web/code_executors/code_executor_context.js +2 -2
- package/dist/web/common.js +6 -2
- package/dist/web/index.js +6 -1
- package/dist/web/index.js.map +4 -4
- package/dist/web/models/base_llm.js +14 -3
- package/dist/web/runner/runner.js +10 -1
- package/dist/web/sessions/in_memory_session_service.js +3 -3
- package/dist/web/sessions/state.js +1 -1
- package/dist/web/tools/agent_tool.js +2 -2
- package/dist/web/tools/function_tool.js +3 -1
- package/dist/web/tools/mcp/mcp_session_manager.js +7 -1
- package/dist/web/utils/gemini_schema_util.js +16 -0
- package/dist/web/version.js +2 -2
- package/package.json +3 -1
|
@@ -3,7 +3,13 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
var _a;
|
|
6
7
|
import { getClientLabels } from "../utils/client_labels.js";
|
|
8
|
+
const BASE_MODEL_SYMBOL = Symbol.for("google.adk.baseModel");
|
|
9
|
+
function isBaseLlm(obj) {
|
|
10
|
+
return typeof obj === "object" && obj !== null && BASE_MODEL_SYMBOL in obj && obj[BASE_MODEL_SYMBOL] === true;
|
|
11
|
+
}
|
|
12
|
+
_a = BASE_MODEL_SYMBOL;
|
|
7
13
|
class BaseLlm {
|
|
8
14
|
/**
|
|
9
15
|
* Creates an instance of BaseLLM.
|
|
@@ -12,6 +18,10 @@ class BaseLlm {
|
|
|
12
18
|
* gemini-1.5-flash-001.
|
|
13
19
|
*/
|
|
14
20
|
constructor({ model }) {
|
|
21
|
+
/**
|
|
22
|
+
* A unique symbol to identify BaseLlm classes.
|
|
23
|
+
*/
|
|
24
|
+
this[_a] = true;
|
|
15
25
|
this.model = model;
|
|
16
26
|
}
|
|
17
27
|
get trackingHeaders() {
|
|
@@ -28,7 +38,7 @@ class BaseLlm {
|
|
|
28
38
|
* @param llmRequest LlmRequest, the request to send to the LLM.
|
|
29
39
|
*/
|
|
30
40
|
maybeAppendUserContent(llmRequest) {
|
|
31
|
-
var
|
|
41
|
+
var _a2;
|
|
32
42
|
if (llmRequest.contents.length === 0) {
|
|
33
43
|
llmRequest.contents.push({
|
|
34
44
|
role: "user",
|
|
@@ -37,7 +47,7 @@ class BaseLlm {
|
|
|
37
47
|
]
|
|
38
48
|
});
|
|
39
49
|
}
|
|
40
|
-
if (((
|
|
50
|
+
if (((_a2 = llmRequest.contents[llmRequest.contents.length - 1]) == null ? void 0 : _a2.role) !== "user") {
|
|
41
51
|
llmRequest.contents.push({
|
|
42
52
|
role: "user",
|
|
43
53
|
parts: [{
|
|
@@ -52,5 +62,6 @@ class BaseLlm {
|
|
|
52
62
|
*/
|
|
53
63
|
BaseLlm.supportedModels = [];
|
|
54
64
|
export {
|
|
55
|
-
BaseLlm
|
|
65
|
+
BaseLlm,
|
|
66
|
+
isBaseLlm
|
|
56
67
|
};
|
|
@@ -8,6 +8,7 @@ import { trace } from "@opentelemetry/api";
|
|
|
8
8
|
import { InvocationContext, newInvocationContextId } from "../agents/invocation_context.js";
|
|
9
9
|
import { LlmAgent } from "../agents/llm_agent.js";
|
|
10
10
|
import { createRunConfig } from "../agents/run_config.js";
|
|
11
|
+
import { BuiltInCodeExecutor } from "../code_executors/built_in_code_executor.js";
|
|
11
12
|
import { createEvent, getFunctionCalls } from "../events/event.js";
|
|
12
13
|
import { createEventActions } from "../events/event_actions.js";
|
|
13
14
|
import { PluginManager } from "../plugins/plugin_manager.js";
|
|
@@ -48,6 +49,11 @@ class Runner {
|
|
|
48
49
|
try {
|
|
49
50
|
const session = await this.sessionService.getSession({ appName: this.appName, userId, sessionId });
|
|
50
51
|
if (!session) {
|
|
52
|
+
if (!this.appName) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`Session lookup failed: appName must be provided in runner constructor`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
51
57
|
throw new Error(`Session not found: ${sessionId}`);
|
|
52
58
|
}
|
|
53
59
|
if (runConfig.supportCfc && this.agent instanceof LlmAgent) {
|
|
@@ -56,6 +62,9 @@ class Runner {
|
|
|
56
62
|
throw new Error(`CFC is not supported for model: ${modelName} in agent: ${this.agent.name}`);
|
|
57
63
|
}
|
|
58
64
|
}
|
|
65
|
+
if (this.agent instanceof LlmAgent && !(this.agent.codeExecutor instanceof BuiltInCodeExecutor)) {
|
|
66
|
+
this.agent.codeExecutor = new BuiltInCodeExecutor();
|
|
67
|
+
}
|
|
59
68
|
const invocationContext = new InvocationContext({
|
|
60
69
|
artifactService: this.artifactService,
|
|
61
70
|
sessionService: this.sessionService,
|
|
@@ -77,7 +86,7 @@ class Runner {
|
|
|
77
86
|
}
|
|
78
87
|
if (newMessage) {
|
|
79
88
|
if (!((_a = newMessage.parts) == null ? void 0 : _a.length)) {
|
|
80
|
-
throw new Error("No parts in the
|
|
89
|
+
throw new Error("No parts in the newMessage.");
|
|
81
90
|
}
|
|
82
91
|
if (runConfig.saveInputBlobsAsArtifacts) {
|
|
83
92
|
await this.saveArtifacts(
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { cloneDeep } from "lodash";
|
|
7
7
|
import { randomUUID } from "../utils/env_aware_utils.js";
|
|
8
8
|
import { logger } from "../utils/logger.js";
|
|
9
9
|
import { BaseSessionService } from "./base_session_service.js";
|
|
@@ -43,7 +43,7 @@ class InMemorySessionService extends BaseSessionService {
|
|
|
43
43
|
}
|
|
44
44
|
this.sessions[appName][userId][session.id] = session;
|
|
45
45
|
return Promise.resolve(
|
|
46
|
-
this.mergeState(appName, userId,
|
|
46
|
+
this.mergeState(appName, userId, cloneDeep(session))
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
49
|
getSession({ appName, userId, sessionId, config }) {
|
|
@@ -51,7 +51,7 @@ class InMemorySessionService extends BaseSessionService {
|
|
|
51
51
|
return Promise.resolve(void 0);
|
|
52
52
|
}
|
|
53
53
|
const session = this.sessions[appName][userId][sessionId];
|
|
54
|
-
const copiedSession =
|
|
54
|
+
const copiedSession = cloneDeep(session);
|
|
55
55
|
if (config) {
|
|
56
56
|
if (config.numRecentEvents) {
|
|
57
57
|
copiedSession.events = copiedSession.events.slice(-config.numRecentEvents);
|
|
@@ -95,8 +95,8 @@ class AgentTool extends BaseTool {
|
|
|
95
95
|
return "";
|
|
96
96
|
}
|
|
97
97
|
const hasOutputSchema = this.agent instanceof LlmAgent && this.agent.outputSchema;
|
|
98
|
-
const
|
|
99
|
-
return hasOutputSchema ? JSON.parse(
|
|
98
|
+
const mergedText = lastEvent.content.parts.map((part) => part.text).filter((text) => text).join("\n");
|
|
99
|
+
return hasOutputSchema ? JSON.parse(mergedText) : mergedText;
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
export {
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { Type } from "@google/genai";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
ZodObject
|
|
9
|
+
} from "zod";
|
|
8
10
|
import { isZodObject, zodObjectToSchema } from "../utils/simple_zod_to_json.js";
|
|
9
11
|
import { BaseTool } from "./base_tool.js";
|
|
10
12
|
function toSchema(parameters) {
|
|
@@ -19,8 +19,14 @@ class MCPSessionManager {
|
|
|
19
19
|
);
|
|
20
20
|
break;
|
|
21
21
|
case "StreamableHTTPConnectionParams":
|
|
22
|
+
const transportOptions = this.connectionParams.header ? {
|
|
23
|
+
requestInit: {
|
|
24
|
+
headers: this.connectionParams.header
|
|
25
|
+
}
|
|
26
|
+
} : void 0;
|
|
22
27
|
await client.connect(new StreamableHTTPClientTransport(
|
|
23
|
-
new URL(this.connectionParams.url)
|
|
28
|
+
new URL(this.connectionParams.url),
|
|
29
|
+
transportOptions
|
|
24
30
|
));
|
|
25
31
|
break;
|
|
26
32
|
default:
|
|
@@ -34,6 +34,22 @@ function toGeminiSchema(mcpSchema) {
|
|
|
34
34
|
return void 0;
|
|
35
35
|
}
|
|
36
36
|
function recursiveConvert(mcp) {
|
|
37
|
+
if (!mcp.type && mcp.anyOf && Array.isArray(mcp.anyOf)) {
|
|
38
|
+
const nonNullOption = mcp.anyOf.find((opt) => {
|
|
39
|
+
const t = opt.type;
|
|
40
|
+
return t !== "null" && t !== "NULL";
|
|
41
|
+
});
|
|
42
|
+
if (nonNullOption) {
|
|
43
|
+
mcp = nonNullOption;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (!mcp.type) {
|
|
47
|
+
if (mcp.properties || mcp.$ref) {
|
|
48
|
+
mcp.type = "object";
|
|
49
|
+
} else if (mcp.items) {
|
|
50
|
+
mcp.type = "array";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
37
53
|
const geminiType = toGeminiType(mcp.type);
|
|
38
54
|
const geminiSchema = { type: geminiType, description: mcp.description };
|
|
39
55
|
if (geminiType === Type.OBJECT) {
|
package/dist/esm/version.js
CHANGED
|
@@ -21,10 +21,25 @@ export interface BaseAgentConfig {
|
|
|
21
21
|
beforeAgentCallback?: BeforeAgentCallback;
|
|
22
22
|
afterAgentCallback?: AfterAgentCallback;
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* A unique symbol to identify ADK agent classes.
|
|
26
|
+
* Defined once and shared by all BaseAgent instances.
|
|
27
|
+
*/
|
|
28
|
+
declare const BASE_AGENT_SIGNATURE_SYMBOL: unique symbol;
|
|
29
|
+
/**
|
|
30
|
+
* Type guard to check if an object is an instance of BaseAgent.
|
|
31
|
+
* @param obj The object to check.
|
|
32
|
+
* @returns True if the object is an instance of BaseAgent, false otherwise.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isBaseAgent(obj: unknown): obj is BaseAgent;
|
|
24
35
|
/**
|
|
25
36
|
* Base class for all agents in Agent Development Kit.
|
|
26
37
|
*/
|
|
27
38
|
export declare abstract class BaseAgent {
|
|
39
|
+
/**
|
|
40
|
+
* A unique symbol to identify ADK agent classes.
|
|
41
|
+
*/
|
|
42
|
+
readonly [BASE_AGENT_SIGNATURE_SYMBOL] = true;
|
|
28
43
|
/**
|
|
29
44
|
* The agent's name.
|
|
30
45
|
* Agent name must be a JS identifier and unique within the agent tree.
|
|
@@ -13,6 +13,8 @@ export declare const REQUEST_EUC_FUNCTION_CALL_NAME = "adk_request_credential";
|
|
|
13
13
|
export declare const REQUEST_CONFIRMATION_FUNCTION_CALL_NAME = "adk_request_confirmation";
|
|
14
14
|
export declare const functionsExportedForTestingOnly: {
|
|
15
15
|
handleFunctionCallList: typeof handleFunctionCallList;
|
|
16
|
+
generateAuthEvent: typeof generateAuthEvent;
|
|
17
|
+
generateRequestConfirmationEvent: typeof generateRequestConfirmationEvent;
|
|
16
18
|
};
|
|
17
19
|
export declare function generateClientFunctionCallId(): string;
|
|
18
20
|
/**
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { GenerateContentConfig, Schema } from '@google/genai';
|
|
7
|
+
import { BaseCodeExecutor } from '../code_executors/base_code_executor.js';
|
|
7
8
|
import { Event } from '../events/event.js';
|
|
8
9
|
import { BaseExampleProvider } from '../examples/base_example_provider.js';
|
|
9
10
|
import { Example } from '../examples/example.js';
|
|
@@ -200,12 +201,33 @@ export interface LlmAgentConfig extends BaseAgentConfig {
|
|
|
200
201
|
* Processors to run after the LLM response is received.
|
|
201
202
|
*/
|
|
202
203
|
responseProcessors?: BaseLlmResponseProcessor[];
|
|
204
|
+
/**
|
|
205
|
+
* Instructs the agent to make a plan and execute it step by step.
|
|
206
|
+
*/
|
|
207
|
+
codeExecutor?: BaseCodeExecutor;
|
|
203
208
|
}
|
|
204
209
|
declare class RequestConfirmationLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
205
210
|
/** Handles tool confirmation information to build the LLM request. */
|
|
206
211
|
runAsync(invocationContext: InvocationContext, llmRequest: LlmRequest): AsyncGenerator<Event, void, void>;
|
|
207
212
|
}
|
|
208
213
|
export declare const REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR: RequestConfirmationLlmRequestProcessor;
|
|
214
|
+
/**
|
|
215
|
+
* Processor for code execution responses.
|
|
216
|
+
*/
|
|
217
|
+
declare class CodeExecutionResponseProcessor implements BaseLlmResponseProcessor {
|
|
218
|
+
/**
|
|
219
|
+
* Processes the LLM response asynchronously.
|
|
220
|
+
*
|
|
221
|
+
* @param invocationContext The invocation context
|
|
222
|
+
* @param llmResponse The LLM response to process
|
|
223
|
+
* @returns An async generator yielding events
|
|
224
|
+
*/
|
|
225
|
+
runAsync(invocationContext: InvocationContext, llmResponse: LlmResponse): AsyncGenerator<Event, void, unknown>;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* The exported response processor instance.
|
|
229
|
+
*/
|
|
230
|
+
export declare const responseProcessor: CodeExecutionResponseProcessor;
|
|
209
231
|
/**
|
|
210
232
|
* An agent that uses a large language model to generate responses.
|
|
211
233
|
*/
|
|
@@ -227,6 +249,7 @@ export declare class LlmAgent extends BaseAgent {
|
|
|
227
249
|
afterToolCallback?: AfterToolCallback;
|
|
228
250
|
requestProcessors: BaseLlmRequestProcessor[];
|
|
229
251
|
responseProcessors: BaseLlmResponseProcessor[];
|
|
252
|
+
codeExecutor?: BaseCodeExecutor;
|
|
230
253
|
constructor(config: LlmAgentConfig);
|
|
231
254
|
/**
|
|
232
255
|
* The resolved BaseLlm instance.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { AuthCredential } from '../auth_credential.js';
|
|
7
|
+
import { AuthScheme } from '../auth_schemes.js';
|
|
8
|
+
/**
|
|
9
|
+
* Base exception for credential exchange errors.
|
|
10
|
+
*/
|
|
11
|
+
export declare class CredentialExchangeError extends Error {
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Base interface for credential exchangers.
|
|
15
|
+
*
|
|
16
|
+
* Credential exchangers are responsible for exchanging credentials from
|
|
17
|
+
* one format or scheme to another.
|
|
18
|
+
*/
|
|
19
|
+
export interface BaseCredentialExchanger {
|
|
20
|
+
/**
|
|
21
|
+
* Exchange credential if needed.
|
|
22
|
+
*
|
|
23
|
+
* @param authCredential - The credential to exchange.
|
|
24
|
+
* @param authScheme - The authentication scheme (optional, some exchangers don't need it).
|
|
25
|
+
* @returns The exchanged credential.
|
|
26
|
+
* @throws CredentialExchangeError: If credential exchange fails.
|
|
27
|
+
*/
|
|
28
|
+
exchange({ authCredential, authScheme, }: {
|
|
29
|
+
authCredential: AuthCredential;
|
|
30
|
+
authScheme?: AuthScheme;
|
|
31
|
+
}): Promise<AuthCredential>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Credential exchanger registry.
|
|
8
|
+
*/
|
|
9
|
+
import { AuthCredentialTypes } from '../auth_credential.js';
|
|
10
|
+
import { BaseCredentialExchanger } from './base_credential_exchanger.js';
|
|
11
|
+
/**
|
|
12
|
+
* Registry for credential exchanger instances.
|
|
13
|
+
*/
|
|
14
|
+
export declare class CredentialExchangerRegistry {
|
|
15
|
+
private exchangers;
|
|
16
|
+
/**
|
|
17
|
+
* Register an exchanger instance for a credential type.
|
|
18
|
+
* @param credentialType - The credential type to register for.
|
|
19
|
+
* @param exchangerInstance - The exchanger instance to register.
|
|
20
|
+
*/
|
|
21
|
+
register(credentialType: AuthCredentialTypes, exchangerInstance: BaseCredentialExchanger): void;
|
|
22
|
+
/**
|
|
23
|
+
* Get the exchanger instance for a credential type.
|
|
24
|
+
* @param credentialType - The credential type to get exchanger for.
|
|
25
|
+
* @returns The exchanger instance if registered, undefined otherwise.
|
|
26
|
+
*/
|
|
27
|
+
getExchanger(credentialType: AuthCredentialTypes): BaseCredentialExchanger | undefined;
|
|
28
|
+
}
|
package/dist/types/common.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
export { BaseAgent } from './agents/base_agent.js';
|
|
6
|
+
export { BaseAgent, isBaseAgent } from './agents/base_agent.js';
|
|
7
7
|
export { CallbackContext } from './agents/callback_context.js';
|
|
8
8
|
export { functionsExportedForTestingOnly } from './agents/functions.js';
|
|
9
9
|
export { InvocationContext } from './agents/invocation_context.js';
|
|
@@ -18,12 +18,13 @@ export { StreamingMode } from './agents/run_config.js';
|
|
|
18
18
|
export { SequentialAgent } from './agents/sequential_agent.js';
|
|
19
19
|
export { InMemoryArtifactService } from './artifacts/in_memory_artifact_service.js';
|
|
20
20
|
export type { BaseCredentialService } from './auth/credential_service/base_credential_service.js';
|
|
21
|
+
export { BuiltInCodeExecutor } from './code_executors/built_in_code_executor.js';
|
|
21
22
|
export { createEvent, getFunctionCalls, getFunctionResponses, hasTrailingCodeExecutionResult, isFinalResponse, stringifyContent } from './events/event.js';
|
|
22
23
|
export type { Event } from './events/event.js';
|
|
23
24
|
export type { EventActions } from './events/event_actions.js';
|
|
24
25
|
export { createEventActions } from './events/event_actions.js';
|
|
25
26
|
export { InMemoryMemoryService } from './memory/in_memory_memory_service.js';
|
|
26
|
-
export { BaseLlm } from './models/base_llm.js';
|
|
27
|
+
export { BaseLlm, isBaseLlm } from './models/base_llm.js';
|
|
27
28
|
export type { BaseLlmConnection } from './models/base_llm_connection.js';
|
|
28
29
|
export { Gemini } from './models/google_llm.js';
|
|
29
30
|
export type { GeminiParams } from './models/google_llm.js';
|
|
@@ -6,10 +6,25 @@
|
|
|
6
6
|
import { BaseLlmConnection } from './base_llm_connection.js';
|
|
7
7
|
import { LlmRequest } from './llm_request.js';
|
|
8
8
|
import { LlmResponse } from './llm_response.js';
|
|
9
|
+
/**
|
|
10
|
+
* A unique symbol to identify BaseLlm classes.
|
|
11
|
+
* Defined once and shared by all BaseLlm instances.
|
|
12
|
+
*/
|
|
13
|
+
declare const BASE_MODEL_SYMBOL: unique symbol;
|
|
14
|
+
/**
|
|
15
|
+
* Type guard to check if an object is an instance of BaseLlm.
|
|
16
|
+
* @param obj The object to check.
|
|
17
|
+
* @returns True if the object is an instance of BaseLlm, false otherwise.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isBaseLlm(obj: unknown): obj is BaseLlm;
|
|
9
20
|
/**
|
|
10
21
|
* The BaseLLM class.
|
|
11
22
|
*/
|
|
12
23
|
export declare abstract class BaseLlm {
|
|
24
|
+
/**
|
|
25
|
+
* A unique symbol to identify BaseLlm classes.
|
|
26
|
+
*/
|
|
27
|
+
readonly [BASE_MODEL_SYMBOL] = true;
|
|
13
28
|
readonly model: string;
|
|
14
29
|
/**
|
|
15
30
|
* Creates an instance of BaseLLM.
|
|
@@ -48,3 +63,4 @@ export declare abstract class BaseLlm {
|
|
|
48
63
|
*/
|
|
49
64
|
maybeAppendUserContent(llmRequest: LlmRequest): void;
|
|
50
65
|
}
|
|
66
|
+
export {};
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2025 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
1
|
import { Event } from '../events/event.js';
|
|
7
2
|
import { AppendEventRequest, BaseSessionService, CreateSessionRequest, DeleteSessionRequest, GetSessionRequest, ListSessionsRequest, ListSessionsResponse } from './base_session_service.js';
|
|
8
3
|
import { Session } from './session.js';
|
|
@@ -17,9 +17,9 @@ export declare class State {
|
|
|
17
17
|
static readonly TEMP_PREFIX = "temp:";
|
|
18
18
|
constructor(
|
|
19
19
|
/** The current value of the state. */
|
|
20
|
-
value
|
|
20
|
+
value?: Record<string, unknown>,
|
|
21
21
|
/** The delta change to the current value that hasn't been committed. */
|
|
22
|
-
delta
|
|
22
|
+
delta?: Record<string, unknown>);
|
|
23
23
|
/**
|
|
24
24
|
* Returns the value of the state dict for the given key.
|
|
25
25
|
*
|
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { FunctionDeclaration, Schema } from '@google/genai';
|
|
7
|
-
import { type infer as zInfer, ZodObject } from 'zod';
|
|
7
|
+
import { type infer as zInfer, ZodObject, type ZodRawShape } from 'zod';
|
|
8
8
|
import { BaseTool, RunAsyncToolRequest } from './base_tool.js';
|
|
9
9
|
import { ToolContext } from './tool_context.js';
|
|
10
10
|
/**
|
|
11
11
|
* Input parameters of the function tool.
|
|
12
12
|
*/
|
|
13
|
-
export type ToolInputParameters = undefined | ZodObject<
|
|
14
|
-
export type ToolExecuteArgument<TParameters extends ToolInputParameters> = TParameters extends ZodObject<
|
|
13
|
+
export type ToolInputParameters = undefined | ZodObject<ZodRawShape> | Schema;
|
|
14
|
+
export type ToolExecuteArgument<TParameters extends ToolInputParameters> = TParameters extends ZodObject<infer T, infer U, infer V> ? zInfer<ZodObject<T, U, V>> : TParameters extends Schema ? unknown : string;
|
|
15
15
|
type ToolExecuteFunction<TParameters extends ToolInputParameters> = (input: ToolExecuteArgument<TParameters>, tool_context?: ToolContext) => Promise<unknown> | unknown;
|
|
16
16
|
/**
|
|
17
17
|
* The configuration options for creating a function-based tool.
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
export declare class ToolConfirmation {
|
|
11
11
|
/** The hint text for why the input is needed. */
|
|
12
12
|
hint: string;
|
|
13
|
-
/** Whether the tool
|
|
13
|
+
/** Whether the tool execution is confirmed. */
|
|
14
14
|
confirmed: boolean;
|
|
15
15
|
/**
|
|
16
16
|
* The custom data payload needed from the user to continue the flow.
|
|
@@ -11,12 +11,12 @@ declare const MCPToolSchema: z.ZodObject<{
|
|
|
11
11
|
required: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
12
12
|
}, "strip", z.ZodTypeAny, {
|
|
13
13
|
type: "object";
|
|
14
|
-
required?: string[] | undefined;
|
|
15
14
|
properties?: Record<string, unknown> | undefined;
|
|
15
|
+
required?: string[] | undefined;
|
|
16
16
|
}, {
|
|
17
17
|
type: "object";
|
|
18
|
-
required?: string[] | undefined;
|
|
19
18
|
properties?: Record<string, unknown> | undefined;
|
|
19
|
+
required?: string[] | undefined;
|
|
20
20
|
}>;
|
|
21
21
|
type MCPToolSchema = z.infer<typeof MCPToolSchema>;
|
|
22
22
|
export declare function toGeminiSchema(mcpSchema?: MCPToolSchema): Schema | undefined;
|
package/dist/types/version.d.ts
CHANGED
|
@@ -39,12 +39,22 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
|
|
|
39
39
|
* Copyright 2025 Google LLC
|
|
40
40
|
* SPDX-License-Identifier: Apache-2.0
|
|
41
41
|
*/
|
|
42
|
+
var _a;
|
|
42
43
|
import { trace } from "@opentelemetry/api";
|
|
43
44
|
import { createEvent } from "../events/event.js";
|
|
44
45
|
import { CallbackContext } from "./callback_context.js";
|
|
45
46
|
import { InvocationContext } from "./invocation_context.js";
|
|
47
|
+
const BASE_AGENT_SIGNATURE_SYMBOL = Symbol.for("google.adk.baseAgent");
|
|
48
|
+
function isBaseAgent(obj) {
|
|
49
|
+
return typeof obj === "object" && obj !== null && BASE_AGENT_SIGNATURE_SYMBOL in obj && obj[BASE_AGENT_SIGNATURE_SYMBOL] === true;
|
|
50
|
+
}
|
|
51
|
+
_a = BASE_AGENT_SIGNATURE_SYMBOL;
|
|
46
52
|
class BaseAgent {
|
|
47
53
|
constructor(config) {
|
|
54
|
+
/**
|
|
55
|
+
* A unique symbol to identify ADK agent classes.
|
|
56
|
+
*/
|
|
57
|
+
this[_a] = true;
|
|
48
58
|
this.name = validateAgentName(config.name);
|
|
49
59
|
this.description = config.description;
|
|
50
60
|
this.parentAgent = config.parentAgent;
|
|
@@ -261,5 +271,6 @@ function getCannonicalCallback(callbacks) {
|
|
|
261
271
|
}
|
|
262
272
|
export {
|
|
263
273
|
BaseAgent,
|
|
264
|
-
getCannonicalCallback
|
|
274
|
+
getCannonicalCallback,
|
|
275
|
+
isBaseAgent
|
|
265
276
|
};
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import { cloneDeep } from "lodash";
|
|
6
7
|
import { createEvent, getFunctionCalls, getFunctionResponses } from "../events/event.js";
|
|
7
|
-
import { deepClone } from "../utils/deep_clone.js";
|
|
8
8
|
import { removeClientFunctionCallId, REQUEST_CONFIRMATION_FUNCTION_CALL_NAME, REQUEST_EUC_FUNCTION_CALL_NAME } from "./functions.js";
|
|
9
9
|
function getContents(events, agentName, currentBranch) {
|
|
10
10
|
var _a, _b, _c;
|
|
@@ -30,7 +30,7 @@ function getContents(events, agentName, currentBranch) {
|
|
|
30
30
|
resultEvents = rearrangeEventsForAsyncFunctionResponsesInHistory(resultEvents);
|
|
31
31
|
const contents = [];
|
|
32
32
|
for (const event of resultEvents) {
|
|
33
|
-
const content =
|
|
33
|
+
const content = cloneDeep(event.content);
|
|
34
34
|
removeClientFunctionCallId(content);
|
|
35
35
|
contents.push(content);
|
|
36
36
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { createUserContent } from "@google/genai";
|
|
7
|
+
import { isEmpty } from "lodash";
|
|
7
8
|
import { createEvent, getFunctionCalls } from "../events/event.js";
|
|
8
9
|
import { mergeEventActions } from "../events/event_actions.js";
|
|
9
10
|
import { ToolContext } from "../tools/tool_context.js";
|
|
@@ -13,7 +14,9 @@ const AF_FUNCTION_CALL_ID_PREFIX = "adk-";
|
|
|
13
14
|
const REQUEST_EUC_FUNCTION_CALL_NAME = "adk_request_credential";
|
|
14
15
|
const REQUEST_CONFIRMATION_FUNCTION_CALL_NAME = "adk_request_confirmation";
|
|
15
16
|
const functionsExportedForTestingOnly = {
|
|
16
|
-
handleFunctionCallList
|
|
17
|
+
handleFunctionCallList,
|
|
18
|
+
generateAuthEvent,
|
|
19
|
+
generateRequestConfirmationEvent
|
|
17
20
|
};
|
|
18
21
|
function generateClientFunctionCallId() {
|
|
19
22
|
return "".concat(AF_FUNCTION_CALL_ID_PREFIX).concat(randomUUID());
|
|
@@ -52,7 +55,7 @@ function getLongRunningFunctionCalls(functionCalls, toolsDict) {
|
|
|
52
55
|
}
|
|
53
56
|
function generateAuthEvent(invocationContext, functionResponseEvent) {
|
|
54
57
|
var _a;
|
|
55
|
-
if (!((_a = functionResponseEvent.actions) == null ? void 0 : _a.requestedAuthConfigs)) {
|
|
58
|
+
if (!((_a = functionResponseEvent.actions) == null ? void 0 : _a.requestedAuthConfigs) || isEmpty(functionResponseEvent.actions.requestedAuthConfigs)) {
|
|
56
59
|
return void 0;
|
|
57
60
|
}
|
|
58
61
|
const parts = [];
|
|
@@ -88,7 +91,7 @@ function generateRequestConfirmationEvent({
|
|
|
88
91
|
functionResponseEvent
|
|
89
92
|
}) {
|
|
90
93
|
var _a, _b;
|
|
91
|
-
if (!((_a = functionResponseEvent.actions) == null ? void 0 : _a.requestedToolConfirmations)) {
|
|
94
|
+
if (!((_a = functionResponseEvent.actions) == null ? void 0 : _a.requestedToolConfirmations) || isEmpty(functionResponseEvent.actions.requestedToolConfirmations)) {
|
|
92
95
|
return;
|
|
93
96
|
}
|
|
94
97
|
const parts = [];
|