Skip to content

Run the langchain-quickjs code interpreter in-workflow - #1874

Draft
DABH wants to merge 1 commit into
deepagents-0.7from
deepagents-quickjs
Draft

DABH wants to merge 1 commit into
deepagents-0.7from
deepagents-quickjs

Conversation

@DABH

@DABH DABH commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

TLDR: Makes Deep Agents' QuickJS code interpreter (langchain-quickjs) work under DeepAgentsPlugin, with sub-agents dispatched from JavaScript getting their own deepagents.invoke_model Activities. Stacked on #1873 (deepagents 0.7 bump), which langchain-quickjs requires. langchain-quickjs stays optional — nothing is imported unless the workflow imports it.

Why two pieces

Sandbox passthrough alone would make things worse: today the sandbox fails loudly at middleware construction (threading.Lock restricted); with passthrough but no executor change the workflow hangs silently after the first model call. The middleware hosts its VM on a dedicated thread and wakes the caller via call_soon_threadsafe, which the deterministic workflow loop cannot service and which never runs outside an activation. So this PR ships both:

  1. Inline executor (_quickjs.py) — while workflow.in_workflow(), quickjs_rs.threading.ThreadWorker's run_sync/run_async run the coroutine on the calling loop and no thread is started. Outside workflows upstream behavior is untouched; when quickjs_rs isn't installed the patch is a no-op. Installed/uninstalled with the plugin's other seams in run_context.
  2. Passthrough for langchain_quickjs, quickjs_rs, wasmtime, bsdiff4 — a name-only allowlist checked at import time, so it costs nothing for users who don't use the interpreter.

What you get

JavaScript runs as workflow code and replays; task(...) from JavaScript dispatches the sub-agent in-workflow (model calls → invoke_model Activities); PTC tools.<name>(...) follows the tool's own wrapping (tool_as_activityinvoke_tool Activity). README documents the rules for the JavaScript (no Date.now()/Math.random() — both verified nondeterministic in the VM; generous wall-clock timeout; prefer mode="turn" since mode="thread" snapshots aren't carried across continue-as-new).

Verification

  • New tests/contrib/deepagents/test_quickjs_interpreter.py: one eval that calls a PTC tool and then a task() sub-agent → invoke_model == 3, invoke_tool == 1, result carries the sub-agent's answer, history replays deterministically — under the default sandbox, and again with max_cached_workflows=0. Plus a test that the patch is inert outside workflows.
  • Full deepagents suite and lint gate green. langchain-quickjs added to the dev group only (0.3.5 is the newest inside the two-week exclude-newer window).

Not in this PR (follow-ups)

Determinism guards inside the VM (host functions for Date.now/Math.random backed by workflow time/random), and an upstream ask to LangChain for an executor hook so the ThreadWorker patch can go away.

langchain_quickjs.CodeInterpreterMiddleware hosts its QuickJS VM on a
dedicated thread and wakes the caller through call_soon_threadsafe, which
the deterministic workflow loop cannot service: an unmodified eval parked
the workflow forever with no failure and no deadlock report. The plugin's
run context now makes quickjs_rs's worker hops inline while in a workflow
(inert elsewhere, a no-op when quickjs-rs is absent) and passes the
interpreter's modules through the sandbox. JavaScript is then workflow
code, a task() sub-agent runs in-workflow with its own invoke_model
activities, and a PTC tool follows its own tool_as_activity wrapping.
Verified end to end with replay, also under cache eviction. langchain-quickjs
stays optional; it is only a dev dependency for the tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant