Skip to content

Simplify Code Mode with active tools and Python utilities - #155

Open
vangheem wants to merge 4 commits into
mainfrom
simplify-codemode-active-tools
Open

vangheem wants to merge 4 commits into
mainfrom
simplify-codemode-active-tools

Conversation

@vangheem

@vangheem vangheem commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Overview

Simplify Code Mode so it orchestrates an agent's currently active tools without requiring a second tool registration list or duplicating their JSON schemas in the model context. Optional capabilities are now ordinary Python utility functions that add functionality outside the agent tool catalog.

Architecture and critical paths

  • create_codemode_tool() resolves active external tools from the executing harness on every invocation. Core agent tools, inactive lazy tools, and all Code Mode instances are excluded. Utility/tool name collisions fail explicitly.
  • Tool calls continue through HarnessTool.execute() for schema and Pydantic validation, returning complete JSON-mode outputs. Plain sync/async utility functions use Python signature binding and share the existing result serialization, size limits, usage accounting, and sanitized nested audit events.
  • The exported codemode convenience tool now shares the factory implementation while retaining automatic remote/local selection. The factory retains fail-closed remote execution by default, execution admission control, runtime/memory limits, and the exactly-once output(value) contract.
  • A shared ALLOWED_GLOBAL_MODULES registry supplies worker globals, attribute guards, reserved names, and the description's module list. It includes re, math, statistics, itertools, and decimal. Safe public attributes are available on approved modules and their classes/instances, with exact type-module checks and RestrictedPython's attribute protections.
  • Explicitly approved builtin types (list, dict, str, and tuple) support ordinary public methods and constructors without exposing the entire builtins module. Item assignment/deletion is restricted to plain lists and dictionaries; private attributes, unsafe string formatting, and module/class writes remain blocked.
  • Model-facing Code Mode descriptions refresh before each model call and include compact input and JSON return-type signatures for active external tools, additional utility signatures, concise guidance, and a small example. Return shapes reflect nested serialization aliases and field serializers, with bounded expansion for large/recursive shapes rather than repeated tool descriptions and JSON schemas.
  • Harness callbacks preserve agent_id as an ordinary argument without changing legacy published-agent routing behavior.

API changes

  • Remove CodeModeCapability, result adapter APIs, and ToolInheritancePolicy.
  • Register tools directly on the agent; pass plain Python functions through capabilities=[...] for additional utilities.
  • Tools, including Code Mode, are inherited normally. Code Mode resolves the child harness's active tools rather than capturing the parent's tool catalog.
  • Tool context formatters no longer determine what generated code sees: complete JSON outputs are exposed. Private fields must be removed by the tool itself.
  • Decimal values must be converted to strings or floats before crossing the JSON worker boundary.

Documentation and regression coverage are updated for active/lazy tools, child harness dispatch, sync/async utilities, serialized return shapes, container operations, module access, argument preservation, and the existing execution safeguards. Live read-only Facilities Maintenance Demo runs exercised Code Mode with real queries, list/dict mutations, statistics, and decimal rounding; the verified snapshot contains 20 work orders with a 50.00% completion rate.

@vangheem
vangheem requested a review from a team October 2, 2026 14:01
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