Repository navigation
feat(python): expose embedded runtime host functions to agent tools - #2739
Merged
Merged
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | 7dafe0c | Commit Preview URL Branch Preview URL |
Oct 16 2026, 06:04 PM |
2 tasks done
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.
What changed
Embedded Python and TypeScript programs can call registered async host functions through Python
BashTool, LangChain, and deepagents. Python usesexternal_functions/external_handler; TypeScript has separatetypescript_external_functions/typescript_external_handleroptions. Both can coexist and share the virtual filesystem.Async execution runs handlers on the caller's event loop with the request's ContextVars. Sync execution uses a persistent private worker loop, including inside notebooks and FastAPI sync endpoints. Reset preserves registration; snapshot factories require the host to supply callbacks again. Cancellation is scoped to each execution, and recursive interpreter/live-filesystem access fails promptly instead of deadlocking. Native result deliveries drain before interpreter shutdown, preventing a reference-cleanup race exposed by immediate process exit after async execution.
Why
Closes #2737. Agents need to orchestrate host services from sandboxed programs while preserving the threading and loop behavior of existing integrations.
Before / After
Before: passing
external_functionsorexternal_handlertoBashToolfailed with an unexpected-keyword error; framework integrations could not expose host functions to embedded programs.After: a registered
lookupdispatcher returns{"value": 42}to either language:Evidence: real-interpreter regression tests cover both languages across sync/async calls, multiple threads and successive loops, Selector/uvloop, concurrent FastAPI requests, LangChain/deepagents, cancellation/timeout reuse, and reentry. A real Jupyter kernel executes the new notebook. The full Python suite passes 973 tests; targeted suites also pass on Python 3.9 and 3.14. Deterministic regressions cover native result-delivery cleanup for all three tool classes and private callback cancellation during process exit; 1,000 parallel subprocess runs passed after the shutdown fix (76 crashes before). Repository tests, pre-PR checks, all-feature Clippy, and the parallel-execution benchmark pass. CI additionally exercises macOS and Windows callback loops and Linux Python 3.9–3.14.
Risk
console.log()output after a host-call suspension. Examples use final-expression or VFS output; this limitation is documented.Checklist