@theia/ai-chat 1.71.0-next.0 → 1.71.0-next.11
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/lib/browser/agent-delegation-tool.d.ts +0 -2
- package/lib/browser/agent-delegation-tool.d.ts.map +1 -1
- package/lib/browser/agent-delegation-tool.js +14 -3
- package/lib/browser/agent-delegation-tool.js.map +1 -1
- package/lib/browser/agent-delegation-tool.spec.d.ts +2 -0
- package/lib/browser/agent-delegation-tool.spec.d.ts.map +1 -0
- package/lib/browser/agent-delegation-tool.spec.js +142 -0
- package/lib/browser/agent-delegation-tool.spec.js.map +1 -0
- package/package.json +9 -9
- package/src/browser/agent-delegation-tool.spec.ts +194 -0
- package/src/browser/agent-delegation-tool.ts +18 -5
|
@@ -3,7 +3,6 @@ import { ChatAgentService, ChatService, ChatRequestInvocation } from '../common'
|
|
|
3
3
|
export declare class AgentDelegationTool implements ToolProvider {
|
|
4
4
|
static ID: string;
|
|
5
5
|
protected readonly pendingDelegations: Map<string, {
|
|
6
|
-
agentName: string;
|
|
7
6
|
prompt: string;
|
|
8
7
|
invocation: ChatRequestInvocation;
|
|
9
8
|
}>;
|
|
@@ -11,7 +10,6 @@ export declare class AgentDelegationTool implements ToolProvider {
|
|
|
11
10
|
protected readonly getChatService: () => ChatService;
|
|
12
11
|
getTool(): ToolRequest;
|
|
13
12
|
getDelegation(toolCallId: string): {
|
|
14
|
-
agentName: string;
|
|
15
13
|
prompt: string;
|
|
16
14
|
invocation: ChatRequestInvocation;
|
|
17
15
|
} | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-delegation-tool.d.ts","sourceRoot":"","sources":["../../src/browser/agent-delegation-tool.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAuD,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAEhH,OAAO,EAEH,gBAAgB,EAGhB,WAAW,EAMX,qBAAqB,EACxB,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-delegation-tool.d.ts","sourceRoot":"","sources":["../../src/browser/agent-delegation-tool.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAuD,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAEhH,OAAO,EAEH,gBAAgB,EAGhB,WAAW,EAMX,qBAAqB,EACxB,MAAM,WAAW,CAAC;AAGnB,qBACa,mBAAoB,YAAW,YAAY;IACpD,MAAM,CAAC,EAAE,SAAgC;IAEzC,SAAS,CAAC,QAAQ,CAAC,kBAAkB;gBAA6B,MAAM;oBAAc,qBAAqB;OAAM;IAGjH,SAAS,CAAC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;IAG/D,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,MAAM,WAAW,CAAC;IAErD,OAAO,IAAI,WAAW;IAqCtB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,qBAAqB,CAAA;KAAE,GAAG,SAAS;YAItF,eAAe;IA6J7B;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;IAU9B;;;;OAIG;IACH,OAAO,CAAC,eAAe;CAU1B"}
|
|
@@ -21,6 +21,7 @@ const tslib_1 = require("tslib");
|
|
|
21
21
|
const ai_core_1 = require("@theia/ai-core");
|
|
22
22
|
const inversify_1 = require("@theia/core/shared/inversify");
|
|
23
23
|
const common_1 = require("../common");
|
|
24
|
+
const task_context_variable_1 = require("./task-context-variable");
|
|
24
25
|
let AgentDelegationTool = class AgentDelegationTool {
|
|
25
26
|
constructor() {
|
|
26
27
|
this.pendingDelegations = new Map();
|
|
@@ -34,7 +35,8 @@ let AgentDelegationTool = class AgentDelegationTool {
|
|
|
34
35
|
description: 'Delegate a task or question to a specific AI agent. IMPORTANT: When you delegate a task or question to a specific AI agent using this tool, ' +
|
|
35
36
|
'remember that each sub-agent operates solely within its specialized capabilities and tools and does not have access to previous conversation context ' +
|
|
36
37
|
' or external systems. Therefore, it is crucial to provide all necessary context and detailed information directly within your request to ensure accurate ' +
|
|
37
|
-
'and effective task completion.'
|
|
38
|
+
'and effective task completion. ' +
|
|
39
|
+
'You may optionally pass a taskContextId to make a specific task context (e.g. a plan) available to the delegated agent via its system prompt.',
|
|
38
40
|
parameters: {
|
|
39
41
|
type: 'object',
|
|
40
42
|
properties: {
|
|
@@ -46,6 +48,10 @@ let AgentDelegationTool = class AgentDelegationTool {
|
|
|
46
48
|
type: 'string',
|
|
47
49
|
description: 'The task, question, or prompt to pass to the specified agent.',
|
|
48
50
|
},
|
|
51
|
+
taskContextId: {
|
|
52
|
+
type: 'string',
|
|
53
|
+
description: 'Optional task context ID to make available to the delegated agent. The agent will see the task context in its system prompt.',
|
|
54
|
+
},
|
|
49
55
|
},
|
|
50
56
|
required: ['agentId', 'prompt'],
|
|
51
57
|
},
|
|
@@ -64,7 +70,7 @@ let AgentDelegationTool = class AgentDelegationTool {
|
|
|
64
70
|
}
|
|
65
71
|
try {
|
|
66
72
|
const args = JSON.parse(arg_string);
|
|
67
|
-
const { agentId, prompt } = args;
|
|
73
|
+
const { agentId, prompt, taskContextId } = args;
|
|
68
74
|
if (!agentId || !prompt) {
|
|
69
75
|
const errorMsg = 'Both agentId and prompt parameters are required.';
|
|
70
76
|
console.error(errorMsg, { agentId, prompt });
|
|
@@ -93,6 +99,12 @@ let AgentDelegationTool = class AgentDelegationTool {
|
|
|
93
99
|
const rootId = ctx.rootSessionId || ctx.request.session.id;
|
|
94
100
|
newSession.rootSessionId = rootId;
|
|
95
101
|
newSession.model.rootSessionId = rootId;
|
|
102
|
+
if (taskContextId) {
|
|
103
|
+
newSession.model.context.addVariables({
|
|
104
|
+
variable: task_context_variable_1.TASK_CONTEXT_VARIABLE,
|
|
105
|
+
arg: taskContextId
|
|
106
|
+
});
|
|
107
|
+
}
|
|
96
108
|
// Immediately restore the original active session to avoid confusing the user
|
|
97
109
|
if (currentActiveSession) {
|
|
98
110
|
chatService.setActiveSession(currentActiveSession.id, { focus: false });
|
|
@@ -133,7 +145,6 @@ let AgentDelegationTool = class AgentDelegationTool {
|
|
|
133
145
|
// Store the invocation in the registry so the renderer can access it
|
|
134
146
|
if (ctx.toolCallId) {
|
|
135
147
|
this.pendingDelegations.set(ctx.toolCallId, {
|
|
136
|
-
agentName: agent.name,
|
|
137
148
|
prompt,
|
|
138
149
|
invocation: response
|
|
139
150
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-delegation-tool.js","sourceRoot":"","sources":["../../src/browser/agent-delegation-tool.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;;AAEhF,4CAAgH;AAChH,4DAAkE;AAClE,sCAYmB;
|
|
1
|
+
{"version":3,"file":"agent-delegation-tool.js","sourceRoot":"","sources":["../../src/browser/agent-delegation-tool.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;;AAEhF,4CAAgH;AAChH,4DAAkE;AAClE,sCAYmB;AACnB,mEAAgE;AAGzD,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAAzB;QAGgB,uBAAkB,GAAG,IAAI,GAAG,EAAiE,CAAC;IA4OrH,CAAC;;aA9OU,OAAE,GAAG,sCAA4B,AAA/B,CAAgC;IAUzC,OAAO;QACH,OAAO;YACH,EAAE,EAAE,qBAAmB,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D,IAAI,CAAC,eAAe,CAAC,gBAAgB,EAAE,WAAW,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;OAIG;IACK,eAAe,CACnB,gBAA6B,EAC7B,WAA6B;QAE7B,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,KAAK,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC;QACzE,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC/B,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YACvE,WAAW,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,iBAAiB,CAAC,CAAC;QAC5D,CAAC;IACL,CAAC;;AA9OQ,kDAAmB;AAMT;IADlB,IAAA,kBAAM,EAAC,gCAAuB,CAAC;;gEAC+B;AAG5C;IADlB,IAAA,kBAAM,EAAC,2BAAkB,CAAC;;2DAC0B;8BAT5C,mBAAmB;IAD/B,IAAA,sBAAU,GAAE;GACA,mBAAmB,CA+O/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-delegation-tool.spec.d.ts","sourceRoot":"","sources":["../../src/browser/agent-delegation-tool.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2026 EclipseSource GmbH.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const jsdom_1 = require("@theia/core/lib/browser/test/jsdom");
|
|
19
|
+
let disableJSDOM = (0, jsdom_1.enableJSDOM)();
|
|
20
|
+
const frontend_application_config_provider_1 = require("@theia/core/lib/browser/frontend-application-config-provider");
|
|
21
|
+
frontend_application_config_provider_1.FrontendApplicationConfigProvider.set({});
|
|
22
|
+
const chai_1 = require("chai");
|
|
23
|
+
const sinon = require("sinon");
|
|
24
|
+
const agent_delegation_tool_1 = require("./agent-delegation-tool");
|
|
25
|
+
const task_context_variable_1 = require("./task-context-variable");
|
|
26
|
+
const chat_agent_service_1 = require("../common/chat-agent-service");
|
|
27
|
+
disableJSDOM();
|
|
28
|
+
// --- Factory ---
|
|
29
|
+
function makeAgentDelegationTool(chatAgentService, chatService) {
|
|
30
|
+
const tool = new agent_delegation_tool_1.AgentDelegationTool();
|
|
31
|
+
Object.defineProperty(tool, 'getChatAgentService', { value: () => chatAgentService });
|
|
32
|
+
Object.defineProperty(tool, 'getChatService', { value: () => chatService });
|
|
33
|
+
return tool;
|
|
34
|
+
}
|
|
35
|
+
// --- Helper factories ---
|
|
36
|
+
function makeContextManager() {
|
|
37
|
+
return {
|
|
38
|
+
addVariables: sinon.stub(),
|
|
39
|
+
getVariables: sinon.stub().returns([])
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function makeChangeSet() {
|
|
43
|
+
return { onDidChange: sinon.stub() };
|
|
44
|
+
}
|
|
45
|
+
function makeNewSession(contextManager = makeContextManager()) {
|
|
46
|
+
return {
|
|
47
|
+
id: 'new-session-id',
|
|
48
|
+
model: {
|
|
49
|
+
context: contextManager,
|
|
50
|
+
changeSet: makeChangeSet()
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function makeParentSession() {
|
|
55
|
+
return {
|
|
56
|
+
id: 'parent-session-id',
|
|
57
|
+
model: {
|
|
58
|
+
changeSet: {
|
|
59
|
+
onDidChange: sinon.stub(),
|
|
60
|
+
getElements: sinon.stub().returns([])
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function makeChatAgentService(agentExists = true) {
|
|
66
|
+
const stub = sinon.createStubInstance(chat_agent_service_1.ChatAgentServiceImpl);
|
|
67
|
+
stub.getAgent.returns(agentExists ? { id: 'test-agent', name: 'Test Agent' } : undefined);
|
|
68
|
+
stub.getAgents.returns([]);
|
|
69
|
+
return stub;
|
|
70
|
+
}
|
|
71
|
+
function makeChatContext() {
|
|
72
|
+
return {
|
|
73
|
+
cancellationToken: undefined,
|
|
74
|
+
toolCallId: undefined,
|
|
75
|
+
request: { session: makeParentSession() },
|
|
76
|
+
response: {}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function makeChatService(newSession) {
|
|
80
|
+
const responseCompleted = Promise.resolve({
|
|
81
|
+
response: { asString: () => 'agent response' }
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
onSessionEvent: sinon.stub(),
|
|
85
|
+
getSession: sinon.stub(),
|
|
86
|
+
getSessions: sinon.stub().returns([]),
|
|
87
|
+
getActiveSession: sinon.stub().returns({ id: 'active-session-id' }),
|
|
88
|
+
setActiveSession: sinon.stub(),
|
|
89
|
+
createSession: sinon.stub().returns(newSession),
|
|
90
|
+
sendRequest: sinon.stub().resolves({ responseCompleted }),
|
|
91
|
+
deleteSession: sinon.stub().resolves(),
|
|
92
|
+
renameSession: sinon.stub().resolves(),
|
|
93
|
+
getAgent: sinon.stub(),
|
|
94
|
+
deleteChangeSet: sinon.stub(),
|
|
95
|
+
deleteChangeSetElement: sinon.stub(),
|
|
96
|
+
cancelRequest: sinon.stub().resolves(),
|
|
97
|
+
getOrRestoreSession: sinon.stub().resolves(undefined),
|
|
98
|
+
getPersistedSessions: sinon.stub().resolves({}),
|
|
99
|
+
hasPersistedSessions: sinon.stub().resolves(false),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
// --- Tests ---
|
|
103
|
+
describe('AgentDelegationTool', () => {
|
|
104
|
+
before(() => {
|
|
105
|
+
disableJSDOM = (0, jsdom_1.enableJSDOM)();
|
|
106
|
+
});
|
|
107
|
+
after(() => {
|
|
108
|
+
disableJSDOM();
|
|
109
|
+
});
|
|
110
|
+
describe('delegateToAgent() — taskContextId parameter', () => {
|
|
111
|
+
let contextManager;
|
|
112
|
+
let tool;
|
|
113
|
+
let ctx;
|
|
114
|
+
beforeEach(() => {
|
|
115
|
+
contextManager = makeContextManager();
|
|
116
|
+
const newSession = makeNewSession(contextManager);
|
|
117
|
+
const agentService = makeChatAgentService();
|
|
118
|
+
const chatService = makeChatService(newSession);
|
|
119
|
+
tool = makeAgentDelegationTool(agentService, chatService);
|
|
120
|
+
ctx = makeChatContext();
|
|
121
|
+
});
|
|
122
|
+
it('injects TASK_CONTEXT_VARIABLE when taskContextId is provided', async () => {
|
|
123
|
+
const argString = JSON.stringify({ agentId: 'test-agent', prompt: 'do something', taskContextId: 'my-task-ctx-id' });
|
|
124
|
+
await tool.getTool().handler(argString, ctx);
|
|
125
|
+
(0, chai_1.expect)(contextManager.addVariables.calledOnce).to.be.true;
|
|
126
|
+
const callArg = contextManager.addVariables.firstCall.args[0];
|
|
127
|
+
(0, chai_1.expect)(callArg.variable).to.equal(task_context_variable_1.TASK_CONTEXT_VARIABLE);
|
|
128
|
+
(0, chai_1.expect)(callArg.arg).to.equal('my-task-ctx-id');
|
|
129
|
+
});
|
|
130
|
+
it('does not inject any task context variable when taskContextId is not provided', async () => {
|
|
131
|
+
const argString = JSON.stringify({ agentId: 'test-agent', prompt: 'do something' });
|
|
132
|
+
await tool.getTool().handler(argString, ctx);
|
|
133
|
+
(0, chai_1.expect)(contextManager.addVariables.called).to.be.false;
|
|
134
|
+
});
|
|
135
|
+
it('does not inject any task context variable when taskContextId is an empty string', async () => {
|
|
136
|
+
const argString = JSON.stringify({ agentId: 'test-agent', prompt: 'do something', taskContextId: '' });
|
|
137
|
+
await tool.getTool().handler(argString, ctx);
|
|
138
|
+
(0, chai_1.expect)(contextManager.addVariables.called).to.be.false;
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
//# sourceMappingURL=agent-delegation-tool.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-delegation-tool.spec.js","sourceRoot":"","sources":["../../src/browser/agent-delegation-tool.spec.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;AAEhF,8DAAiE;AACjE,IAAI,YAAY,GAAG,IAAA,mBAAW,GAAE,CAAC;AACjC,uHAAiH;AACjH,wEAAiC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAE1C,+BAA8B;AAC9B,+BAA+B;AAC/B,mEAA8D;AAC9D,mEAAgE;AAUhE,qEAAoE;AAGpE,YAAY,EAAE,CAAC;AAEf,kBAAkB;AAElB,SAAS,uBAAuB,CAAC,gBAAkC,EAAE,WAAwB;IACzF,MAAM,IAAI,GAAG,IAAI,2CAAmB,EAAE,CAAC;IACvC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,qBAAqB,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,gBAAgB,EAAE,CAAC,CAAC;IACtF,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,gBAAgB,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;IAC5E,OAA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|
5
5
|
"dependencies": {
|
|
6
|
-
"@theia/ai-core": "1.71.0-next.
|
|
7
|
-
"@theia/core": "1.71.0-next.
|
|
8
|
-
"@theia/editor": "1.71.0-next.
|
|
9
|
-
"@theia/file-search": "1.71.0-next.
|
|
10
|
-
"@theia/filesystem": "1.71.0-next.
|
|
11
|
-
"@theia/monaco": "1.71.0-next.
|
|
6
|
+
"@theia/ai-core": "1.71.0-next.11+2554837d1",
|
|
7
|
+
"@theia/core": "1.71.0-next.11+2554837d1",
|
|
8
|
+
"@theia/editor": "1.71.0-next.11+2554837d1",
|
|
9
|
+
"@theia/file-search": "1.71.0-next.11+2554837d1",
|
|
10
|
+
"@theia/filesystem": "1.71.0-next.11+2554837d1",
|
|
11
|
+
"@theia/monaco": "1.71.0-next.11+2554837d1",
|
|
12
12
|
"@theia/monaco-editor-core": "1.108.201",
|
|
13
|
-
"@theia/workspace": "1.71.0-next.
|
|
13
|
+
"@theia/workspace": "1.71.0-next.11+2554837d1",
|
|
14
14
|
"js-yaml": "^4.1.0",
|
|
15
15
|
"tslib": "^2.6.2"
|
|
16
16
|
},
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"nyc": {
|
|
55
55
|
"extends": "../../configs/nyc.json"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "2554837d1cd32aad585887f2ab43bda2a4a8f091"
|
|
58
58
|
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { enableJSDOM } from '@theia/core/lib/browser/test/jsdom';
|
|
18
|
+
let disableJSDOM = enableJSDOM();
|
|
19
|
+
import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';
|
|
20
|
+
FrontendApplicationConfigProvider.set({});
|
|
21
|
+
|
|
22
|
+
import { expect } from 'chai';
|
|
23
|
+
import * as sinon from 'sinon';
|
|
24
|
+
import { AgentDelegationTool } from './agent-delegation-tool';
|
|
25
|
+
import { TASK_CONTEXT_VARIABLE } from './task-context-variable';
|
|
26
|
+
import { AIVariableResolutionRequest } from '@theia/ai-core';
|
|
27
|
+
import {
|
|
28
|
+
ActiveSessionChangedEvent,
|
|
29
|
+
ChatAgentService,
|
|
30
|
+
ChatService,
|
|
31
|
+
SessionCreatedEvent,
|
|
32
|
+
SessionDeletedEvent,
|
|
33
|
+
SessionRenamedEvent,
|
|
34
|
+
} from '../common';
|
|
35
|
+
import { ChatAgentServiceImpl } from '../common/chat-agent-service';
|
|
36
|
+
import { Event } from '@theia/core';
|
|
37
|
+
|
|
38
|
+
disableJSDOM();
|
|
39
|
+
|
|
40
|
+
// --- Factory ---
|
|
41
|
+
|
|
42
|
+
function makeAgentDelegationTool(chatAgentService: ChatAgentService, chatService: ChatService): AgentDelegationTool {
|
|
43
|
+
const tool = new AgentDelegationTool();
|
|
44
|
+
Object.defineProperty(tool, 'getChatAgentService', { value: () => chatAgentService });
|
|
45
|
+
Object.defineProperty(tool, 'getChatService', { value: () => chatService });
|
|
46
|
+
return tool;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// --- Helper factories ---
|
|
50
|
+
|
|
51
|
+
function makeContextManager(): { addVariables: sinon.SinonStub; getVariables: sinon.SinonStub } {
|
|
52
|
+
return {
|
|
53
|
+
addVariables: sinon.stub(),
|
|
54
|
+
getVariables: sinon.stub().returns([])
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function makeChangeSet(): { onDidChange: sinon.SinonStub } {
|
|
59
|
+
return { onDidChange: sinon.stub() };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function makeNewSession(contextManager = makeContextManager()): {
|
|
63
|
+
id: string;
|
|
64
|
+
model: {
|
|
65
|
+
context: ReturnType<typeof makeContextManager>;
|
|
66
|
+
changeSet: ReturnType<typeof makeChangeSet>;
|
|
67
|
+
};
|
|
68
|
+
} {
|
|
69
|
+
return {
|
|
70
|
+
id: 'new-session-id',
|
|
71
|
+
model: {
|
|
72
|
+
context: contextManager,
|
|
73
|
+
changeSet: makeChangeSet()
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function makeParentSession(): {
|
|
79
|
+
id: string;
|
|
80
|
+
model: {
|
|
81
|
+
changeSet: { onDidChange: sinon.SinonStub; getElements: sinon.SinonStub };
|
|
82
|
+
};
|
|
83
|
+
} {
|
|
84
|
+
return {
|
|
85
|
+
id: 'parent-session-id',
|
|
86
|
+
model: {
|
|
87
|
+
changeSet: {
|
|
88
|
+
onDidChange: sinon.stub(),
|
|
89
|
+
getElements: sinon.stub().returns([])
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function makeChatAgentService(agentExists = true): ChatAgentService {
|
|
96
|
+
const stub = sinon.createStubInstance(ChatAgentServiceImpl);
|
|
97
|
+
stub.getAgent.returns(agentExists ? { id: 'test-agent', name: 'Test Agent' } as never : undefined);
|
|
98
|
+
stub.getAgents.returns([]);
|
|
99
|
+
return stub as ChatAgentService;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function makeChatContext(): {
|
|
103
|
+
cancellationToken: undefined;
|
|
104
|
+
toolCallId: undefined;
|
|
105
|
+
request: { session: ReturnType<typeof makeParentSession> };
|
|
106
|
+
response: object;
|
|
107
|
+
} {
|
|
108
|
+
return {
|
|
109
|
+
cancellationToken: undefined,
|
|
110
|
+
toolCallId: undefined,
|
|
111
|
+
request: { session: makeParentSession() },
|
|
112
|
+
response: {}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
type SessionEvent = ActiveSessionChangedEvent | SessionCreatedEvent | SessionDeletedEvent | SessionRenamedEvent;
|
|
117
|
+
|
|
118
|
+
function makeChatService(newSession: ReturnType<typeof makeNewSession>): ChatService {
|
|
119
|
+
const responseCompleted = Promise.resolve({
|
|
120
|
+
response: { asString: () => 'agent response' }
|
|
121
|
+
});
|
|
122
|
+
return {
|
|
123
|
+
onSessionEvent: sinon.stub() as Event<SessionEvent>,
|
|
124
|
+
getSession: sinon.stub(),
|
|
125
|
+
getSessions: sinon.stub().returns([]),
|
|
126
|
+
getActiveSession: sinon.stub().returns({ id: 'active-session-id' }),
|
|
127
|
+
setActiveSession: sinon.stub(),
|
|
128
|
+
createSession: sinon.stub().returns(newSession),
|
|
129
|
+
sendRequest: sinon.stub().resolves({ responseCompleted }),
|
|
130
|
+
deleteSession: sinon.stub().resolves(),
|
|
131
|
+
renameSession: sinon.stub().resolves(),
|
|
132
|
+
getAgent: sinon.stub(),
|
|
133
|
+
deleteChangeSet: sinon.stub(),
|
|
134
|
+
deleteChangeSetElement: sinon.stub(),
|
|
135
|
+
cancelRequest: sinon.stub().resolves(),
|
|
136
|
+
getOrRestoreSession: sinon.stub().resolves(undefined),
|
|
137
|
+
getPersistedSessions: sinon.stub().resolves({}),
|
|
138
|
+
hasPersistedSessions: sinon.stub().resolves(false),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// --- Tests ---
|
|
143
|
+
|
|
144
|
+
describe('AgentDelegationTool', () => {
|
|
145
|
+
before(() => {
|
|
146
|
+
disableJSDOM = enableJSDOM();
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
after(() => {
|
|
150
|
+
disableJSDOM();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe('delegateToAgent() — taskContextId parameter', () => {
|
|
154
|
+
let contextManager: ReturnType<typeof makeContextManager>;
|
|
155
|
+
let tool: AgentDelegationTool;
|
|
156
|
+
let ctx: ReturnType<typeof makeChatContext>;
|
|
157
|
+
|
|
158
|
+
beforeEach(() => {
|
|
159
|
+
contextManager = makeContextManager();
|
|
160
|
+
const newSession = makeNewSession(contextManager);
|
|
161
|
+
const agentService = makeChatAgentService();
|
|
162
|
+
const chatService = makeChatService(newSession);
|
|
163
|
+
tool = makeAgentDelegationTool(agentService, chatService);
|
|
164
|
+
ctx = makeChatContext();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('injects TASK_CONTEXT_VARIABLE when taskContextId is provided', async () => {
|
|
168
|
+
const argString = JSON.stringify({ agentId: 'test-agent', prompt: 'do something', taskContextId: 'my-task-ctx-id' });
|
|
169
|
+
|
|
170
|
+
await tool.getTool().handler(argString, ctx);
|
|
171
|
+
|
|
172
|
+
expect(contextManager.addVariables.calledOnce).to.be.true;
|
|
173
|
+
const callArg: AIVariableResolutionRequest = contextManager.addVariables.firstCall.args[0];
|
|
174
|
+
expect(callArg.variable).to.equal(TASK_CONTEXT_VARIABLE);
|
|
175
|
+
expect(callArg.arg).to.equal('my-task-ctx-id');
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('does not inject any task context variable when taskContextId is not provided', async () => {
|
|
179
|
+
const argString = JSON.stringify({ agentId: 'test-agent', prompt: 'do something' });
|
|
180
|
+
|
|
181
|
+
await tool.getTool().handler(argString, ctx);
|
|
182
|
+
|
|
183
|
+
expect(contextManager.addVariables.called).to.be.false;
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('does not inject any task context variable when taskContextId is an empty string', async () => {
|
|
187
|
+
const argString = JSON.stringify({ agentId: 'test-agent', prompt: 'do something', taskContextId: '' });
|
|
188
|
+
|
|
189
|
+
await tool.getTool().handler(argString, ctx);
|
|
190
|
+
|
|
191
|
+
expect(contextManager.addVariables.called).to.be.false;
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
});
|
|
@@ -29,12 +29,13 @@ import {
|
|
|
29
29
|
ChatSession,
|
|
30
30
|
ChatRequestInvocation,
|
|
31
31
|
} from '../common';
|
|
32
|
+
import { TASK_CONTEXT_VARIABLE } from './task-context-variable';
|
|
32
33
|
|
|
33
34
|
@injectable()
|
|
34
35
|
export class AgentDelegationTool implements ToolProvider {
|
|
35
36
|
static ID = AGENT_DELEGATION_FUNCTION_ID;
|
|
36
37
|
|
|
37
|
-
protected readonly pendingDelegations = new Map<string, {
|
|
38
|
+
protected readonly pendingDelegations = new Map<string, { prompt: string; invocation: ChatRequestInvocation }>();
|
|
38
39
|
|
|
39
40
|
@inject(ChatAgentServiceFactory)
|
|
40
41
|
protected readonly getChatAgentService: () => ChatAgentService;
|
|
@@ -50,7 +51,8 @@ export class AgentDelegationTool implements ToolProvider {
|
|
|
50
51
|
'Delegate a task or question to a specific AI agent. IMPORTANT: When you delegate a task or question to a specific AI agent using this tool, ' +
|
|
51
52
|
'remember that each sub-agent operates solely within its specialized capabilities and tools and does not have access to previous conversation context ' +
|
|
52
53
|
' or external systems. Therefore, it is crucial to provide all necessary context and detailed information directly within your request to ensure accurate ' +
|
|
53
|
-
'and effective task completion.'
|
|
54
|
+
'and effective task completion. ' +
|
|
55
|
+
'You may optionally pass a taskContextId to make a specific task context (e.g. a plan) available to the delegated agent via its system prompt.',
|
|
54
56
|
parameters: {
|
|
55
57
|
type: 'object',
|
|
56
58
|
properties: {
|
|
@@ -64,6 +66,10 @@ export class AgentDelegationTool implements ToolProvider {
|
|
|
64
66
|
description:
|
|
65
67
|
'The task, question, or prompt to pass to the specified agent.',
|
|
66
68
|
},
|
|
69
|
+
taskContextId: {
|
|
70
|
+
type: 'string',
|
|
71
|
+
description: 'Optional task context ID to make available to the delegated agent. The agent will see the task context in its system prompt.',
|
|
72
|
+
},
|
|
67
73
|
},
|
|
68
74
|
required: ['agentId', 'prompt'],
|
|
69
75
|
},
|
|
@@ -74,7 +80,7 @@ export class AgentDelegationTool implements ToolProvider {
|
|
|
74
80
|
};
|
|
75
81
|
}
|
|
76
82
|
|
|
77
|
-
getDelegation(toolCallId: string): {
|
|
83
|
+
getDelegation(toolCallId: string): { prompt: string; invocation: ChatRequestInvocation } | undefined {
|
|
78
84
|
return this.pendingDelegations.get(toolCallId);
|
|
79
85
|
}
|
|
80
86
|
|
|
@@ -88,7 +94,7 @@ export class AgentDelegationTool implements ToolProvider {
|
|
|
88
94
|
|
|
89
95
|
try {
|
|
90
96
|
const args = JSON.parse(arg_string);
|
|
91
|
-
const { agentId, prompt } = args;
|
|
97
|
+
const { agentId, prompt, taskContextId } = args;
|
|
92
98
|
|
|
93
99
|
if (!agentId || !prompt) {
|
|
94
100
|
const errorMsg = 'Both agentId and prompt parameters are required.';
|
|
@@ -121,12 +127,20 @@ export class AgentDelegationTool implements ToolProvider {
|
|
|
121
127
|
{ focus: false },
|
|
122
128
|
agent
|
|
123
129
|
);
|
|
130
|
+
|
|
124
131
|
// Set root session ID to enable task context sharing across delegation chains
|
|
125
132
|
// Root is either the current root (for nested delegation) or current session (for first-level delegation)
|
|
126
133
|
const rootId = ctx.rootSessionId || ctx.request.session.id;
|
|
127
134
|
newSession.rootSessionId = rootId;
|
|
128
135
|
newSession.model.rootSessionId = rootId;
|
|
129
136
|
|
|
137
|
+
if (taskContextId) {
|
|
138
|
+
newSession.model.context.addVariables({
|
|
139
|
+
variable: TASK_CONTEXT_VARIABLE,
|
|
140
|
+
arg: taskContextId
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
130
144
|
// Immediately restore the original active session to avoid confusing the user
|
|
131
145
|
if (currentActiveSession) {
|
|
132
146
|
chatService.setActiveSession(currentActiveSession.id, { focus: false });
|
|
@@ -176,7 +190,6 @@ export class AgentDelegationTool implements ToolProvider {
|
|
|
176
190
|
// Store the invocation in the registry so the renderer can access it
|
|
177
191
|
if (ctx.toolCallId) {
|
|
178
192
|
this.pendingDelegations.set(ctx.toolCallId, {
|
|
179
|
-
agentName: agent.name,
|
|
180
193
|
prompt,
|
|
181
194
|
invocation: response
|
|
182
195
|
});
|