Skip to content

Commit f44c9c4

Browse files
committed
fix(agents): ShellToolMiddleware session lost on HIL resume
2 parents 2b5068f + cd0aa8c commit f44c9c4

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

libs/langchain_v1/langchain/agents/middleware/shell_tool.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,17 @@ def _run_shell_tool(
677677
if payload.get("restart"):
678678
LOGGER.info("Restarting shell session on request.")
679679
try:
680-
session.stop(self._execution_policy.termination_timeout)
681-
session.start()
682-
self._run_startup_commands(session)
683-
self._session = session
680+
session.stop(self._execution_policy.termination_timeout)
681+
new_session = ShellSession(
682+
session._workspace,
683+
self._execution_policy,
684+
self._shell_command,
685+
self._environment or {},
686+
)
687+
new_session.start()
688+
self._run_startup_commands(new_session)
689+
self._session = new_session
690+
resources.session = new_session
684691
except BaseException as err:
685692
LOGGER.exception("Restarting shell session failed; session remains unavailable.")
686693
msg = "Failed to restart shell session."

0 commit comments

Comments
 (0)