@@ -847,6 +847,23 @@ pub(crate) async fn run_with_tools(
847847 runtime_context,
848848 ) ;
849849
850+ // Create a shared steer inbox that the gateway can push steering text into.
851+ // A background task polls the ChatRuntime and forwards any `/steer` text.
852+ let steer_inbox: moltis_agents:: runner:: SteerInbox = Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ;
853+ let steer_inbox_writer = steer_inbox. clone ( ) ;
854+ let steer_state = state. clone ( ) ;
855+ let steer_session_key = session_key. to_string ( ) ;
856+ let steer_task = tokio:: spawn ( async move {
857+ // Drain any stale steering text left over from a previous run.
858+ let _ = steer_state. take_steer_text ( & steer_session_key) . await ;
859+ loop {
860+ tokio:: time:: sleep ( Duration :: from_millis ( 500 ) ) . await ;
861+ if let Some ( texts) = steer_state. take_steer_text ( & steer_session_key) . await {
862+ steer_inbox_writer. lock ( ) . await . extend ( texts) ;
863+ }
864+ }
865+ } ) ;
866+
850867 let provider_ref = provider. clone ( ) ;
851868 let first_result = run_agent_loop_streaming (
852869 provider,
@@ -858,6 +875,7 @@ pub(crate) async fn run_with_tools(
858875 Some ( tool_context. clone ( ) ) ,
859876 hook_registry. clone ( ) ,
860877 sender_name. clone ( ) ,
878+ Some ( steer_inbox. clone ( ) ) ,
861879 )
862880 . await ;
863881
@@ -956,6 +974,7 @@ pub(crate) async fn run_with_tools(
956974 Some ( tool_context) ,
957975 hook_registry,
958976 sender_name,
977+ Some ( steer_inbox. clone ( ) ) ,
959978 )
960979 . await
961980 } ,
@@ -981,6 +1000,7 @@ pub(crate) async fn run_with_tools(
9811000 } ,
9821001 other => other,
9831002 } ;
1003+ steer_task. abort ( ) ;
9841004
9851005 // Ensure all runner events (including deltas) are broadcast in order before
9861006 // emitting terminal final/error frames.
0 commit comments