@@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
77use serde_json:: Value ;
88use uuid:: Uuid ;
99
10- use crate :: { Agent , AgentId , Context , Error , Event , ModelId , Result , Workflow } ;
10+ use crate :: { Agent , AgentId , Compact , Context , Error , Event , ModelId , Result , Workflow } ;
1111
1212#[ derive( Debug , Display , Serialize , Deserialize , Clone , PartialEq , Eq , Hash ) ]
1313#[ serde( transparent) ]
@@ -105,7 +105,17 @@ impl Conversation {
105105 }
106106
107107 if let Some ( model) = workflow. model . clone ( ) {
108- agent. model = Some ( model) ;
108+ agent. model = Some ( model. clone ( ) ) ;
109+
110+ // If a workflow model is specified, ensure all agents have a compact model
111+ // initialized with that model, creating the compact configuration if needed
112+ if agent. compact . is_some ( ) {
113+ if let Some ( ref mut compact) = agent. compact {
114+ compact. model = model;
115+ }
116+ } else {
117+ agent. compact = Some ( Compact :: new ( model) ) ;
118+ }
109119 }
110120
111121 if let Some ( tool_supported) = workflow. tool_supported {
@@ -294,7 +304,7 @@ mod tests {
294304
295305 use serde_json:: json;
296306
297- use crate :: { Agent , Command , Error , ModelId , Temperature , Workflow } ;
307+ use crate :: { Agent , AgentId , Command , Compact , Error , ModelId , Temperature , Workflow } ;
298308
299309 #[ test]
300310 fn test_conversation_new_with_empty_workflow ( ) {
@@ -684,4 +694,39 @@ mod tests {
684694 . unwrap ( ) ;
685695 assert_eq ! ( agent2. tool_supported, Some ( true ) ) ;
686696 }
697+
698+ #[ test]
699+ fn test_workflow_model_overrides_compact_model ( ) {
700+ // Arrange
701+ let id = super :: ConversationId :: generate ( ) ;
702+
703+ // Create an agent with compaction configured
704+ let agent1 =
705+ Agent :: new ( "agent1" ) . compact ( Compact :: new ( ModelId :: new ( "old-compaction-model" ) ) ) ;
706+
707+ // Create an agent without compaction
708+ let agent2 = Agent :: new ( "agent2" ) ;
709+
710+ // Use setters pattern to create the workflow
711+ let workflow = Workflow :: new ( )
712+ . agents ( vec ! [ agent1, agent2] )
713+ . model ( ModelId :: new ( "workflow-model" ) ) ;
714+
715+ // Act
716+ let conversation = super :: Conversation :: new_inner ( id. clone ( ) , workflow) ;
717+
718+ // Check that agent1's compact.model was updated to the workflow model
719+ let agent1 = conversation. get_agent ( & AgentId :: new ( "agent1" ) ) . unwrap ( ) ;
720+ let compact = agent1. compact . as_ref ( ) . unwrap ( ) ;
721+ assert_eq ! ( compact. model, ModelId :: new( "workflow-model" ) ) ;
722+
723+ // Regular agent model should also be updated
724+ assert_eq ! ( agent1. model, Some ( ModelId :: new( "workflow-model" ) ) ) ;
725+
726+ // Check that agent2 still has no compaction
727+ let agent2 = conversation. get_agent ( & AgentId :: new ( "agent2" ) ) . unwrap ( ) ;
728+ let compact = agent2. compact . as_ref ( ) . unwrap ( ) ;
729+ assert_eq ! ( compact. model, ModelId :: new( "workflow-model" ) ) ;
730+ assert_eq ! ( agent2. model, Some ( ModelId :: new( "workflow-model" ) ) ) ;
731+ }
687732}
0 commit comments