@@ -127,6 +127,7 @@ use types::{
127127 AgentSnapshot ,
128128 ConversationMetadata ,
129129 ConversationState ,
130+ EmbeddedUserMessages ,
130131} ;
131132use util:: path:: canonicalize_path_sys;
132133use util:: providers:: {
@@ -222,6 +223,7 @@ pub struct Agent {
222223 id : AgentId ,
223224 agent_config : AgentConfig ,
224225
226+ embedded_user_msgs : EmbeddedUserMessages ,
225227 conversation_state : ConversationState ,
226228 conversation_metadata : ConversationMetadata ,
227229 execution_state : ExecutionState ,
@@ -303,6 +305,7 @@ impl Agent {
303305 Ok ( Self {
304306 id : snapshot. id ,
305307 agent_config,
308+ embedded_user_msgs : Default :: default ( ) ,
306309 conversation_state : snapshot. conversation_state ,
307310 conversation_metadata : snapshot. conversation_metadata ,
308311 execution_state : snapshot. execution_state ,
@@ -323,6 +326,10 @@ impl Agent {
323326 } )
324327 }
325328
329+ pub fn set_embedded_user_msg ( & mut self , msg : & str ) {
330+ self . embedded_user_msgs . messages . push ( msg. to_string ( ) ) ;
331+ }
332+
326333 pub fn set_sys_provider ( & mut self , provider : impl SystemProvider ) {
327334 self . sys_provider = Arc :: new ( provider) ;
328335 }
@@ -981,6 +988,7 @@ impl Agent {
981988 self . make_tool_spec ( ) . await ,
982989 & self . agent_config ,
983990 self . agent_spawn_hooks . iter ( ) . map ( |( _, c) | c) ,
991+ & self . embedded_user_msgs ,
984992 & self . sys_provider ,
985993 )
986994 . await
@@ -1720,6 +1728,7 @@ async fn format_request<T, U, P>(
17201728 mut tool_spec : Vec < ToolSpec > ,
17211729 agent_config : & AgentConfig ,
17221730 agent_spawn_hooks : T ,
1731+ embedded_user_msgs : & EmbeddedUserMessages ,
17231732 provider : & P ,
17241733) -> SendRequestArgs
17251734where
@@ -1734,10 +1743,20 @@ where
17341743 messages. push_front ( msg) ;
17351744 }
17361745
1746+ let system_prompt = match ( agent_config. system_prompt ( ) , embedded_user_msgs. messages . is_empty ( ) ) {
1747+ ( Some ( system_prompt) , false ) => {
1748+ let embedded_user_msgs_as_str = embedded_user_msgs. to_string ( ) ;
1749+ Some ( format ! ( "{embedded_user_msgs_as_str}\n {system_prompt}" ) )
1750+ } ,
1751+ ( Some ( system_prompt) , true ) => Some ( system_prompt. to_string ( ) ) ,
1752+ ( None , false ) => Some ( embedded_user_msgs. to_string ( ) ) ,
1753+ ( _, _) => None ,
1754+ } ;
1755+
17371756 SendRequestArgs :: new (
17381757 messages. into ( ) ,
17391758 if tool_spec. is_empty ( ) { None } else { Some ( tool_spec) } ,
1740- agent_config . system_prompt ( ) . map ( String :: from ) ,
1759+ system_prompt,
17411760 )
17421761}
17431762
0 commit comments