Skip to content

Python: Add Hyperlight CodeAct package and docs#5185

Merged
moonbox3 merged 42 commits intomicrosoft:mainfrom
eavanvalkenburg:code_mode
Apr 17, 2026
Merged

Python: Add Hyperlight CodeAct package and docs#5185
moonbox3 merged 42 commits intomicrosoft:mainfrom
eavanvalkenburg:code_mode

Conversation

@eavanvalkenburg
Copy link
Copy Markdown
Member

@eavanvalkenburg eavanvalkenburg commented Apr 9, 2026

Motivation and Context

Add a concrete, optional CodeAct implementation for Python and capture the cross-SDK design for CodeAct with Hyperlight. This provides a reusable path for long-running agents to execute sandboxed code with provider-owned tools, file mounts, and network allow-lists without baking CodeAct into core.

Description

  • add ADR 0024 plus Python feature design notes for the CodeAct and Hyperlight design
  • introduce the alpha agent-framework-hyperlight package with HyperlightCodeActProvider and HyperlightExecuteCodeTool
  • add provider-managed tool, file, and network CRUD; derived approval behavior; serializable provider state; and Hyperlight-backed execution results
  • move the CodeAct samples into the new package and update workspace/package metadata
  • add unit coverage, a guarded real-sandbox integration test, and wire Hyperlight into the Python misc integration workflow

Closes: #5187

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings April 9, 2026 14:00
@moonbox3 moonbox3 added documentation Improvements or additions to documentation python labels Apr 9, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an optional Python Hyperlight-backed CodeAct implementation plus cross-SDK design documentation, and wires the new package into the Python workspace and CI.

Changes:

  • Introduces the new agent-framework-hyperlight alpha package (provider + execute_code tool), including samples and tests.
  • Updates agent-framework-core to let context providers inspect/override per-run runtime tools via SessionContext.options["tools"].
  • Adds ADR/design docs for CodeAct and updates Python CI workflows to include Hyperlight integration coverage.

Reviewed changes

Copilot reviewed 27 out of 28 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
python/uv.lock Adds Hyperlight package + Hyperlight sandbox deps; updates a few dependency markers.
python/pyproject.toml Registers agent-framework-hyperlight in the Python workspace.
python/packages/hyperlight/tests/hyperlight/test_hyperlight_codeact.py Adds unit coverage + guarded real-sandbox integration test.
python/packages/hyperlight/samples/README.md Documents how to run the new Hyperlight samples.
python/packages/hyperlight/samples/codeact_tool.py Standalone HyperlightExecuteCodeTool sample.
python/packages/hyperlight/samples/codeact_context_provider.py Provider-owned CodeAct sample using HyperlightCodeActProvider.
python/packages/hyperlight/README.md Package-level README for installation and public API.
python/packages/hyperlight/pyproject.toml New package metadata, deps, and tooling config.
python/packages/hyperlight/LICENSE Adds MIT license for the new package.
python/packages/hyperlight/agent_framework_hyperlight/_types.py Adds public types (FileMount, FilesystemMode, NetworkMode).
python/packages/hyperlight/agent_framework_hyperlight/_provider.py Implements HyperlightCodeActProvider context provider.
python/packages/hyperlight/agent_framework_hyperlight/_instructions.py Builds dynamic CodeAct instructions and tool descriptions.
python/packages/hyperlight/agent_framework_hyperlight/_execute_code_tool.py Implements sandbox execution, caching, CRUD registries for tools/files/network.
python/packages/hyperlight/agent_framework_hyperlight/init.py Exposes public API + version metadata.
python/packages/core/tests/core/test_agents.py Adds tests validating providers can inspect/remove runtime tools.
python/packages/core/agent_framework/_tools.py Introduces ApprovalMode type alias and updates signatures.
python/packages/core/agent_framework/_sessions.py Updates docs to reflect provider mutability of options["tools"].
python/packages/core/agent_framework/_agents.py Passes runtime tools via SessionContext.options and resolves tools from provider-mutated options.
python/PACKAGE_STATUS.md Adds agent-framework-hyperlight as alpha.
python/.cspell.json Adds codeact and hyperlight to dictionary.
docs/features/code_act/python-implementation.md Adds Python-specific CodeAct design notes and API contract.
docs/features/code_act/dotnet-implementation.md Adds placeholder for .NET CodeAct implementation notes.
docs/decisions/0024-codeact-integration.md Adds ADR covering cross-SDK CodeAct integration approach and approval model.
.github/workflows/python-merge-tests.yml Includes Hyperlight tests in “misc integration” selection.
.github/workflows/python-integration-tests.yml Includes Hyperlight tests in “misc integration” job.

Comment thread python/packages/hyperlight/agent_framework_hyperlight/_execute_code_tool.py Outdated
Comment thread python/packages/hyperlight/pyproject.toml
Comment thread docs/features/code_act/python-implementation.md Outdated
Comment thread docs/decisions/0024-codeact-integration.md Outdated
Comment thread python/packages/core/agent_framework/_agents.py Outdated
@moonbox3
Copy link
Copy Markdown
Contributor

