feat(deepagents): PTC via Worker repl#296
Open
Christian Bromann (christian-bromann) wants to merge 3 commits intocb/ptcfrom
Open
feat(deepagents): PTC via Worker repl#296Christian Bromann (christian-bromann) wants to merge 3 commits intocb/ptcfrom
Christian Bromann (christian-bromann) wants to merge 3 commits intocb/ptcfrom
Conversation
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends
createSandboxPtcMiddlewareto work without any sandbox backend. When no backend is provided (or the backend doesn't supportspawnInteractive()), the middleware adds ajs_evaltool backed by an isolated Worker thread withtoolCall()andspawnAgent()as async globals. The agent writes JavaScript withPromise.all()for parallel tool calls and subagent spawning — no Deno, Modal, Docker, or VFS needed.Motivation
The sandbox PTC from #287 requires a sandbox provider with
spawnInteractive(). Many users just want programmatic tool calling and subagent spawning without setting up sandbox infrastructure. This PR adds a lightweight alternative: an in-process JavaScript REPL running in a Worker thread, with the sametoolCall()/spawnAgent()API.How it works
The middleware now detects the backend type and picks the right mode:
spawnInteractive()execute(bash/python/node)&+waitjs_eval(JavaScript)Promise.all()In Worker REPL mode:
js_evaltool and hides all PTC tools (includingtask) from the model — the agent must usetoolCall()/spawnAgent()insidejs_evaljs_evalcreates a Node.js Worker Thread (or Web Worker in browsers) that evaluates the code withtoolCall()andspawnAgent()injected as async globalspostMessageto the main thread, which invokes the actual tool with the LangGraph config (sotask/subagents work correctly), then sends the result backPromise.all()works naturally sincetoolCall()returns Promises and the Worker's event loop isn't blockedEnvironment detection
Usage
The agent gets filesystem tools from the
StateBackendandjs_evalfrom the PTC middleware. Insidejs_eval, the agent writes:Example trace: https://smith.langchain.com/public/71192fe6-3a0b-4068-b057-816ae384f053/r