@google/adk 0.5.0 → 0.6.1
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/README.md +1 -1
- package/dist/cjs/a2a/a2a_event.js +53 -26
- package/dist/cjs/a2a/a2a_remote_agent.js +179 -0
- package/dist/cjs/a2a/a2a_remote_agent_run_processor.js +205 -0
- package/dist/cjs/a2a/a2a_remote_agent_utils.js +165 -0
- package/dist/cjs/a2a/agent_card.js +380 -0
- package/dist/cjs/a2a/agent_executor.js +221 -0
- package/dist/cjs/a2a/agent_to_a2a.js +115 -0
- package/dist/cjs/a2a/event_processor_utils.js +180 -0
- package/dist/cjs/a2a/executor_context.js +1 -1
- package/dist/cjs/a2a/metadata_converter_utils.js +1 -0
- package/dist/cjs/a2a/part_converter_utils.js +24 -13
- package/dist/cjs/agents/llm_agent.js +17 -0
- package/dist/cjs/agents/{content_processor_utils.js → processors/content_processor_utils.js} +21 -2
- package/dist/cjs/agents/processors/content_request_processor.js +24 -3
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +61 -0
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/cjs/artifacts/file_artifact_service.js +35 -4
- package/dist/cjs/common.js +37 -0
- package/dist/cjs/context/base_context_compactor.js +27 -0
- package/dist/cjs/context/summarizers/base_summarizer.js +27 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +93 -0
- package/dist/cjs/context/token_based_context_compactor.js +135 -0
- package/dist/cjs/context/truncating_context_compactor.js +58 -0
- package/dist/cjs/events/compacted_event.js +53 -0
- package/dist/cjs/index.js +38 -14
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/memory/in_memory_memory_service.js +1 -1
- package/dist/cjs/runner/runner.js +19 -10
- package/dist/cjs/sessions/db/operations.js +4 -14
- package/dist/cjs/sessions/state.js +2 -2
- package/dist/cjs/tools/agent_tool.js +6 -5
- package/dist/cjs/tools/load_artifacts_tool.js +188 -0
- package/dist/cjs/tools/load_memory_tool.js +107 -0
- package/dist/cjs/tools/preload_memory_tool.js +109 -0
- package/dist/cjs/utils/gemini_schema_util.js +54 -12
- package/dist/cjs/utils/logger.js +1 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_event.js +52 -26
- package/dist/esm/a2a/a2a_remote_agent.js +153 -0
- package/dist/esm/a2a/a2a_remote_agent_run_processor.js +182 -0
- package/dist/esm/a2a/a2a_remote_agent_utils.js +131 -0
- package/dist/esm/a2a/agent_card.js +340 -0
- package/dist/esm/a2a/agent_executor.js +202 -0
- package/dist/esm/a2a/agent_to_a2a.js +80 -0
- package/dist/esm/a2a/event_processor_utils.js +159 -0
- package/dist/esm/a2a/executor_context.js +1 -1
- package/dist/esm/a2a/metadata_converter_utils.js +1 -0
- package/dist/esm/a2a/part_converter_utils.js +24 -13
- package/dist/esm/agents/llm_agent.js +17 -0
- package/dist/esm/agents/{content_processor_utils.js → processors/content_processor_utils.js} +23 -2
- package/dist/esm/agents/processors/content_request_processor.js +25 -4
- package/dist/esm/agents/processors/context_compactor_request_processor.js +31 -0
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/esm/artifacts/file_artifact_service.js +30 -3
- package/dist/esm/common.js +33 -1
- package/dist/esm/context/base_context_compactor.js +5 -0
- package/dist/esm/context/summarizers/base_summarizer.js +5 -0
- package/dist/esm/context/summarizers/llm_summarizer.js +65 -0
- package/dist/esm/context/token_based_context_compactor.js +105 -0
- package/dist/esm/context/truncating_context_compactor.js +28 -0
- package/dist/esm/events/compacted_event.js +22 -0
- package/dist/esm/index.js +38 -14
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/memory/in_memory_memory_service.js +1 -1
- package/dist/esm/runner/runner.js +17 -9
- package/dist/esm/sessions/db/operations.js +4 -14
- package/dist/esm/sessions/state.js +2 -2
- package/dist/esm/tools/agent_tool.js +6 -5
- package/dist/esm/tools/load_artifacts_tool.js +159 -0
- package/dist/esm/tools/load_memory_tool.js +78 -0
- package/dist/esm/tools/preload_memory_tool.js +80 -0
- package/dist/esm/utils/gemini_schema_util.js +54 -12
- package/dist/esm/utils/logger.js +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_event.d.ts +23 -6
- package/dist/types/a2a/a2a_remote_agent.d.ts +67 -0
- package/dist/types/a2a/a2a_remote_agent_run_processor.d.ts +31 -0
- package/dist/types/a2a/a2a_remote_agent_utils.d.ts +38 -0
- package/dist/types/a2a/agent_card.d.ts +23 -0
- package/dist/types/a2a/agent_executor.d.ts +52 -0
- package/dist/types/a2a/agent_to_a2a.d.ts +45 -0
- package/dist/types/a2a/event_processor_utils.d.ts +24 -0
- package/dist/types/a2a/executor_context.d.ts +1 -1
- package/dist/types/a2a/metadata_converter_utils.d.ts +2 -1
- package/dist/types/agents/llm_agent.d.ts +6 -0
- package/dist/types/agents/loop_agent.d.ts +1 -1
- package/dist/types/agents/{content_processor_utils.d.ts → processors/content_processor_utils.d.ts} +1 -1
- package/dist/types/agents/processors/context_compactor_request_processor.d.ts +22 -0
- package/dist/types/artifacts/file_artifact_service.d.ts +4 -0
- package/dist/types/common.d.ts +16 -1
- package/dist/types/context/base_context_compactor.d.ts +24 -0
- package/dist/types/context/summarizers/base_summarizer.d.ts +19 -0
- package/dist/types/context/summarizers/llm_summarizer.d.ts +23 -0
- package/dist/types/context/token_based_context_compactor.d.ts +33 -0
- package/dist/types/context/truncating_context_compactor.d.ts +24 -0
- package/dist/types/events/compacted_event.d.ts +33 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/runner/runner.d.ts +13 -0
- package/dist/types/sessions/db/operations.d.ts +2 -3
- package/dist/types/tools/load_artifacts_tool.d.ts +21 -0
- package/dist/types/tools/load_memory_tool.d.ts +22 -0
- package/dist/types/tools/preload_memory_tool.d.ts +23 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/a2a_event.js +52 -26
- package/dist/web/a2a/a2a_remote_agent.js +184 -0
- package/dist/web/a2a/a2a_remote_agent_run_processor.js +182 -0
- package/dist/web/a2a/a2a_remote_agent_utils.js +131 -0
- package/dist/web/a2a/agent_card.js +340 -0
- package/dist/web/a2a/agent_executor.js +216 -0
- package/dist/web/a2a/agent_to_a2a.js +80 -0
- package/dist/web/a2a/event_processor_utils.js +168 -0
- package/dist/web/a2a/executor_context.js +1 -1
- package/dist/web/a2a/metadata_converter_utils.js +1 -0
- package/dist/web/a2a/part_converter_utils.js +24 -13
- package/dist/web/agents/llm_agent.js +17 -0
- package/dist/web/agents/{content_processor_utils.js → processors/content_processor_utils.js} +22 -2
- package/dist/web/agents/processors/content_request_processor.js +25 -4
- package/dist/web/agents/processors/context_compactor_request_processor.js +49 -0
- package/dist/web/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/web/artifacts/file_artifact_service.js +30 -3
- package/dist/web/common.js +33 -1
- package/dist/web/context/base_context_compactor.js +5 -0
- package/dist/web/context/summarizers/base_summarizer.js +5 -0
- package/dist/web/context/summarizers/llm_summarizer.js +74 -0
- package/dist/web/context/token_based_context_compactor.js +105 -0
- package/dist/web/context/truncating_context_compactor.js +28 -0
- package/dist/web/events/compacted_event.js +40 -0
- package/dist/web/index.js +1 -1
- package/dist/web/index.js.map +4 -4
- package/dist/web/memory/in_memory_memory_service.js +1 -1
- package/dist/web/runner/runner.js +17 -9
- package/dist/web/sessions/db/operations.js +4 -14
- package/dist/web/sessions/state.js +2 -2
- package/dist/web/tools/agent_tool.js +6 -5
- package/dist/web/tools/load_artifacts_tool.js +150 -0
- package/dist/web/tools/load_memory_tool.js +77 -0
- package/dist/web/tools/preload_memory_tool.js +75 -0
- package/dist/web/utils/gemini_schema_util.js +85 -12
- package/dist/web/utils/logger.js +1 -0
- package/dist/web/version.js +1 -1
- package/package.json +7 -5
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var a2a_remote_agent_utils_exports = {};
|
|
26
|
+
__export(a2a_remote_agent_utils_exports, {
|
|
27
|
+
getFunctionResponseCallId: () => getFunctionResponseCallId,
|
|
28
|
+
getUserFunctionCallAt: () => getUserFunctionCallAt,
|
|
29
|
+
isFunctionCallEvent: () => isFunctionCallEvent,
|
|
30
|
+
presentAsUserMessage: () => presentAsUserMessage,
|
|
31
|
+
toMissingRemoteSessionParts: () => toMissingRemoteSessionParts
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(a2a_remote_agent_utils_exports);
|
|
34
|
+
var import_event = require("../events/event.js");
|
|
35
|
+
var import_metadata_converter_utils = require("./metadata_converter_utils.js");
|
|
36
|
+
var import_part_converter_utils = require("./part_converter_utils.js");
|
|
37
|
+
/**
|
|
38
|
+
* @license
|
|
39
|
+
* Copyright 2026 Google LLC
|
|
40
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
41
|
+
*/
|
|
42
|
+
function getUserFunctionCallAt(session, index) {
|
|
43
|
+
const events = session.events;
|
|
44
|
+
if (index < 0 || index >= events.length) {
|
|
45
|
+
return void 0;
|
|
46
|
+
}
|
|
47
|
+
const candidate = events[index];
|
|
48
|
+
if (candidate.author !== "user") {
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
const fnCallId = getFunctionResponseCallId(candidate);
|
|
52
|
+
if (!fnCallId) {
|
|
53
|
+
return void 0;
|
|
54
|
+
}
|
|
55
|
+
for (let i = index - 1; i >= 0; i--) {
|
|
56
|
+
const request = events[i];
|
|
57
|
+
if (!isFunctionCallEvent(request, fnCallId)) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const metadata = request.customMetadata || {};
|
|
61
|
+
const taskId = metadata[import_metadata_converter_utils.AdkMetadataKeys.TASK_ID] || "";
|
|
62
|
+
const contextId = metadata[import_metadata_converter_utils.AdkMetadataKeys.CONTEXT_ID] || "";
|
|
63
|
+
return {
|
|
64
|
+
response: candidate,
|
|
65
|
+
taskId,
|
|
66
|
+
contextId
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
function isFunctionCallEvent(event, callId) {
|
|
72
|
+
if (!event || !event.content || !event.content.parts) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
return event.content.parts.some(
|
|
76
|
+
(part) => part.functionCall && part.functionCall.id === callId
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
function getFunctionResponseCallId(event) {
|
|
80
|
+
var _a;
|
|
81
|
+
if (!event || !event.content || !event.content.parts) {
|
|
82
|
+
return void 0;
|
|
83
|
+
}
|
|
84
|
+
const responsePart = event.content.parts.find(
|
|
85
|
+
(part) => part.functionResponse
|
|
86
|
+
);
|
|
87
|
+
return (_a = responsePart == null ? void 0 : responsePart.functionResponse) == null ? void 0 : _a.id;
|
|
88
|
+
}
|
|
89
|
+
function toMissingRemoteSessionParts(ctx, session) {
|
|
90
|
+
const events = session.events;
|
|
91
|
+
let contextId = void 0;
|
|
92
|
+
let lastRemoteResponseIndex = -1;
|
|
93
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
94
|
+
const event = events[i];
|
|
95
|
+
if (event.author === ctx.agent.name) {
|
|
96
|
+
lastRemoteResponseIndex = i;
|
|
97
|
+
const metadata = event.customMetadata || {};
|
|
98
|
+
contextId = metadata[import_metadata_converter_utils.AdkMetadataKeys.CONTEXT_ID];
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const missingParts = [];
|
|
103
|
+
for (let i = lastRemoteResponseIndex + 1; i < events.length; i++) {
|
|
104
|
+
let event = events[i];
|
|
105
|
+
if (event.author !== "user" && event.author !== ctx.agent.name) {
|
|
106
|
+
event = presentAsUserMessage(ctx, event);
|
|
107
|
+
}
|
|
108
|
+
if (!event.content || !event.content.parts || event.content.parts.length === 0) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const parts = (0, import_part_converter_utils.toA2AParts)(event.content.parts, event.longRunningToolIds);
|
|
112
|
+
missingParts.push(...parts);
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
parts: missingParts,
|
|
116
|
+
contextId
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function presentAsUserMessage(ctx, agentEvent) {
|
|
120
|
+
const event = (0, import_event.createEvent)({
|
|
121
|
+
author: "user",
|
|
122
|
+
invocationId: ctx.invocationId
|
|
123
|
+
});
|
|
124
|
+
if (!agentEvent.content || !agentEvent.content.parts) {
|
|
125
|
+
return event;
|
|
126
|
+
}
|
|
127
|
+
const parts = [{ text: "For context:" }];
|
|
128
|
+
for (const part of agentEvent.content.parts) {
|
|
129
|
+
if (part.thought) {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (part.text) {
|
|
133
|
+
parts.push({
|
|
134
|
+
text: `[${agentEvent.author}] said: ${part.text}`
|
|
135
|
+
});
|
|
136
|
+
} else if (part.functionCall) {
|
|
137
|
+
const call = part.functionCall;
|
|
138
|
+
parts.push({
|
|
139
|
+
text: `[${agentEvent.author}] called tool ${call.name} with parameters: ${JSON.stringify(call.args)}`
|
|
140
|
+
});
|
|
141
|
+
} else if (part.functionResponse) {
|
|
142
|
+
const resp = part.functionResponse;
|
|
143
|
+
parts.push({
|
|
144
|
+
text: `[${agentEvent.author}] ${resp.name} tool returned result: ${JSON.stringify(resp.response)}`
|
|
145
|
+
});
|
|
146
|
+
} else {
|
|
147
|
+
parts.push(part);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (parts.length > 1) {
|
|
151
|
+
event.content = {
|
|
152
|
+
role: "user",
|
|
153
|
+
parts
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return event;
|
|
157
|
+
}
|
|
158
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
159
|
+
0 && (module.exports = {
|
|
160
|
+
getFunctionResponseCallId,
|
|
161
|
+
getUserFunctionCallAt,
|
|
162
|
+
isFunctionCallEvent,
|
|
163
|
+
presentAsUserMessage,
|
|
164
|
+
toMissingRemoteSessionParts
|
|
165
|
+
});
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __create = Object.create;
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
11
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
12
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
27
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
29
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
31
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
32
|
+
mod
|
|
33
|
+
));
|
|
34
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
|
+
var agent_card_exports = {};
|
|
36
|
+
__export(agent_card_exports, {
|
|
37
|
+
buildAgentSkills: () => buildAgentSkills,
|
|
38
|
+
getA2AAgentCard: () => getA2AAgentCard,
|
|
39
|
+
resolveAgentCard: () => resolveAgentCard
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(agent_card_exports);
|
|
42
|
+
var import_client = require("@a2a-js/sdk/client");
|
|
43
|
+
var fs = __toESM(require("node:fs/promises"), 1);
|
|
44
|
+
var import_invocation_context = require("../agents/invocation_context.js");
|
|
45
|
+
var import_llm_agent = require("../agents/llm_agent.js");
|
|
46
|
+
var import_loop_agent = require("../agents/loop_agent.js");
|
|
47
|
+
var import_parallel_agent = require("../agents/parallel_agent.js");
|
|
48
|
+
var import_readonly_context = require("../agents/readonly_context.js");
|
|
49
|
+
var import_sequential_agent = require("../agents/sequential_agent.js");
|
|
50
|
+
var import_base_tool = require("../tools/base_tool.js");
|
|
51
|
+
var import_base_toolset = require("../tools/base_toolset.js");
|
|
52
|
+
var import_logger = require("../utils/logger.js");
|
|
53
|
+
/**
|
|
54
|
+
* @license
|
|
55
|
+
* Copyright 2026 Google LLC
|
|
56
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
57
|
+
*/
|
|
58
|
+
async function resolveAgentCard(agentCard) {
|
|
59
|
+
if (typeof agentCard === "object") {
|
|
60
|
+
return agentCard;
|
|
61
|
+
}
|
|
62
|
+
const source = agentCard;
|
|
63
|
+
if (source.startsWith("http://") || source.startsWith("https://")) {
|
|
64
|
+
const resolver = new import_client.DefaultAgentCardResolver();
|
|
65
|
+
return await resolver.resolve(source);
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
const content = await fs.readFile(source, "utf-8");
|
|
69
|
+
return JSON.parse(content);
|
|
70
|
+
} catch (err) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
`Failed to read agent card from file ${source}: ${err.message}`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async function getA2AAgentCard(agent, transports) {
|
|
77
|
+
return {
|
|
78
|
+
name: agent.name,
|
|
79
|
+
description: agent.description || "",
|
|
80
|
+
protocolVersion: "0.3.0",
|
|
81
|
+
version: "1.0.0",
|
|
82
|
+
skills: await buildAgentSkills(agent),
|
|
83
|
+
url: transports[0].url,
|
|
84
|
+
preferredTransport: transports[0].transport,
|
|
85
|
+
capabilities: {
|
|
86
|
+
extensions: [],
|
|
87
|
+
stateTransitionHistory: false,
|
|
88
|
+
pushNotifications: false,
|
|
89
|
+
streaming: true
|
|
90
|
+
},
|
|
91
|
+
defaultInputModes: ["text"],
|
|
92
|
+
defaultOutputModes: ["text"],
|
|
93
|
+
additionalInterfaces: transports
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
async function buildAgentSkills(agent) {
|
|
97
|
+
const [primarySkills, subAgentSkills] = await Promise.all([
|
|
98
|
+
buildPrimarySkills(agent),
|
|
99
|
+
buildSubAgentSkills(agent)
|
|
100
|
+
]);
|
|
101
|
+
return [...primarySkills, ...subAgentSkills];
|
|
102
|
+
}
|
|
103
|
+
async function buildPrimarySkills(agent) {
|
|
104
|
+
if ((0, import_llm_agent.isLlmAgent)(agent)) {
|
|
105
|
+
return buildLLMAgentSkills(agent);
|
|
106
|
+
}
|
|
107
|
+
return buildNonLLMAgentSkills(agent);
|
|
108
|
+
}
|
|
109
|
+
async function buildSubAgentSkills(agent) {
|
|
110
|
+
const subAgents = agent.subAgents;
|
|
111
|
+
const result = [];
|
|
112
|
+
for (const sub of subAgents) {
|
|
113
|
+
const skills = await buildPrimarySkills(sub);
|
|
114
|
+
for (const subSkill of skills) {
|
|
115
|
+
const skill = {
|
|
116
|
+
id: `${sub.name}_${subSkill.id}`,
|
|
117
|
+
name: `${sub.name}: ${subSkill.name}`,
|
|
118
|
+
description: subSkill.description,
|
|
119
|
+
tags: [`sub_agent:${sub.name}`, ...subSkill.tags]
|
|
120
|
+
};
|
|
121
|
+
result.push(skill);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
async function buildLLMAgentSkills(agent) {
|
|
127
|
+
const skills = [
|
|
128
|
+
{
|
|
129
|
+
id: agent.name,
|
|
130
|
+
name: "model",
|
|
131
|
+
description: await buildDescriptionFromInstructions(agent),
|
|
132
|
+
tags: ["llm"]
|
|
133
|
+
}
|
|
134
|
+
];
|
|
135
|
+
if (agent.tools && agent.tools.length > 0) {
|
|
136
|
+
for (const toolUnion of agent.tools) {
|
|
137
|
+
if ((0, import_base_tool.isBaseTool)(toolUnion)) {
|
|
138
|
+
skills.push(toolToSkill(agent.name, toolUnion));
|
|
139
|
+
} else if ((0, import_base_toolset.isBaseToolset)(toolUnion)) {
|
|
140
|
+
const tools = await toolUnion.getTools();
|
|
141
|
+
for (const tool of tools) {
|
|
142
|
+
skills.push(toolToSkill(agent.name, tool));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return skills;
|
|
148
|
+
}
|
|
149
|
+
function toolToSkill(prefix, tool) {
|
|
150
|
+
let description = tool.description;
|
|
151
|
+
if (!description) {
|
|
152
|
+
description = `Tool: ${tool.name}`;
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
id: `${prefix}-${tool.name}`,
|
|
156
|
+
name: tool.name,
|
|
157
|
+
description,
|
|
158
|
+
tags: ["llm", "tools"]
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function buildNonLLMAgentSkills(agent) {
|
|
162
|
+
const skills = [
|
|
163
|
+
{
|
|
164
|
+
id: agent.name,
|
|
165
|
+
name: getAgentSkillName(agent),
|
|
166
|
+
description: buildAgentDescription(agent),
|
|
167
|
+
tags: [getAgentTypeTag(agent)]
|
|
168
|
+
}
|
|
169
|
+
];
|
|
170
|
+
const subAgents = agent.subAgents;
|
|
171
|
+
if (subAgents.length > 0) {
|
|
172
|
+
const descriptions = subAgents.map(
|
|
173
|
+
(sub) => sub.description || "No description"
|
|
174
|
+
);
|
|
175
|
+
skills.push({
|
|
176
|
+
id: `${agent.name}-sub-agents`,
|
|
177
|
+
name: "sub-agents",
|
|
178
|
+
description: `Orchestrates: ${descriptions.join("; ")}`,
|
|
179
|
+
tags: [getAgentTypeTag(agent), "orchestration"]
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
return skills;
|
|
183
|
+
}
|
|
184
|
+
function buildAgentDescription(agent) {
|
|
185
|
+
const descriptionParts = [];
|
|
186
|
+
if (agent.description) {
|
|
187
|
+
descriptionParts.push(agent.description);
|
|
188
|
+
}
|
|
189
|
+
if (agent.subAgents.length > 0) {
|
|
190
|
+
if ((0, import_loop_agent.isLoopAgent)(agent)) {
|
|
191
|
+
descriptionParts.push(buildLoopAgentDescription(agent));
|
|
192
|
+
} else if ((0, import_parallel_agent.isParallelAgent)(agent)) {
|
|
193
|
+
descriptionParts.push(buildParallelAgentDescription(agent));
|
|
194
|
+
} else if ((0, import_sequential_agent.isSequentialAgent)(agent)) {
|
|
195
|
+
descriptionParts.push(buildSequentialAgentDescription(agent));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (descriptionParts.length > 0) {
|
|
199
|
+
return descriptionParts.join(" ");
|
|
200
|
+
} else {
|
|
201
|
+
return getDefaultAgentDescription(agent);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function buildSequentialAgentDescription(agent) {
|
|
205
|
+
const subAgents = agent.subAgents;
|
|
206
|
+
const descriptions = [];
|
|
207
|
+
subAgents.forEach((sub, i) => {
|
|
208
|
+
let subDescription = sub.description;
|
|
209
|
+
if (!subDescription) {
|
|
210
|
+
subDescription = `execute the ${sub.name} agent`;
|
|
211
|
+
}
|
|
212
|
+
if (i === 0) {
|
|
213
|
+
descriptions.push(`First, this agent will ${subDescription}.`);
|
|
214
|
+
} else if (i === subAgents.length - 1) {
|
|
215
|
+
descriptions.push(`Finally, this agent will ${subDescription}.`);
|
|
216
|
+
} else {
|
|
217
|
+
descriptions.push(`Then, this agent will ${subDescription}.`);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
return descriptions.join(" ");
|
|
221
|
+
}
|
|
222
|
+
function buildParallelAgentDescription(agent) {
|
|
223
|
+
const subAgents = agent.subAgents;
|
|
224
|
+
const descriptions = [];
|
|
225
|
+
subAgents.forEach((sub, i) => {
|
|
226
|
+
let subDescription = sub.description;
|
|
227
|
+
if (!subDescription) {
|
|
228
|
+
subDescription = `execute the ${sub.name} agent`;
|
|
229
|
+
}
|
|
230
|
+
if (i === 0) {
|
|
231
|
+
descriptions.push(`This agent will ${subDescription}`);
|
|
232
|
+
} else if (i === subAgents.length - 1) {
|
|
233
|
+
descriptions.push(`and ${subDescription}`);
|
|
234
|
+
} else {
|
|
235
|
+
descriptions.push(`, ${subDescription}`);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
return `${descriptions.join(" ")} simultaneously.`;
|
|
239
|
+
}
|
|
240
|
+
function buildLoopAgentDescription(agent) {
|
|
241
|
+
const maxIterationsVal = agent.maxIterations;
|
|
242
|
+
let maxIterations = "unlimited";
|
|
243
|
+
if (typeof maxIterationsVal === "number" && maxIterationsVal < Number.MAX_SAFE_INTEGER) {
|
|
244
|
+
maxIterations = maxIterationsVal.toString();
|
|
245
|
+
}
|
|
246
|
+
const subAgents = agent.subAgents;
|
|
247
|
+
const descriptions = [];
|
|
248
|
+
subAgents.forEach((sub, i) => {
|
|
249
|
+
let subDescription = sub.description;
|
|
250
|
+
if (!subDescription) {
|
|
251
|
+
subDescription = `execute the ${sub.name} agent`;
|
|
252
|
+
}
|
|
253
|
+
if (i === 0) {
|
|
254
|
+
descriptions.push(`This agent will ${subDescription}`);
|
|
255
|
+
} else if (i === subAgents.length - 1) {
|
|
256
|
+
descriptions.push(`and ${subDescription}`);
|
|
257
|
+
} else {
|
|
258
|
+
descriptions.push(`, ${subDescription}`);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
return `${descriptions.join(" ")} in a loop (max ${maxIterations} iterations).`;
|
|
262
|
+
}
|
|
263
|
+
async function buildDescriptionFromInstructions(agent) {
|
|
264
|
+
const descriptionParts = [];
|
|
265
|
+
if (agent.description) {
|
|
266
|
+
descriptionParts.push(agent.description);
|
|
267
|
+
}
|
|
268
|
+
if (agent.instruction) {
|
|
269
|
+
let instructionStr;
|
|
270
|
+
if (typeof agent.instruction === "function") {
|
|
271
|
+
const dummyContext = new import_readonly_context.ReadonlyContext(
|
|
272
|
+
new import_invocation_context.InvocationContext({
|
|
273
|
+
agent
|
|
274
|
+
})
|
|
275
|
+
);
|
|
276
|
+
try {
|
|
277
|
+
instructionStr = await agent.instruction(dummyContext);
|
|
278
|
+
} catch (e) {
|
|
279
|
+
import_logger.logger.warn("Failed to resolve dynamic instruction for AgentCard", e);
|
|
280
|
+
instructionStr = "";
|
|
281
|
+
}
|
|
282
|
+
} else {
|
|
283
|
+
instructionStr = agent.instruction;
|
|
284
|
+
}
|
|
285
|
+
if (instructionStr) {
|
|
286
|
+
descriptionParts.push(replacePronouns(instructionStr));
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
const root = agent.rootAgent;
|
|
290
|
+
if ((0, import_llm_agent.isLlmAgent)(root) && root.globalInstruction) {
|
|
291
|
+
let globalInstructionStr;
|
|
292
|
+
if (typeof root.globalInstruction === "function") {
|
|
293
|
+
const dummyContext = new import_readonly_context.ReadonlyContext(
|
|
294
|
+
new import_invocation_context.InvocationContext({
|
|
295
|
+
agent
|
|
296
|
+
})
|
|
297
|
+
);
|
|
298
|
+
try {
|
|
299
|
+
globalInstructionStr = await root.globalInstruction(dummyContext);
|
|
300
|
+
} catch (e) {
|
|
301
|
+
import_logger.logger.warn(
|
|
302
|
+
"Failed to resolve dynamic global instruction for AgentCard",
|
|
303
|
+
e
|
|
304
|
+
);
|
|
305
|
+
globalInstructionStr = "";
|
|
306
|
+
}
|
|
307
|
+
} else {
|
|
308
|
+
globalInstructionStr = root.globalInstruction;
|
|
309
|
+
}
|
|
310
|
+
if (globalInstructionStr) {
|
|
311
|
+
descriptionParts.push(replacePronouns(globalInstructionStr));
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if (descriptionParts.length > 0) {
|
|
315
|
+
return descriptionParts.join(" ");
|
|
316
|
+
} else {
|
|
317
|
+
return getDefaultAgentDescription(agent);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function replacePronouns(instruction) {
|
|
321
|
+
const substitutions = [
|
|
322
|
+
{ original: "you were", target: "I was" },
|
|
323
|
+
{ original: "you are", target: "I am" },
|
|
324
|
+
{ original: "you're", target: "I am" },
|
|
325
|
+
{ original: "you've", target: "I have" },
|
|
326
|
+
{ original: "yours", target: "mine" },
|
|
327
|
+
{ original: "your", target: "my" },
|
|
328
|
+
{ original: "you", target: "I" }
|
|
329
|
+
];
|
|
330
|
+
let result = instruction;
|
|
331
|
+
for (const sub of substitutions) {
|
|
332
|
+
const pattern = new RegExp(`\\b${sub.original}\\b`, "gi");
|
|
333
|
+
result = result.replace(pattern, sub.target);
|
|
334
|
+
}
|
|
335
|
+
return result;
|
|
336
|
+
}
|
|
337
|
+
function getDefaultAgentDescription(agent) {
|
|
338
|
+
if ((0, import_loop_agent.isLoopAgent)(agent)) {
|
|
339
|
+
return "A loop workflow agent";
|
|
340
|
+
} else if ((0, import_sequential_agent.isSequentialAgent)(agent)) {
|
|
341
|
+
return "A sequential workflow agent";
|
|
342
|
+
} else if ((0, import_parallel_agent.isParallelAgent)(agent)) {
|
|
343
|
+
return "A parallel workflow agent";
|
|
344
|
+
} else if ((0, import_llm_agent.isLlmAgent)(agent)) {
|
|
345
|
+
return "An LLM-based agent";
|
|
346
|
+
} else {
|
|
347
|
+
return "A custom agent";
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
function getAgentTypeTag(agent) {
|
|
351
|
+
if ((0, import_loop_agent.isLoopAgent)(agent)) {
|
|
352
|
+
return "loop_workflow";
|
|
353
|
+
} else if ((0, import_sequential_agent.isSequentialAgent)(agent)) {
|
|
354
|
+
return "sequential_workflow";
|
|
355
|
+
} else if ((0, import_parallel_agent.isParallelAgent)(agent)) {
|
|
356
|
+
return "parallel_workflow";
|
|
357
|
+
} else if ((0, import_llm_agent.isLlmAgent)(agent)) {
|
|
358
|
+
return "llm_agent";
|
|
359
|
+
} else {
|
|
360
|
+
return "custom_agent";
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
function getAgentSkillName(agent) {
|
|
364
|
+
if ((0, import_llm_agent.isLlmAgent)(agent)) {
|
|
365
|
+
return "model";
|
|
366
|
+
}
|
|
367
|
+
if (isWorkflowAgent(agent)) {
|
|
368
|
+
return "workflow";
|
|
369
|
+
}
|
|
370
|
+
return "custom";
|
|
371
|
+
}
|
|
372
|
+
function isWorkflowAgent(agent) {
|
|
373
|
+
return (0, import_loop_agent.isLoopAgent)(agent) || (0, import_sequential_agent.isSequentialAgent)(agent) || (0, import_parallel_agent.isParallelAgent)(agent);
|
|
374
|
+
}
|
|
375
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
376
|
+
0 && (module.exports = {
|
|
377
|
+
buildAgentSkills,
|
|
378
|
+
getA2AAgentCard,
|
|
379
|
+
resolveAgentCard
|
|
380
|
+
});
|