Skip to content

Conversation

sudheerr48
Copy link

feat(langchain): add timeout to ToolNode ainvoke to prevent hangs

Description:
This PR resolves issue #32853, where ToolNode.ainvoke could freeze indefinitely if a tool's execution hangs, particularly with sse_read_timeout configurations.

To address this, I've implemented a timeout mechanism in the ToolNode class:
Added timeout Parameter: A new optional timeout parameter has been added to the ToolNode's init method, allowing users to specify a timeout in seconds.

Asynchronous Timeout Handling: The _afunc method now uses asyncio.wait_for to enforce the timeout on concurrent tool executions. If a timeout occurs, a TimeoutError is raised with an informative message.

Comprehensive Unit Tests: New tests have been added to verify the timeout functionality, including scenarios for timeout exceptions, successful completions, and backward compatibility.

All existing and new tests pass, and the code adheres to the project's linting and formatting standards.
Issue:
Fixes #32853
Dependencies:
None

Copy link

vercel bot commented Sep 14, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
langchain Ignored Ignored Preview Sep 14, 2025 5:28am

@mdrxy mdrxy changed the title feat: Add timeout to ToolNode ainvoke to prevent hangs feat: Add timeout to ToolNode ainvoke() Sep 15, 2025
@mdrxy mdrxy changed the title feat: Add timeout to ToolNode ainvoke() feat(langchain): Add timeout to ToolNode ainvoke() Sep 15, 2025
@mdrxy mdrxy requested a review from sydney-runkle September 15, 2025 01:37
@mdrxy mdrxy added langchain Related to the package `langchain` v1 Issue specific to LangChain 1.0 labels Sep 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
langchain Related to the package `langchain` v1 Issue specific to LangChain 1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ToolNode ainvoke freezes if sse_read_timeout
2 participants