@@ -26,7 +26,10 @@ interface ExecutionArgs extends Omit<LangGraphPlatformEndpoint, "agents"> {
2626 nodeName : string ;
2727 messages : Message [ ] ;
2828 state : State ;
29- configurable ?: Record < string , any > ;
29+ config ?: {
30+ configurable ?: Record < string , any > ;
31+ [ key : string ] : any ;
32+ } ;
3033 properties : CopilotRequestContextProperties ;
3134 actions : ExecutionAction [ ] ;
3235 logger : Logger ;
@@ -119,7 +122,7 @@ async function streamEvents(controller: ReadableStreamDefaultController, args: E
119122 agent,
120123 nodeName : initialNodeName ,
121124 state : initialState ,
122- configurable ,
125+ config : explicitConfig ,
123126 messages,
124127 actions,
125128 logger,
@@ -234,11 +237,40 @@ async function streamEvents(controller: ReadableStreamDefaultController, args: E
234237 const graphInfo = await client . assistants . getGraph ( assistantId ) ;
235238 const graphSchema = await client . assistants . getSchemas ( assistantId ) ;
236239 const schemaKeys = getSchemaKeys ( graphSchema ) ;
237- if ( configurable ) {
238- const filteredConfigurable = schemaKeys ?. config
239- ? filterObjectBySchemaKeys ( configurable , schemaKeys ?. config )
240- : configurable ;
241- await client . assistants . update ( assistantId , { config : { configurable : filteredConfigurable } } ) ;
240+
241+ if ( explicitConfig ) {
242+ let filteredConfigurable = retrievedAssistant . config . configurable ;
243+ if ( explicitConfig . configurable ) {
244+ filteredConfigurable = schemaKeys ?. config
245+ ? filterObjectBySchemaKeys ( explicitConfig ?. configurable , schemaKeys ?. config )
246+ : explicitConfig ?. configurable ;
247+ }
248+
249+ const newConfig = {
250+ ...retrievedAssistant . config ,
251+ ...explicitConfig ,
252+ configurable : filteredConfigurable ,
253+ } ;
254+
255+ // LG does not return recursion limit if it's the default, therefore we check: if no recursion limit is currently set, and the user asked for 25, there is no change.
256+ const isRecursionLimitSetToDefault =
257+ retrievedAssistant . config . recursion_limit == null && explicitConfig . recursion_limit === 25 ;
258+ // Deep compare configs to avoid unnecessary update calls
259+ const configsAreDifferent =
260+ JSON . stringify ( newConfig ) !== JSON . stringify ( retrievedAssistant . config ) ;
261+
262+ // Check if the only difference is the recursion_limit being set to default
263+ const isOnlyRecursionLimitDifferent =
264+ isRecursionLimitSetToDefault &&
265+ JSON . stringify ( { ...newConfig , recursion_limit : null } ) ===
266+ JSON . stringify ( { ...retrievedAssistant . config , recursion_limit : null } ) ;
267+
268+ // If configs are different, we further check: Is the only diff a request to set the recursion limit to its already default?
269+ if ( configsAreDifferent && ! isOnlyRecursionLimitDifferent ) {
270+ await client . assistants . update ( assistantId , {
271+ config : newConfig ,
272+ } ) ;
273+ }
242274 }
243275
244276 // Do not input keys that are not part of the input schema
0 commit comments