@@ -175,16 +175,96 @@ func (agent *Agent) ResumeSession(
175175 return agent .newSession (ctx , op , params )
176176}
177177
178+ func (agent * Agent ) ReplaceSession (
179+ ctx context.Context ,
180+ current * Session ,
181+ options * SessionOptions ,
182+ ) (* Session , error ) {
183+ const op = "agent_replace_session"
184+ if err := validateAgent (agent , ctx , op ); err != nil {
185+ return nil , err
186+ }
187+ if current == nil || current .handle == "" {
188+ return nil , invalid (op , "current session is not initialized" )
189+ }
190+ params := current .params ()
191+ params ["agent_id" ] = agent .id
192+ if options != nil {
193+ params ["options" ] = options
194+ }
195+ return agent .newSession (ctx , op , params )
196+ }
197+
198+ func (agent * Agent ) SessionForAgent (
199+ ctx context.Context ,
200+ workspace string ,
201+ agentName string ,
202+ agentDirs []string ,
203+ options * SessionOptions ,
204+ ) (* Session , error ) {
205+ const op = "agent_session_for_agent"
206+ if err := validateAgent (agent , ctx , op ); err != nil {
207+ return nil , err
208+ }
209+ if strings .TrimSpace (workspace ) == "" {
210+ return nil , invalid (op , "workspace cannot be empty" )
211+ }
212+ if strings .TrimSpace (agentName ) == "" {
213+ return nil , invalid (op , "agent name cannot be empty" )
214+ }
215+ params := map [string ]any {
216+ "agent_id" : agent .id ,
217+ "workspace" : workspace ,
218+ "agent_name" : agentName ,
219+ "agent_dirs" : agentDirs ,
220+ }
221+ if options != nil {
222+ params ["options" ] = options
223+ }
224+ return agent .newSession (ctx , op , params )
225+ }
226+
227+ func (agent * Agent ) SessionForWorker (
228+ ctx context.Context ,
229+ workspace string ,
230+ worker WorkerAgentSpec ,
231+ options * SessionOptions ,
232+ ) (* Session , error ) {
233+ const op = "agent_session_for_worker"
234+ if err := validateAgent (agent , ctx , op ); err != nil {
235+ return nil , err
236+ }
237+ if strings .TrimSpace (workspace ) == "" {
238+ return nil , invalid (op , "workspace cannot be empty" )
239+ }
240+ if strings .TrimSpace (worker .Name ) == "" || strings .TrimSpace (worker .Description ) == "" {
241+ return nil , invalid (op , "worker name and description cannot be empty" )
242+ }
243+ params := map [string ]any {
244+ "agent_id" : agent .id ,
245+ "workspace" : workspace ,
246+ "worker" : worker ,
247+ }
248+ if options != nil {
249+ params ["options" ] = options
250+ }
251+ return agent .newSession (ctx , op , params )
252+ }
253+
178254func (agent * Agent ) newSession (
179255 ctx context.Context ,
180256 operation string ,
181257 params map [string ]any ,
182258) (* Session , error ) {
183259 var created struct {
184- SessionHandle string `json:"session_handle"`
185- SessionID string `json:"session_id"`
186- Workspace string `json:"workspace"`
187- InitWarning * string `json:"init_warning"`
260+ SessionHandle string `json:"session_handle"`
261+ SessionID string `json:"session_id"`
262+ Workspace string `json:"workspace"`
263+ InitWarning * string `json:"init_warning"`
264+ TenantID * string `json:"tenant_id"`
265+ Principal * string `json:"principal"`
266+ AgentTemplateID * string `json:"agent_template_id"`
267+ CorrelationID * string `json:"correlation_id"`
188268 }
189269 if err := agent .runtime .Request (ctx , operation , params , & created ); err != nil {
190270 return nil , err
@@ -198,11 +278,15 @@ func (agent *Agent) newSession(
198278 )
199279 }
200280 return & Session {
201- runtime : agent .runtime ,
202- handle : created .SessionHandle ,
203- id : created .SessionID ,
204- workspace : created .Workspace ,
205- initWarning : created .InitWarning ,
281+ runtime : agent .runtime ,
282+ handle : created .SessionHandle ,
283+ id : created .SessionID ,
284+ workspace : created .Workspace ,
285+ initWarning : created .InitWarning ,
286+ tenantID : created .TenantID ,
287+ principal : created .Principal ,
288+ agentTemplateID : created .AgentTemplateID ,
289+ correlationID : created .CorrelationID ,
206290 }, nil
207291}
208292
@@ -251,6 +335,80 @@ func (agent *Agent) CloseSession(ctx context.Context, sessionID string) (bool, e
251335 return result .Closed , err
252336}
253337
338+ func (agent * Agent ) DisconnectIdleMCP (
339+ ctx context.Context ,
340+ idleThresholdMS uint64 ,
341+ ) ([]string , error ) {
342+ const op = "agent_disconnect_idle_mcp"
343+ if err := validateAgent (agent , ctx , op ); err != nil {
344+ return nil , err
345+ }
346+ var result struct {
347+ Names []string `json:"names"`
348+ }
349+ err := agent .runtime .Request (ctx , op , map [string ]any {
350+ "agent_id" : agent .id ,
351+ "idle_threshold_ms" : idleThresholdMS ,
352+ }, & result )
353+ return result .Names , err
354+ }
355+
356+ type ServeHandle struct {
357+ runtime Runtime
358+ handle string
359+ stopOnce sync.Once
360+ stopErr error
361+ }
362+
363+ func (agent * Agent ) ServeAgentDir (
364+ ctx context.Context ,
365+ dir string ,
366+ workspace string ,
367+ options * SessionOptions ,
368+ ) (* ServeHandle , error ) {
369+ const op = "agent_serve_agent_dir"
370+ if err := validateAgent (agent , ctx , op ); err != nil {
371+ return nil , err
372+ }
373+ if strings .TrimSpace (dir ) == "" || strings .TrimSpace (workspace ) == "" {
374+ return nil , invalid (op , "agent directory and workspace cannot be empty" )
375+ }
376+ params := map [string ]any {
377+ "agent_id" : agent .id ,
378+ "dir" : dir ,
379+ "workspace" : workspace ,
380+ }
381+ if options != nil {
382+ params ["options" ] = options
383+ }
384+ var result struct {
385+ Handle string `json:"serve_handle"`
386+ }
387+ if err := agent .runtime .Request (ctx , op , params , & result ); err != nil {
388+ return nil , err
389+ }
390+ if result .Handle == "" {
391+ return nil , sdkError (op , CodeProtocol , "bridge returned an empty serve handle" , nil )
392+ }
393+ return & ServeHandle {runtime : agent .runtime , handle : result .Handle }, nil
394+ }
395+
396+ func (handle * ServeHandle ) Stop (ctx context.Context ) error {
397+ const op = "agent_stop_serve"
398+ if handle == nil {
399+ return nil
400+ }
401+ if ctx == nil {
402+ return invalid (op , "context cannot be nil" )
403+ }
404+ handle .stopOnce .Do (func () {
405+ handle .stopErr = handle .runtime .Request (ctx , op , map [string ]any {
406+ "serve_handle" : handle .handle ,
407+ }, nil )
408+ })
409+ return handle .stopErr
410+ }
411+
254412func (agent * Agent ) IsClosed (ctx context.Context ) (bool , error ) {
255413 const op = "agent_is_closed"
256414 if err := validateAgent (agent , ctx , op ); err != nil {
0 commit comments