@@ -7,6 +7,8 @@ use agent_client_protocol_schema::{
77 NewSessionResponse , PromptRequest , PromptResponse , Result , SetSessionConfigOptionRequest ,
88 SetSessionConfigOptionResponse , SetSessionModeRequest , SetSessionModeResponse ,
99} ;
10+ #[ cfg( feature = "unstable_session_close" ) ]
11+ use agent_client_protocol_schema:: { CloseSessionRequest , CloseSessionResponse } ;
1012#[ cfg( feature = "unstable_session_fork" ) ]
1113use agent_client_protocol_schema:: { ForkSessionRequest , ForkSessionResponse } ;
1214#[ cfg( feature = "unstable_session_resume" ) ]
@@ -183,6 +185,21 @@ pub trait Agent {
183185 Err ( Error :: method_not_found ( ) )
184186 }
185187
188+ /// **UNSTABLE**
189+ ///
190+ /// This capability is not part of the spec yet, and may be removed or changed at any point.
191+ ///
192+ /// Closes an active session, freeing up any resources associated with it.
193+ ///
194+ /// The agent must cancel any ongoing work (as if `session/cancel` was called)
195+ /// and then free up any resources associated with the session.
196+ ///
197+ /// Only available if the Agent supports the `session.close` capability.
198+ #[ cfg( feature = "unstable_session_close" ) ]
199+ async fn close_session ( & self , _args : CloseSessionRequest ) -> Result < CloseSessionResponse > {
200+ Err ( Error :: method_not_found ( ) )
201+ }
202+
186203 /// Handles extension method requests from the client.
187204 ///
188205 /// Extension methods provide a way to add custom functionality while maintaining
@@ -255,6 +272,10 @@ impl<T: Agent> Agent for Rc<T> {
255272 async fn resume_session ( & self , args : ResumeSessionRequest ) -> Result < ResumeSessionResponse > {
256273 self . as_ref ( ) . resume_session ( args) . await
257274 }
275+ #[ cfg( feature = "unstable_session_close" ) ]
276+ async fn close_session ( & self , args : CloseSessionRequest ) -> Result < CloseSessionResponse > {
277+ self . as_ref ( ) . close_session ( args) . await
278+ }
258279 async fn ext_method ( & self , args : ExtRequest ) -> Result < ExtResponse > {
259280 self . as_ref ( ) . ext_method ( args) . await
260281 }
@@ -313,6 +334,10 @@ impl<T: Agent> Agent for Arc<T> {
313334 async fn resume_session ( & self , args : ResumeSessionRequest ) -> Result < ResumeSessionResponse > {
314335 self . as_ref ( ) . resume_session ( args) . await
315336 }
337+ #[ cfg( feature = "unstable_session_close" ) ]
338+ async fn close_session ( & self , args : CloseSessionRequest ) -> Result < CloseSessionResponse > {
339+ self . as_ref ( ) . close_session ( args) . await
340+ }
316341 async fn ext_method ( & self , args : ExtRequest ) -> Result < ExtResponse > {
317342 self . as_ref ( ) . ext_method ( args) . await
318343 }
0 commit comments