@inkeep/agents-run-api 0.0.0-dev-20260113172432 → 0.0.0-dev-20260115183047
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 +2 -1
- package/dist/a2a/client.d.ts +3 -1
- package/dist/a2a/client.js +23 -9
- package/dist/a2a/handlers.js +11 -5
- package/dist/a2a/transfer.d.ts +6 -1
- package/dist/a2a/transfer.js +10 -6
- package/dist/agents/Agent.d.ts +8 -4
- package/dist/agents/Agent.js +226 -92
- package/dist/agents/ToolSessionManager.js +2 -2
- package/dist/agents/generateTaskHandler.d.ts +4 -9
- package/dist/agents/generateTaskHandler.js +107 -246
- package/dist/agents/relationTools.d.ts +19 -8
- package/dist/agents/relationTools.js +105 -14
- package/dist/agents/types.d.ts +4 -2
- package/dist/agents/versions/v1/Phase1Config.d.ts +4 -3
- package/dist/agents/versions/v1/Phase1Config.js +33 -20
- package/dist/constants/execution-limits/index.js +1 -1
- package/dist/context/ContextFetcher.d.ts +68 -0
- package/dist/context/ContextFetcher.js +276 -0
- package/dist/context/ContextResolver.d.ts +56 -0
- package/dist/context/ContextResolver.js +273 -0
- package/dist/context/context.d.ts +19 -0
- package/dist/context/context.js +108 -0
- package/dist/context/contextCache.d.ts +56 -0
- package/dist/context/contextCache.js +175 -0
- package/dist/context/index.d.ts +6 -0
- package/dist/context/index.js +7 -0
- package/dist/context/validation.d.ts +39 -0
- package/dist/context/validation.js +255 -0
- package/dist/create-app.d.ts +2 -2
- package/dist/create-app.js +7 -2
- package/dist/data/agent.d.ts +2 -2
- package/dist/data/agent.js +17 -22
- package/dist/data/agents.d.ts +2 -2
- package/dist/data/agents.js +34 -42
- package/dist/data/conversations.d.ts +2 -1
- package/dist/data/conversations.js +7 -8
- package/dist/data/db/dbClient.d.ts +2 -2
- package/dist/data/db/dbClient.js +2 -10
- package/dist/env.d.ts +6 -2
- package/dist/env.js +3 -1
- package/dist/handlers/executionHandler.d.ts +3 -2
- package/dist/handlers/executionHandler.js +46 -22
- package/dist/index.d.ts +3 -3
- package/dist/middleware/api-key-auth.d.ts +4 -10
- package/dist/middleware/api-key-auth.js +164 -163
- package/dist/middleware/index.d.ts +3 -2
- package/dist/middleware/index.js +3 -2
- package/dist/middleware/projectConfig.d.ts +19 -0
- package/dist/middleware/projectConfig.js +80 -0
- package/dist/routes/agents.d.ts +2 -1
- package/dist/routes/agents.js +7 -13
- package/dist/routes/chat.d.ts +2 -1
- package/dist/routes/chat.js +29 -52
- package/dist/routes/chatDataStream.d.ts +2 -1
- package/dist/routes/chatDataStream.js +28 -30
- package/dist/routes/mcp.d.ts +2 -1
- package/dist/routes/mcp.js +25 -37
- package/dist/services/AgentSession.d.ts +5 -7
- package/dist/services/AgentSession.js +25 -34
- package/dist/services/ArtifactParser.d.ts +2 -2
- package/dist/services/ArtifactParser.js +2 -2
- package/dist/services/ArtifactService.d.ts +2 -3
- package/dist/services/ArtifactService.js +23 -20
- package/dist/services/BaseCompressor.js +2 -2
- package/dist/services/IncrementalStreamParser.d.ts +2 -2
- package/dist/services/IncrementalStreamParser.js +2 -2
- package/dist/services/ResponseFormatter.d.ts +2 -2
- package/dist/services/ResponseFormatter.js +2 -2
- package/dist/services/evaluationHttpClient.d.ts +21 -0
- package/dist/services/evaluationHttpClient.js +48 -0
- package/dist/services/evaluationRunConfigMatcher.d.ts +6 -0
- package/dist/services/evaluationRunConfigMatcher.js +7 -0
- package/dist/tools/NativeSandboxExecutor.js +1 -1
- package/dist/tools/distill-conversation-history-tool.js +2 -2
- package/dist/tools/distill-conversation-tool.js +2 -2
- package/dist/types/execution-context.d.ts +8 -14
- package/dist/types/execution-context.js +3 -2
- package/dist/utils/model-resolver.d.ts +2 -2
- package/dist/utils/model-resolver.js +3 -13
- package/dist/utils/project.d.ts +207 -0
- package/dist/utils/project.js +315 -0
- package/dist/utils/token-estimator.d.ts +6 -52
- package/dist/utils/token-estimator.js +2 -38
- package/package.json +2 -2
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { env } from "../env.js";
|
|
2
|
+
import { getLogger as getLogger$1 } from "../logger.js";
|
|
3
|
+
import { getUserIdFromContext } from "../types/execution-context.js";
|
|
3
4
|
import { toolSessionManager } from "./ToolSessionManager.js";
|
|
4
5
|
import { agentSessionManager } from "../services/AgentSession.js";
|
|
5
6
|
import { resolveModelConfig } from "../utils/model-resolver.js";
|
|
7
|
+
import { enhanceInternalRelation, enhanceTeamRelation, getArtifactComponentsForSubAgent, getDataComponentsForSubAgent, getSubAgentRelations, getToolsForSubAgent } from "../utils/project.js";
|
|
8
|
+
import { buildTransferRelationConfig } from "./relationTools.js";
|
|
6
9
|
import { Agent } from "./Agent.js";
|
|
7
|
-
import {
|
|
8
|
-
import { TaskState, dbResultToMcpTool, generateId, getAgentById, getAgentWithDefaultSubAgent, getArtifactComponentsForAgent, getDataComponentsForAgent, getExternalAgentsForSubAgent, getRelatedAgentsForAgent, getSubAgentById, getTeamAgentsForSubAgent, getToolsForAgent } from "@inkeep/agents-core";
|
|
10
|
+
import { InternalServices, ManagementApiClient, TaskState, generateId } from "@inkeep/agents-core";
|
|
9
11
|
|
|
10
12
|
//#region src/agents/generateTaskHandler.ts
|
|
11
|
-
const logger = getLogger("generateTaskHandler");
|
|
13
|
+
const logger = getLogger$1("generateTaskHandler");
|
|
12
14
|
const createTaskHandler = (config, credentialStoreRegistry) => {
|
|
13
15
|
return async (task) => {
|
|
14
16
|
let agent;
|
|
@@ -22,141 +24,81 @@ const createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
22
24
|
artifacts: []
|
|
23
25
|
};
|
|
24
26
|
const forwardedHeaders = task.context?.metadata?.forwardedHeaders;
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
agentId: config.agentId,
|
|
56
|
-
subAgentId: config.subAgentId
|
|
57
|
-
} }),
|
|
58
|
-
getArtifactComponentsForAgent(dbClient_default)({ scopes: {
|
|
59
|
-
tenantId: config.tenantId,
|
|
60
|
-
projectId: config.projectId,
|
|
61
|
-
agentId: config.agentId,
|
|
62
|
-
subAgentId: config.subAgentId
|
|
63
|
-
} })
|
|
64
|
-
]);
|
|
65
|
-
const enhancedInternalRelations = await Promise.all(internalRelations.data.map(async (relation) => {
|
|
27
|
+
const { project, agentId, tenantId, projectId, resolvedRef } = config.executionContext;
|
|
28
|
+
const currentAgent = project.agents[agentId];
|
|
29
|
+
const currentSubAgent = currentAgent?.subAgents?.[config.subAgentId];
|
|
30
|
+
if (!currentSubAgent) return {
|
|
31
|
+
status: {
|
|
32
|
+
state: TaskState.Failed,
|
|
33
|
+
message: `Sub-agent ${config.subAgentId} not found in project`
|
|
34
|
+
},
|
|
35
|
+
artifacts: []
|
|
36
|
+
};
|
|
37
|
+
const { externalRelations, teamRelations, transferRelations, internalDelegateRelations } = getSubAgentRelations({
|
|
38
|
+
agent: currentAgent,
|
|
39
|
+
project,
|
|
40
|
+
subAgent: currentSubAgent
|
|
41
|
+
});
|
|
42
|
+
const allInternalRelations = [...transferRelations, ...internalDelegateRelations];
|
|
43
|
+
const toolsForAgent = getToolsForSubAgent({
|
|
44
|
+
agent: currentAgent,
|
|
45
|
+
project,
|
|
46
|
+
subAgent: currentSubAgent
|
|
47
|
+
});
|
|
48
|
+
const dataComponents = getDataComponentsForSubAgent({
|
|
49
|
+
project,
|
|
50
|
+
subAgent: currentSubAgent
|
|
51
|
+
});
|
|
52
|
+
const artifactComponents = getArtifactComponentsForSubAgent({
|
|
53
|
+
project,
|
|
54
|
+
subAgent: currentSubAgent
|
|
55
|
+
});
|
|
56
|
+
const enhancedInternalRelations = allInternalRelations.map((relation) => {
|
|
66
57
|
try {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
},
|
|
73
|
-
subAgentId: relation.id
|
|
74
|
-
})) {
|
|
75
|
-
const relatedAgentRelations = await getRelatedAgentsForAgent(dbClient_default)({
|
|
76
|
-
scopes: {
|
|
77
|
-
tenantId: config.tenantId,
|
|
78
|
-
projectId: config.projectId,
|
|
79
|
-
agentId: config.agentId
|
|
80
|
-
},
|
|
81
|
-
subAgentId: relation.id
|
|
82
|
-
});
|
|
83
|
-
const relatedAgentExternalAgentRelations = await getExternalAgentsForSubAgent(dbClient_default)({ scopes: {
|
|
84
|
-
tenantId: config.tenantId,
|
|
85
|
-
projectId: config.projectId,
|
|
86
|
-
agentId: config.agentId,
|
|
87
|
-
subAgentId: relation.id
|
|
88
|
-
} });
|
|
89
|
-
const relatedAgentTeamAgentRelations = await getTeamAgentsForSubAgent(dbClient_default)({ scopes: {
|
|
90
|
-
tenantId: config.tenantId,
|
|
91
|
-
projectId: config.projectId,
|
|
92
|
-
agentId: config.agentId,
|
|
93
|
-
subAgentId: relation.id
|
|
94
|
-
} });
|
|
95
|
-
const enhancedDescription = generateDescriptionWithRelationData(relation.description || "", relatedAgentRelations.data, relatedAgentExternalAgentRelations.data, relatedAgentTeamAgentRelations.data);
|
|
96
|
-
return {
|
|
97
|
-
...relation,
|
|
98
|
-
description: enhancedDescription
|
|
99
|
-
};
|
|
100
|
-
}
|
|
58
|
+
return enhanceInternalRelation({
|
|
59
|
+
relation,
|
|
60
|
+
agent: currentAgent,
|
|
61
|
+
project
|
|
62
|
+
});
|
|
101
63
|
} catch (error) {
|
|
102
64
|
logger.warn({
|
|
103
65
|
subAgentId: relation.id,
|
|
104
66
|
error
|
|
105
67
|
}, "Failed to enhance agent description");
|
|
68
|
+
return relation;
|
|
106
69
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const enhancedTeamRelations = await Promise.all(teamRelations.data.map(async (relation) => {
|
|
70
|
+
});
|
|
71
|
+
const enhancedTeamRelations = teamRelations.map((relation) => {
|
|
110
72
|
try {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
} });
|
|
116
|
-
if (teamAgentWithDefault?.defaultSubAgent) {
|
|
117
|
-
const defaultSubAgent = teamAgentWithDefault.defaultSubAgent;
|
|
118
|
-
const relatedAgentRelations = await getRelatedAgentsForAgent(dbClient_default)({
|
|
119
|
-
scopes: {
|
|
120
|
-
tenantId: config.tenantId,
|
|
121
|
-
projectId: config.projectId,
|
|
122
|
-
agentId: relation.targetAgentId
|
|
123
|
-
},
|
|
124
|
-
subAgentId: defaultSubAgent.id
|
|
125
|
-
});
|
|
126
|
-
const relatedAgentExternalAgentRelations = await getExternalAgentsForSubAgent(dbClient_default)({ scopes: {
|
|
127
|
-
tenantId: config.tenantId,
|
|
128
|
-
projectId: config.projectId,
|
|
129
|
-
agentId: relation.targetAgentId,
|
|
130
|
-
subAgentId: defaultSubAgent.id
|
|
131
|
-
} });
|
|
132
|
-
const relatedAgentTeamAgentRelations = await getTeamAgentsForSubAgent(dbClient_default)({ scopes: {
|
|
133
|
-
tenantId: config.tenantId,
|
|
134
|
-
projectId: config.projectId,
|
|
135
|
-
agentId: relation.targetAgentId,
|
|
136
|
-
subAgentId: defaultSubAgent.id
|
|
137
|
-
} });
|
|
138
|
-
const enhancedDescription = generateDescriptionWithRelationData(teamAgentWithDefault.description || "", relatedAgentRelations.data, relatedAgentExternalAgentRelations.data, relatedAgentTeamAgentRelations.data);
|
|
139
|
-
return {
|
|
140
|
-
...relation,
|
|
141
|
-
targetAgent: {
|
|
142
|
-
...relation.targetAgent,
|
|
143
|
-
description: enhancedDescription
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
}
|
|
73
|
+
return enhanceTeamRelation({
|
|
74
|
+
relation,
|
|
75
|
+
project
|
|
76
|
+
});
|
|
147
77
|
} catch (error) {
|
|
148
78
|
logger.warn({
|
|
149
79
|
targetAgentId: relation.targetAgentId,
|
|
150
80
|
error
|
|
151
81
|
}, "Failed to enhance team agent description");
|
|
82
|
+
return relation;
|
|
152
83
|
}
|
|
153
|
-
|
|
154
|
-
}));
|
|
84
|
+
});
|
|
155
85
|
const prompt = "prompt" in config.agentSchema ? config.agentSchema.prompt || void 0 : "";
|
|
156
86
|
const models = "models" in config.agentSchema ? config.agentSchema.models : void 0;
|
|
157
87
|
const stopWhen = "stopWhen" in config.agentSchema ? config.agentSchema.stopWhen : void 0;
|
|
158
|
-
const
|
|
159
|
-
|
|
88
|
+
const manageApiClient = new ManagementApiClient({
|
|
89
|
+
apiUrl: env.INKEEP_AGENTS_MANAGE_API_URL,
|
|
90
|
+
tenantId,
|
|
91
|
+
projectId,
|
|
92
|
+
auth: {
|
|
93
|
+
mode: "internalService",
|
|
94
|
+
internalServiceName: InternalServices.INKEEP_AGENTS_RUN_API
|
|
95
|
+
},
|
|
96
|
+
ref: resolvedRef.name,
|
|
97
|
+
userId: config.userId
|
|
98
|
+
});
|
|
99
|
+
const toolsForAgentResult = await Promise.all(toolsForAgent.map(async (item) => {
|
|
100
|
+
const mcpTool = await manageApiClient.getMcpTool(item.tool.id);
|
|
101
|
+
if (item.relationshipId) mcpTool.relationshipId = item.relationshipId;
|
|
160
102
|
if (item.selectedTools && item.selectedTools.length > 0) {
|
|
161
103
|
const selectedToolsSet = new Set(item.selectedTools);
|
|
162
104
|
mcpTool.availableTools = mcpTool.availableTools?.filter((tool) => selectedToolsSet.has(tool.name)) || [];
|
|
@@ -165,9 +107,9 @@ const createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
165
107
|
})) ?? [];
|
|
166
108
|
agent = new Agent({
|
|
167
109
|
id: config.subAgentId,
|
|
168
|
-
tenantId
|
|
169
|
-
projectId
|
|
170
|
-
agentId
|
|
110
|
+
tenantId,
|
|
111
|
+
projectId,
|
|
112
|
+
agentId,
|
|
171
113
|
baseUrl: config.baseUrl,
|
|
172
114
|
apiKey: config.apiKey,
|
|
173
115
|
userId: config.userId,
|
|
@@ -178,9 +120,9 @@ const createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
178
120
|
stopWhen: stopWhen || void 0,
|
|
179
121
|
subAgentRelations: enhancedInternalRelations.map((relation) => ({
|
|
180
122
|
id: relation.id,
|
|
181
|
-
tenantId
|
|
182
|
-
projectId
|
|
183
|
-
agentId
|
|
123
|
+
tenantId,
|
|
124
|
+
projectId,
|
|
125
|
+
agentId,
|
|
184
126
|
baseUrl: config.baseUrl,
|
|
185
127
|
apiKey: config.apiKey,
|
|
186
128
|
name: relation.name,
|
|
@@ -188,99 +130,24 @@ const createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
188
130
|
prompt: "",
|
|
189
131
|
delegateRelations: [],
|
|
190
132
|
subAgentRelations: [],
|
|
191
|
-
transferRelations: []
|
|
192
|
-
|
|
193
|
-
transferRelations: await Promise.all(enhancedInternalRelations.filter((relation) => relation.relationType === "transfer").map(async (relation) => {
|
|
194
|
-
const targetToolsForAgent = await getToolsForAgent(dbClient_default)({ scopes: {
|
|
195
|
-
tenantId: config.tenantId,
|
|
196
|
-
projectId: config.projectId,
|
|
197
|
-
agentId: config.agentId,
|
|
198
|
-
subAgentId: relation.id
|
|
199
|
-
} });
|
|
200
|
-
let targetTransferRelations = { data: [] };
|
|
201
|
-
let targetDelegateRelations = { data: [] };
|
|
202
|
-
try {
|
|
203
|
-
const [transferRel, delegateRel] = await Promise.all([getRelatedAgentsForAgent(dbClient_default)({
|
|
204
|
-
scopes: {
|
|
205
|
-
tenantId: config.tenantId,
|
|
206
|
-
projectId: config.projectId,
|
|
207
|
-
agentId: config.agentId
|
|
208
|
-
},
|
|
209
|
-
subAgentId: relation.id
|
|
210
|
-
}), getExternalAgentsForSubAgent(dbClient_default)({ scopes: {
|
|
211
|
-
tenantId: config.tenantId,
|
|
212
|
-
projectId: config.projectId,
|
|
213
|
-
agentId: config.agentId,
|
|
214
|
-
subAgentId: relation.id
|
|
215
|
-
} })]);
|
|
216
|
-
targetTransferRelations = transferRel;
|
|
217
|
-
targetDelegateRelations = delegateRel;
|
|
218
|
-
} catch (err) {
|
|
219
|
-
logger.info({
|
|
220
|
-
agentId: relation.id,
|
|
221
|
-
error: err?.message || "Unknown error"
|
|
222
|
-
}, "Could not fetch relations for target agent (likely external/team agent), using basic info only");
|
|
223
|
-
}
|
|
224
|
-
const targetAgentTools = await Promise.all(targetToolsForAgent.data.map(async (item) => {
|
|
225
|
-
const mcpTool = await dbResultToMcpTool(item.tool, dbClient_default, credentialStoreRegistry, item.id, config.userId);
|
|
226
|
-
if (item.selectedTools && item.selectedTools.length > 0) {
|
|
227
|
-
const selectedToolsSet = new Set(item.selectedTools);
|
|
228
|
-
mcpTool.availableTools = mcpTool.availableTools?.filter((tool) => selectedToolsSet.has(tool.name)) || [];
|
|
229
|
-
}
|
|
230
|
-
return mcpTool;
|
|
231
|
-
})) ?? [];
|
|
232
|
-
const targetTransferRelationsConfig = targetTransferRelations.data.filter((rel) => rel.relationType === "transfer").map((rel) => ({
|
|
233
|
-
baseUrl: config.baseUrl,
|
|
234
|
-
apiKey: config.apiKey,
|
|
235
|
-
id: rel.id,
|
|
236
|
-
tenantId: config.tenantId,
|
|
237
|
-
projectId: config.projectId,
|
|
238
|
-
agentId: config.agentId,
|
|
239
|
-
name: rel.name,
|
|
240
|
-
description: rel.description,
|
|
241
|
-
prompt: "",
|
|
242
|
-
delegateRelations: [],
|
|
243
|
-
subAgentRelations: [],
|
|
244
|
-
transferRelations: []
|
|
245
|
-
}));
|
|
246
|
-
const targetDelegateRelationsConfig = targetDelegateRelations.data.map((rel) => ({
|
|
247
|
-
type: "external",
|
|
248
|
-
config: {
|
|
249
|
-
id: rel.externalAgent.id,
|
|
250
|
-
name: rel.externalAgent.name,
|
|
251
|
-
description: rel.externalAgent.description || "",
|
|
252
|
-
baseUrl: rel.externalAgent.baseUrl,
|
|
253
|
-
headers: rel.headers,
|
|
254
|
-
credentialReferenceId: rel.externalAgent.credentialReferenceId,
|
|
255
|
-
relationId: rel.id,
|
|
256
|
-
relationType: "delegate"
|
|
257
|
-
}
|
|
258
|
-
}));
|
|
259
|
-
return {
|
|
260
|
-
baseUrl: config.baseUrl,
|
|
261
|
-
apiKey: config.apiKey,
|
|
262
|
-
id: relation.id,
|
|
263
|
-
tenantId: config.tenantId,
|
|
264
|
-
projectId: config.projectId,
|
|
265
|
-
agentId: config.agentId,
|
|
266
|
-
name: relation.name,
|
|
267
|
-
description: relation.description || void 0,
|
|
268
|
-
prompt: "",
|
|
269
|
-
delegateRelations: targetDelegateRelationsConfig,
|
|
270
|
-
subAgentRelations: [],
|
|
271
|
-
transferRelations: targetTransferRelationsConfig,
|
|
272
|
-
tools: targetAgentTools
|
|
273
|
-
};
|
|
133
|
+
transferRelations: [],
|
|
134
|
+
relationId: relation.relationId
|
|
274
135
|
})),
|
|
136
|
+
transferRelations: await Promise.all(enhancedInternalRelations.filter((relation) => relation.relationType === "transfer").map((relation) => buildTransferRelationConfig({
|
|
137
|
+
relation,
|
|
138
|
+
executionContext: config.executionContext,
|
|
139
|
+
baseUrl: config.baseUrl,
|
|
140
|
+
apiKey: config.apiKey
|
|
141
|
+
}))),
|
|
275
142
|
delegateRelations: [
|
|
276
143
|
...enhancedInternalRelations.filter((relation) => relation.relationType === "delegate").map((relation) => ({
|
|
277
144
|
type: "internal",
|
|
278
145
|
config: {
|
|
279
146
|
id: relation.id,
|
|
280
147
|
relationId: relation.relationId,
|
|
281
|
-
tenantId
|
|
282
|
-
projectId
|
|
283
|
-
agentId
|
|
148
|
+
tenantId,
|
|
149
|
+
projectId,
|
|
150
|
+
agentId,
|
|
284
151
|
baseUrl: config.baseUrl,
|
|
285
152
|
apiKey: config.apiKey,
|
|
286
153
|
name: relation.name,
|
|
@@ -289,19 +156,21 @@ const createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
289
156
|
delegateRelations: [],
|
|
290
157
|
subAgentRelations: [],
|
|
291
158
|
transferRelations: [],
|
|
292
|
-
tools: []
|
|
159
|
+
tools: [],
|
|
160
|
+
project
|
|
293
161
|
}
|
|
294
162
|
})),
|
|
295
|
-
...externalRelations.
|
|
163
|
+
...externalRelations.map((relation) => ({
|
|
296
164
|
type: "external",
|
|
297
165
|
config: {
|
|
298
166
|
id: relation.externalAgent.id,
|
|
299
167
|
name: relation.externalAgent.name,
|
|
300
168
|
description: relation.externalAgent.description || "",
|
|
169
|
+
ref: resolvedRef,
|
|
301
170
|
baseUrl: relation.externalAgent.baseUrl,
|
|
302
171
|
headers: relation.headers,
|
|
303
172
|
credentialReferenceId: relation.externalAgent.credentialReferenceId,
|
|
304
|
-
relationId: relation.
|
|
173
|
+
relationId: relation.relationId,
|
|
305
174
|
relationType: "delegate"
|
|
306
175
|
}
|
|
307
176
|
})),
|
|
@@ -309,11 +178,12 @@ const createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
309
178
|
type: "team",
|
|
310
179
|
config: {
|
|
311
180
|
id: relation.targetAgent.id,
|
|
181
|
+
ref: resolvedRef,
|
|
312
182
|
name: relation.targetAgent.name,
|
|
313
183
|
description: relation.targetAgent.description || "",
|
|
314
184
|
baseUrl: config.baseUrl,
|
|
315
185
|
headers: relation.headers,
|
|
316
|
-
relationId: relation.
|
|
186
|
+
relationId: relation.relationId
|
|
317
187
|
}
|
|
318
188
|
}))
|
|
319
189
|
],
|
|
@@ -325,7 +195,7 @@ const createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
325
195
|
conversationHistoryConfig: config.conversationHistoryConfig,
|
|
326
196
|
sandboxConfig: config.sandboxConfig,
|
|
327
197
|
forwardedHeaders
|
|
328
|
-
}, credentialStoreRegistry);
|
|
198
|
+
}, config.executionContext, credentialStoreRegistry);
|
|
329
199
|
const artifactStreamRequestId = task.context?.metadata?.streamRequestId;
|
|
330
200
|
if (artifactStreamRequestId && artifactComponents.length > 0) agentSessionManager.updateArtifactComponents(artifactStreamRequestId, artifactComponents);
|
|
331
201
|
let contextId = task.context?.conversationId;
|
|
@@ -351,8 +221,10 @@ const createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
351
221
|
taskId: task.id,
|
|
352
222
|
delegationId
|
|
353
223
|
}, "Delegated agent - streaming disabled");
|
|
354
|
-
if (streamRequestId &&
|
|
224
|
+
if (streamRequestId && tenantId && projectId) toolSessionManager.ensureAgentSession(streamRequestId, tenantId, projectId, contextId, task.id);
|
|
355
225
|
}
|
|
226
|
+
logger.info({ contextId }, "Context ID");
|
|
227
|
+
logger.info({ userMessage }, "User Message");
|
|
356
228
|
const response = await agent.generate(userMessage, {
|
|
357
229
|
contextId,
|
|
358
230
|
metadata: {
|
|
@@ -473,30 +345,19 @@ const deserializeTaskHandlerConfig = (configJson) => {
|
|
|
473
345
|
return JSON.parse(configJson);
|
|
474
346
|
};
|
|
475
347
|
/**
|
|
476
|
-
* Creates a task handler configuration from
|
|
348
|
+
* Creates a task handler configuration from execution context and project data
|
|
477
349
|
*/
|
|
478
350
|
const createTaskHandlerConfig = async (params) => {
|
|
479
|
-
const
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
subAgentId: params.subAgentId
|
|
486
|
-
});
|
|
487
|
-
const agent = await getAgentById(dbClient_default)({ scopes: {
|
|
488
|
-
tenantId: params.tenantId,
|
|
489
|
-
projectId: params.projectId,
|
|
490
|
-
agentId: params.agentId
|
|
491
|
-
} });
|
|
492
|
-
if (!subAgent) throw new Error(`Agent not found: ${params.subAgentId}`);
|
|
493
|
-
const effectiveModels = await resolveModelConfig(params.agentId, subAgent);
|
|
351
|
+
const { executionContext, subAgentId, baseUrl, apiKey, sandboxConfig } = params;
|
|
352
|
+
const { project, agentId } = executionContext;
|
|
353
|
+
const agent = project.agents[agentId];
|
|
354
|
+
const subAgent = agent?.subAgents?.[subAgentId];
|
|
355
|
+
if (!subAgent) throw new Error(`Sub-agent not found: ${subAgentId}`);
|
|
356
|
+
const effectiveModels = await resolveModelConfig(executionContext, subAgent);
|
|
494
357
|
const effectiveConversationHistoryConfig = subAgent.conversationHistoryConfig;
|
|
495
358
|
return {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
agentId: params.agentId,
|
|
499
|
-
subAgentId: params.subAgentId,
|
|
359
|
+
executionContext,
|
|
360
|
+
subAgentId,
|
|
500
361
|
agentSchema: {
|
|
501
362
|
id: subAgent.id,
|
|
502
363
|
name: subAgent.name,
|
|
@@ -508,14 +369,14 @@ const createTaskHandlerConfig = async (params) => {
|
|
|
508
369
|
createdAt: subAgent.createdAt,
|
|
509
370
|
updatedAt: subAgent.updatedAt
|
|
510
371
|
},
|
|
511
|
-
baseUrl
|
|
512
|
-
apiKey
|
|
372
|
+
baseUrl,
|
|
373
|
+
apiKey,
|
|
513
374
|
name: subAgent.name,
|
|
514
375
|
description: subAgent.description || void 0,
|
|
515
376
|
conversationHistoryConfig: effectiveConversationHistoryConfig,
|
|
516
|
-
contextConfigId: agent?.
|
|
517
|
-
sandboxConfig
|
|
518
|
-
userId:
|
|
377
|
+
contextConfigId: agent?.contextConfig?.id || void 0,
|
|
378
|
+
sandboxConfig,
|
|
379
|
+
userId: getUserIdFromContext(executionContext)
|
|
519
380
|
};
|
|
520
381
|
};
|
|
521
382
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AgentConfig, DelegateRelation } from "./Agent.js";
|
|
2
|
+
import { InternalRelation } from "../utils/project.js";
|
|
2
3
|
import * as _inkeep_agents_core0 from "@inkeep/agents-core";
|
|
3
|
-
import { CredentialStoreRegistry } from "@inkeep/agents-core";
|
|
4
|
+
import { CredentialStoreRegistry, FullExecutionContext } from "@inkeep/agents-core";
|
|
4
5
|
import * as ai0 from "ai";
|
|
5
6
|
|
|
6
7
|
//#region src/agents/relationTools.d.ts
|
|
@@ -22,9 +23,7 @@ declare const createTransferToAgentTool: ({
|
|
|
22
23
|
declare function createDelegateToAgentTool({
|
|
23
24
|
delegateConfig,
|
|
24
25
|
callingAgentId,
|
|
25
|
-
|
|
26
|
-
projectId,
|
|
27
|
-
agentId,
|
|
26
|
+
executionContext,
|
|
28
27
|
contextId,
|
|
29
28
|
metadata,
|
|
30
29
|
sessionId,
|
|
@@ -33,9 +32,7 @@ declare function createDelegateToAgentTool({
|
|
|
33
32
|
}: {
|
|
34
33
|
delegateConfig: DelegateRelation;
|
|
35
34
|
callingAgentId: string;
|
|
36
|
-
|
|
37
|
-
projectId: string;
|
|
38
|
-
agentId: string;
|
|
35
|
+
executionContext: FullExecutionContext;
|
|
39
36
|
contextId: string;
|
|
40
37
|
metadata: {
|
|
41
38
|
conversationId: string;
|
|
@@ -53,5 +50,19 @@ declare function createDelegateToAgentTool({
|
|
|
53
50
|
toolCallId: any;
|
|
54
51
|
result: _inkeep_agents_core0.Message | _inkeep_agents_core0.Task;
|
|
55
52
|
}>;
|
|
53
|
+
/**
|
|
54
|
+
* Parameters for building a transfer relation config
|
|
55
|
+
*/
|
|
56
|
+
type BuildTransferRelationConfigParams = {
|
|
57
|
+
relation: InternalRelation;
|
|
58
|
+
executionContext: FullExecutionContext;
|
|
59
|
+
baseUrl: string;
|
|
60
|
+
apiKey?: string;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Build a transfer relation config for an internal relation.
|
|
64
|
+
* Fetches tools, transfer relations, and external agent relations for the target sub-agent.
|
|
65
|
+
*/
|
|
66
|
+
declare function buildTransferRelationConfig(params: BuildTransferRelationConfigParams): Promise<AgentConfig>;
|
|
56
67
|
//#endregion
|
|
57
|
-
export { createDelegateToAgentTool, createTransferToAgentTool };
|
|
68
|
+
export { BuildTransferRelationConfigParams, buildTransferRelationConfig, createDelegateToAgentTool, createTransferToAgentTool };
|