@@ -247,6 +247,7 @@ We're going to have the agent ask us to name it, so we'll need a state property
247247 # Interrupt and wait for the user to respond with a name
248248 answer, messages = copilotkit_interrupt(message = ' Before we start, what would you like to call me?' ) # [!code highlight]
249249 state[" agent_name" ] = answer
250+ state[" messages" ] = [* state[" messages" ], * messages]
250251
251252 # Tell the agent its name
252253 system_message = SystemMessage(
@@ -260,7 +261,8 @@ We're going to have the agent ask us to name it, so we'll need a state property
260261
261262 return {
262263 ** state,
263- " messages" : response,
264+ # messages receives from the interrupt are not automatically saved to state, don't forget to add them!
265+ " messages" : [* state[" messages" ], response],
264266 }
265267 ```
266268 </Tab >
@@ -275,6 +277,7 @@ We're going to have the agent ask us to name it, so we'll need a state property
275277 if (! state .agentName ) {
276278 const { answer, messages } = copilotKitInterrupt ({ message: ' Before we start, what would you like to call me?' }); // [!code highlight]
277279 state .agentName = answer
280+ state .messages = [... state .message , ... messages ]
278281 }
279282
280283 // Tell the agent its name
@@ -289,7 +292,8 @@ We're going to have the agent ask us to name it, so we'll need a state property
289292
290293 return {
291294 ... state ,
292- messages: response ,
295+ // messages receives from the interrupt are not automatically saved to state, don't forget to add them!
296+ messages: [... state .messages , response ],
293297 };
294298 }
295299 ```
@@ -306,8 +310,8 @@ We're going to have the agent ask us to name it, so we'll need a state property
306310
307311 export function YourComponent() {
308312 useCopilotAction ({
309- name: " showCalendarMeeting " ,
310- description: " Displays calendar meeting information " ,
313+ name: " AskName " ,
314+ description: " Ask the user how they would like to call you " ,
311315 parameters: [
312316 {
313317 name: " message" ,
@@ -346,6 +350,7 @@ We're going to have the agent ask us to name it, so we'll need a state property
346350 args = { " message" : " Before we start, what would you like to call me?" } # The arguments to pass when the tool is called.
347351 )
348352 state[" agent_name" ] = answer
353+ state[" messages" ] = [* state[" messages" ], * messages]
349354
350355 # Tell the agent its name
351356 system_message = SystemMessage(
@@ -359,7 +364,8 @@ We're going to have the agent ask us to name it, so we'll need a state property
359364
360365 return {
361366 ** state,
362- " messages" : response,
367+ # messages receives from the interrupt are not automatically saved to state, don't forget to add them!
368+ " messages" : [* state[" messages" ], response],
363369 }
364370 ```
365371 </Tab >
@@ -378,6 +384,7 @@ We're going to have the agent ask us to name it, so we'll need a state property
378384 args: { message: ' Before we start, what would you like to call me?' }, // The arguments to pass when the tool is called.
379385 }); // [!code highlight]
380386 state .agentName = answer
387+ state .messages = [... state .message , ... messages ]
381388 }
382389
383390 // Tell the agent its name
@@ -392,7 +399,8 @@ We're going to have the agent ask us to name it, so we'll need a state property
392399
393400 return {
394401 ... state ,
395- messages: response ,
402+ // messages receives from the interrupt are not automatically saved to state, don't forget to add them!
403+ messages: [... state .messages , response ],
396404 };
397405 }
398406 ```
@@ -424,9 +432,14 @@ These can be used to notify the LLM about the recent communication:
424432 from copilotkit import copilotkit_interrupt
425433
426434 # ...
427- agent_name, new_messages = copilotkit_interrupt(message = " Before we start, what would you like to call me?" )
428- state[" messages" ] = state[" messages" ] + new_messages
429- state[" agent_name" ] = agent_name
435+ async def chat_node (state : AgentState, config : RunnableConfig)
436+ agent_name, new_messages = copilotkit_interrupt(message = " Before we start, what would you like to call me?" )
437+ state[" messages" ] = state[" messages" ] + new_messages
438+ state[" agent_name" ] = agent_name
439+ # ... add the rest of the node implementation, including LLM calls etc.
440+
441+ # Don't forget to return the messages list with our newly added interrupt messages, and the new agent name
442+ return { " messages" : state[" messages" ], " agent_name" : state[" agent_name" ] }
430443 # ...
431444 ```
432445 </Tab >
@@ -435,10 +448,15 @@ These can be used to notify the LLM about the recent communication:
435448 import { copilotKitInterrupt } from " @copilotkit/sdk-js/langgraph" ;
436449
437450 // ...
438- const {agentName, newMessages} = copilotKitInterrupt (" Before we start, what would you like to call me?" );
439- state .messages = [... state .messages , ... newMessages ];
440- state .agentName = agentName ;
441- // ...
451+ async function chat_node(state : AgentState , config : RunnableConfig ) {
452+ const { agentName, messages } = copilotKitInterrupt ({ message: " Before we start, what would you like to call me?" });
453+ state .messages = [... state .messages , ... messages ];
454+ state .agentName = agentName ;
455+ // ... add the rest of the node implementation, including LLM calls etc.
456+
457+ // Don't forget to return the messages list with our newly added interrupt messages, and the new agent name
458+ return { messages: state .messages , agentName: state .agentName }
459+ }
442460 ```
443461 </Tab >
444462</Tabs >
0 commit comments