@@ -12,13 +12,17 @@ import type { Config } from '../config/config.js';
1212import type { MessageBus } from '../confirmation-bus/message-bus.js' ;
1313import { LocalSubagentInvocation } from './local-invocation.js' ;
1414import { RemoteAgentInvocation } from './remote-invocation.js' ;
15+ import { LocalSessionInvocation } from './local-session-invocation.js' ;
16+ import { RemoteSessionInvocation } from './remote-session-invocation.js' ;
1517import { BrowserAgentInvocation } from './browser/browserAgentInvocation.js' ;
1618import { BROWSER_AGENT_NAME } from './browser/browserAgentDefinition.js' ;
1719import { AgentRegistry } from './registry.js' ;
1820import type { LocalAgentDefinition , RemoteAgentDefinition } from './types.js' ;
1921
2022vi . mock ( './local-invocation.js' ) ;
2123vi . mock ( './remote-invocation.js' ) ;
24+ vi . mock ( './local-session-invocation.js' ) ;
25+ vi . mock ( './remote-session-invocation.js' ) ;
2226vi . mock ( './browser/browserAgentInvocation.js' ) ;
2327
2428describe ( 'AgentTool' , ( ) => {
@@ -141,4 +145,122 @@ describe('AgentTool', () => {
141145 'Invoke Browser Agent' ,
142146 ) ;
143147 } ) ;
148+
149+ describe ( 'agentSessionSubagentEnabled feature flag' , ( ) => {
150+ it ( 'should use LocalSessionInvocation when flag is enabled for local agent' , async ( ) => {
151+ vi . spyOn ( mockConfig , 'isAgentSessionSubagentEnabled' ) . mockReturnValue (
152+ true ,
153+ ) ;
154+ tool = new AgentTool ( mockConfig , mockMessageBus ) ;
155+
156+ const params = {
157+ agent_name : 'TestLocalAgent' ,
158+ prompt : 'Do something' ,
159+ } ;
160+ const invocation = tool [ 'createInvocation' ] ( params , mockMessageBus ) ;
161+ await invocation . shouldConfirmExecute ( new AbortController ( ) . signal ) ;
162+
163+ expect ( LocalSessionInvocation ) . toHaveBeenCalledWith (
164+ testLocalDefinition ,
165+ mockConfig ,
166+ { objective : 'Do something' } ,
167+ mockMessageBus ,
168+ undefined ,
169+ ) ;
170+ expect ( LocalSubagentInvocation ) . not . toHaveBeenCalled ( ) ;
171+ } ) ;
172+
173+ it ( 'should use RemoteSessionInvocation when flag is enabled for remote agent' , async ( ) => {
174+ vi . spyOn ( mockConfig , 'isAgentSessionSubagentEnabled' ) . mockReturnValue (
175+ true ,
176+ ) ;
177+ tool = new AgentTool ( mockConfig , mockMessageBus ) ;
178+
179+ const params = {
180+ agent_name : 'TestRemoteAgent' ,
181+ prompt : 'Search something' ,
182+ } ;
183+ const invocation = tool [ 'createInvocation' ] ( params , mockMessageBus ) ;
184+ await invocation . shouldConfirmExecute ( new AbortController ( ) . signal ) ;
185+
186+ expect ( RemoteSessionInvocation ) . toHaveBeenCalledWith (
187+ testRemoteDefinition ,
188+ mockConfig ,
189+ { query : 'Search something' } ,
190+ mockMessageBus ,
191+ undefined ,
192+ ) ;
193+ expect ( RemoteAgentInvocation ) . not . toHaveBeenCalled ( ) ;
194+ } ) ;
195+
196+ it ( 'should use legacy invocations when flag is disabled (default)' , async ( ) => {
197+ vi . spyOn ( mockConfig , 'isAgentSessionSubagentEnabled' ) . mockReturnValue (
198+ false ,
199+ ) ;
200+ tool = new AgentTool ( mockConfig , mockMessageBus ) ;
201+
202+ const localParams = {
203+ agent_name : 'TestLocalAgent' ,
204+ prompt : 'Do something' ,
205+ } ;
206+ const localInv = tool [ 'createInvocation' ] ( localParams , mockMessageBus ) ;
207+ await localInv . shouldConfirmExecute ( new AbortController ( ) . signal ) ;
208+
209+ expect ( LocalSubagentInvocation ) . toHaveBeenCalled ( ) ;
210+ expect ( LocalSessionInvocation ) . not . toHaveBeenCalled ( ) ;
211+
212+ vi . clearAllMocks ( ) ;
213+
214+ const remoteParams = {
215+ agent_name : 'TestRemoteAgent' ,
216+ prompt : 'Search' ,
217+ } ;
218+ const remoteInv = tool [ 'createInvocation' ] ( remoteParams , mockMessageBus ) ;
219+ await remoteInv . shouldConfirmExecute ( new AbortController ( ) . signal ) ;
220+
221+ expect ( RemoteAgentInvocation ) . toHaveBeenCalled ( ) ;
222+ expect ( RemoteSessionInvocation ) . not . toHaveBeenCalled ( ) ;
223+ } ) ;
224+
225+ it ( 'should thread onAgentEvent to session invocations' , async ( ) => {
226+ vi . spyOn ( mockConfig , 'isAgentSessionSubagentEnabled' ) . mockReturnValue (
227+ true ,
228+ ) ;
229+ const onEvent = vi . fn ( ) ;
230+ tool = new AgentTool ( mockConfig , mockMessageBus , onEvent ) ;
231+
232+ const params = {
233+ agent_name : 'TestLocalAgent' ,
234+ prompt : 'Do something' ,
235+ } ;
236+ const invocation = tool [ 'createInvocation' ] ( params , mockMessageBus ) ;
237+ await invocation . shouldConfirmExecute ( new AbortController ( ) . signal ) ;
238+
239+ expect ( LocalSessionInvocation ) . toHaveBeenCalledWith (
240+ testLocalDefinition ,
241+ mockConfig ,
242+ { objective : 'Do something' } ,
243+ mockMessageBus ,
244+ { onAgentEvent : onEvent } ,
245+ ) ;
246+ } ) ;
247+
248+ it ( 'should always use BrowserAgentInvocation for browser agent regardless of flag' , async ( ) => {
249+ vi . spyOn ( mockConfig , 'isAgentSessionSubagentEnabled' ) . mockReturnValue (
250+ true ,
251+ ) ;
252+ tool = new AgentTool ( mockConfig , mockMessageBus ) ;
253+
254+ const params = {
255+ agent_name : BROWSER_AGENT_NAME ,
256+ prompt : 'Open page' ,
257+ } ;
258+ const invocation = tool [ 'createInvocation' ] ( params , mockMessageBus ) ;
259+ await invocation . shouldConfirmExecute ( new AbortController ( ) . signal ) ;
260+
261+ expect ( BrowserAgentInvocation ) . toHaveBeenCalled ( ) ;
262+ expect ( LocalSessionInvocation ) . not . toHaveBeenCalled ( ) ;
263+ expect ( RemoteSessionInvocation ) . not . toHaveBeenCalled ( ) ;
264+ } ) ;
265+ } ) ;
144266} ) ;
0 commit comments