@@ -1179,11 +1179,14 @@ def _select_skills_for_prompt(self, prompt: str) -> None:
11791179 def _setup_run (self , prompt : str , thread_id : str | None ) -> tuple [dict , dict ]:
11801180 """Reset per-run counters and build the LangGraph inputs/config dicts.
11811181
1182- Shared by ``run()``, ``arun()``, and ``run_stream()``. Does *not*
1183- reset ``self.log`` — callers that maintain a log do so explicitly.
1182+ Shared by ``run()``, ``arun()``, and ``run_stream()``. Resets
1183+ ``_interrupted`` because any prior interrupt is irrelevant to a new run.
1184+ Does *not* reset ``self.log`` — ``resume()``/``reject()`` append to the
1185+ existing log rather than starting fresh, so they manage it themselves.
11841186 """
11851187 self .critic_count = 0
11861188 self .user_task = prompt
1189+ self ._interrupted = False
11871190 # Reset per-run counters; mark the start index in usage_metrics for
11881191 # per-run cost budget checks (existing metrics are preserved for
11891192 # lifetime cost tracking via agent._usage_metrics)
@@ -1204,15 +1207,15 @@ def _setup_run(self, prompt: str, thread_id: str | None) -> tuple[dict, dict]:
12041207 self ._run_config = config
12051208 return inputs , config
12061209
1207- def _post_stream_result (self , graph_state , final_state , last_msg ):
1210+ def _post_stream_result (self , graph_state , last_values , last_msg ):
12081211 """Set conversation state, detect interrupt, and return ``(log, content)``.
12091212
12101213 Shared by ``run()``, ``arun()``, ``resume()``, ``aresume()``,
12111214 ``reject()``, and ``areject()``. The caller fetches ``graph_state``
12121215 via ``get_state()`` (sync) or ``await aget_state()`` (async) and
12131216 passes it in, keeping this helper synchronous.
12141217 """
1215- self ._conversation_state = final_state
1218+ self ._conversation_state = last_values
12161219 for task in (graph_state .tasks or []):
12171220 if hasattr (task , "interrupts" ) and task .interrupts :
12181221 self ._interrupted = True
@@ -1242,13 +1245,13 @@ def run(self, prompt: str, thread_id: str | None = None):
12421245 inputs , config = self ._setup_run (prompt , thread_id )
12431246 self .log = []
12441247 last_msg = None
1245- final_state = None
1248+ last_values = None
12461249 for state in self .app .stream (inputs , stream_mode = "values" , config = config ):
12471250 last_msg = state ["input" ][- 1 ]
12481251 self .log .append (pretty_print (last_msg ))
1249- final_state = state
1252+ last_values = state
12501253 graph_state = self .app .get_state (config )
1251- return self ._post_stream_result (graph_state , final_state , last_msg )
1254+ return self ._post_stream_result (graph_state , last_values , last_msg )
12521255
12531256 def resume (self ):
12541257 """Approve the pending code block and continue execution.
@@ -1268,13 +1271,13 @@ def resume(self):
12681271
12691272 config = self ._run_config
12701273 last_msg = None
1271- final_state = None
1274+ last_values = None
12721275 for state in self .app .stream (Command (resume = True ), stream_mode = "values" , config = config ):
12731276 last_msg = state ["input" ][- 1 ]
12741277 self .log .append (pretty_print (last_msg ))
1275- final_state = state
1278+ last_values = state
12761279 graph_state = self .app .get_state (config )
1277- return self ._post_stream_result (graph_state , final_state , last_msg )
1280+ return self ._post_stream_result (graph_state , last_values , last_msg )
12781281
12791282 def reject (self , feedback : str = "User rejected this code. Try a different approach." ):
12801283 """Reject the pending code block and provide feedback to the agent.
@@ -1298,17 +1301,17 @@ def reject(self, feedback: str = "User rejected this code. Try a different appro
12981301
12991302 config = self ._run_config
13001303 last_msg = None
1301- final_state = None
1304+ last_values = None
13021305 for state in self .app .stream (
13031306 Command (resume = {"approved" : False , "feedback" : feedback }),
13041307 stream_mode = "values" ,
13051308 config = config ,
13061309 ):
13071310 last_msg = state ["input" ][- 1 ]
13081311 self .log .append (pretty_print (last_msg ))
1309- final_state = state
1312+ last_values = state
13101313 graph_state = self .app .get_state (config )
1311- return self ._post_stream_result (graph_state , final_state , last_msg )
1314+ return self ._post_stream_result (graph_state , last_values , last_msg )
13121315
13131316 # ------------------------------------------------------------------
13141317 # Async public API
@@ -1332,17 +1335,13 @@ async def arun(self, prompt: str, thread_id: str | None = None):
13321335 inputs , config = self ._setup_run (prompt , thread_id )
13331336 self .log = []
13341337 last_msg = None
1335- final_state = None
1336- try :
1337- async for state in self .app .astream (inputs , stream_mode = "values" , config = config ):
1338- last_msg = state ["input" ][- 1 ]
1339- self .log .append (pretty_print (last_msg ))
1340- final_state = state
1341- except Exception :
1342- self ._interrupted = False # prevent stale interrupt state on error
1343- raise
1338+ last_values = None
1339+ async for state in self .app .astream (inputs , stream_mode = "values" , config = config ):
1340+ last_msg = state ["input" ][- 1 ]
1341+ self .log .append (pretty_print (last_msg ))
1342+ last_values = state
13441343 graph_state = await self .app .aget_state (config )
1345- return self ._post_stream_result (graph_state , final_state , last_msg )
1344+ return self ._post_stream_result (graph_state , last_values , last_msg )
13461345
13471346 async def aresume (self ):
13481347 """Async equivalent of :meth:`resume`.
@@ -1358,19 +1357,15 @@ async def aresume(self):
13581357
13591358 config = self ._run_config
13601359 last_msg = None
1361- final_state = None
1362- try :
1363- async for state in self .app .astream (
1364- Command (resume = True ), stream_mode = "values" , config = config
1365- ):
1366- last_msg = state ["input" ][- 1 ]
1367- self .log .append (pretty_print (last_msg ))
1368- final_state = state
1369- except Exception :
1370- self ._interrupted = False
1371- raise
1360+ last_values = None
1361+ async for state in self .app .astream (
1362+ Command (resume = True ), stream_mode = "values" , config = config
1363+ ):
1364+ last_msg = state ["input" ][- 1 ]
1365+ self .log .append (pretty_print (last_msg ))
1366+ last_values = state
13721367 graph_state = await self .app .aget_state (config )
1373- return self ._post_stream_result (graph_state , final_state , last_msg )
1368+ return self ._post_stream_result (graph_state , last_values , last_msg )
13741369
13751370 async def areject (self , feedback : str = "User rejected this code. Try a different approach." ):
13761371 """Async equivalent of :meth:`reject`.
@@ -1389,21 +1384,17 @@ async def areject(self, feedback: str = "User rejected this code. Try a differen
13891384
13901385 config = self ._run_config
13911386 last_msg = None
1392- final_state = None
1393- try :
1394- async for state in self .app .astream (
1395- Command (resume = {"approved" : False , "feedback" : feedback }),
1396- stream_mode = "values" ,
1397- config = config ,
1398- ):
1399- last_msg = state ["input" ][- 1 ]
1400- self .log .append (pretty_print (last_msg ))
1401- final_state = state
1402- except Exception :
1403- self ._interrupted = False
1404- raise
1387+ last_values = None
1388+ async for state in self .app .astream (
1389+ Command (resume = {"approved" : False , "feedback" : feedback }),
1390+ stream_mode = "values" ,
1391+ config = config ,
1392+ ):
1393+ last_msg = state ["input" ][- 1 ]
1394+ self .log .append (pretty_print (last_msg ))
1395+ last_values = state
14051396 graph_state = await self .app .aget_state (config )
1406- return self ._post_stream_result (graph_state , final_state , last_msg )
1397+ return self ._post_stream_result (graph_state , last_values , last_msg )
14071398
14081399 async def run_stream (
14091400 self ,
0 commit comments