Skip to content

fix(langgraph): offload sync remote tool coroutines - #229

Open
fashkl wants to merge 1 commit into
oracle:mainfrom
fashkl:fix/offload-sync-langgraph-tools
Open

fix(langgraph): offload sync remote tool coroutines#229
fashkl wants to merge 1 commit into
oracle:mainfrom
fashkl:fix/offload-sync-langgraph-tools

Conversation

@fashkl

@fashkl fashkl commented Aug 16, 2026

Copy link
Copy Markdown

Problem

Fixes #228.

LangGraph RemoteTool conversion exposes a coroutine for sync remote-tool callables, but the coroutine currently calls the synchronous function directly. For RemoteTool, that function executes httpx.request(...), so async LangGraph execution can block the event loop while waiting on network I/O.

This is worse than leaving StructuredTool.coroutine unset. LangChain's own StructuredTool._arun checks self.coroutine first; when it is None, it falls back to the base async implementation, whose source comment says it is expected to delegate _run to a separate thread. By supplying a fake async wrapper, pyagentspec bypasses that safe default and runs blocking sync I/O on the event-loop thread.

This also makes RemoteTool inconsistent with the existing ApiNode executor split in this codebase: ApiNodeExecutor._execute() uses sync httpx.request(...), while ApiNodeExecutor._aexecute() uses httpx.AsyncClient. RemoteTool is the outlier because its async entrypoint is only async-shaped, not async-safe.

In services with event-loop based liveness/readiness handling, a slow or stuck remote tool request can therefore freeze unrelated async work long enough to trip health checks and restart the service.

Fix

Offload synchronous structured-tool coroutine execution with asyncio.to_thread(...) while preserving native async callables unchanged.

This is a small general safety net for sync callables that pyagentspec intentionally exposes through a coroutine, including the current RemoteTool and ClientTool conversion paths. A future native async RemoteTool implementation using httpx.AsyncClient would still be compatible with this change and could further reduce thread usage for RemoteTool specifically.

Testing

  • Added test_remote_tool_coroutine_does_not_block_event_loop
  • Ran SKIP_LLM_TESTS=1 uv run python -m pytest -q tests/adapters/langgraph/test_tools.py
  • Ran black and isort checks for the changed files

Commit is signed off per the contribution guide.

Signed-off-by: Mohamed Ali <mohamed.ali@openinnovation.ai>
@fashkl
fashkl requested a review from a team August 16, 2026 19:19
@oracle-contributor-agreement

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
The following contributors of this PR have not signed the OCA:

To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application.

When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated.

If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public.

@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. label Aug 16, 2026
@cesarebernardis

Copy link
Copy Markdown
Member

@fashkl Thank you for the contribution!

To start, could you please sign the Oracle Contributor Agreement (OCA)?

You can find more info in the comment at #229 (comment). Please make sure to use the same email associated to your Github account, that should be the one reported in the comment.

@fashkl

fashkl commented Aug 31, 2026

Copy link
Copy Markdown
Author

@fashkl Thank you for the contribution!

To start, could you please sign the Oracle Contributor Agreement (OCA)?

You can find more info in the comment at #229 (comment). Please make sure to use the same email associated to your Github account, that should be the one reported in the comment.

Hello @cesarebernardis
Already I signed the OCA and the request is pending more than two weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Required At least one contributor does not have an approved Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LangGraph RemoteTool coroutine blocks the event loop

2 participants