moonbox3 commented Apr 9, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _tools.py9488690%191–192, 365, 367, 380, 405–407, 415, 433, 447, 454, 461, 484, 486, 493, 501, 540, 584, 588, 620–622, 630, 675–677, 679, 702, 728, 732, 770–772, 776, 798, 910–916, 952, 964, 966, 968, 971–974, 995, 999, 1003, 1017–1019, 1360, 1382, 1469–1475, 1604, 1608, 1654, 1715–1716, 1831, 1851, 1853, 1909, 1972, 2144–2145, 2165, 2221–2222, 2360–2361, 2428, 2433, 2440
packages/hyperlight/agent_framework_hyperlight
   _execute_code_tool.py4778582%64, 100–101, 120, 122, 135, 153, 163, 188, 193, 200, 206, 214, 222–224, 226–231, 271, 276, 278, 280, 297–298, 307–310, 337–340, 346, 348, 358–359, 391–392, 395–396, 403, 431, 465–466, 472, 480–481, 484, 488, 499–505, 557–558, 584, 647, 683, 689–691, 720–724, 728–729, 734, 751–755, 759–760, 816–817
   _instructions.py44588%14, 33, 45–46, 56
   _provider.py421173%53, 57, 65, 69, 73, 77, 81, 85, 89, 93, 97
   _types.py130100% 
TOTAL28248330088% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
5621 30 💤 0 ❌ 0 🔥 1m 31s ⏱️

Copy link
Copy Markdown
Contributor

@moonbox3 moonbox3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice and complete ADR - well done. A lot here to unpack so doing a first pass with some questions.

Comment thread docs/decisions/0024-codeact-integration.md Outdated
Comment thread docs/decisions/0024-codeact-integration.md Outdated
Comment thread docs/decisions/0024-codeact-integration.md
Comment thread docs/decisions/0024-codeact-integration.md Outdated
Comment thread docs/decisions/0024-codeact-integration.md
Comment thread docs/decisions/0024-codeact-integration.md Outdated
Comment thread docs/decisions/0024-codeact-integration.md
Comment thread docs/decisions/0024-codeact-integration.md
Comment thread docs/decisions/0024-codeact-integration.md
Comment thread docs/decisions/0024-codeact-integration.md Outdated
@eavanvalkenburg eavanvalkenburg force-pushed the code_mode branch 2 times, most recently from b309856 to fe24c4f Compare April 14, 2026 07:27
eavanvalkenburg and others added 20 commits April 14, 2026 13:36
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
eavanvalkenburg and others added 11 commits April 14, 2026 13:37
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
eavanvalkenburg and others added 7 commits April 14, 2026 14:02
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Enable the sandbox filesystem by providing a workspace_root so
/output is mounted. Remove os.path.exists assertion (unsupported
in WASM guest) and fix Content data assertion to use .uri.
Skip the network integration test on Windows where the WASM
sandbox lacks the encodings.idna codec.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread docs/decisions/0024-codeact-integration.md Outdated
Comment thread docs/decisions/0024-codeact-integration.md Outdated
Comment thread docs/features/code_act/python-implementation.md
Comment thread docs/features/code_act/python-implementation.md
Comment thread docs/features/code_act/python-implementation.md
Comment thread docs/features/code_act/python-implementation.md Outdated
Comment thread python/packages/hyperlight/samples/README.md
- Add CodeAct introduction section to ADR for unfamiliar readers
- Clarify 'less runtime efficient' con with specific overhead description
- Add note in Python impl doc clarifying ADR vs impl doc split
- Explain why before_run hooks must be per-run (CRUD, concurrency, approval)
- Rename code_interpreter variable to codeact in E2E sample
- Add manual static wiring sample (codeact_manual_wiring.py)
- Add 'when to use which pattern' guidance to samples README

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread python/packages/hyperlight/agent_framework_hyperlight/_execute_code_tool.py Outdated
Comment thread python/packages/hyperlight/agent_framework_hyperlight/_execute_code_tool.py Outdated
Comment thread python/packages/core/agent_framework/_agents.py Outdated
eavanvalkenburg and others added 2 commits April 16, 2026 09:49
… doc

- Fix async callback: _make_sandbox_callback returns sync wrapper with
  thread + asyncio.run() bridge (was broken with real Wasm FFI)
- Fix stale output: clear output_dir before each sandbox.run() call
- Fix blocking event loop: _run_code now async with asyncio.to_thread()
- Revert _agents.py options['tools'] injection (unnecessary; provider
  uses context.extend_tools())
- Revert SessionContext.options docstring back to read-only
- Add real-sandbox test fixtures (shared/restored/fresh)
- Add 8 new real-sandbox tests for callback round-trip, stale output,
  event loop non-blocking, basic execution, stdout/stderr, errors,
  snapshot/restore, and tool registration
- Add comprehensive .NET HyperlightCodeActProvider design document

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tion

Replace bare export list with Quick Start code examples covering the
context provider, standalone tool, manual static wiring, and file
mounts / network access patterns.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@moonbox3 moonbox3 added this pull request to the merge queue Apr 17, 2026
Merged via the queue into microsoft:main with commit b03cb32 Apr 17, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Feature]: CodeAct python implementation

5 participants