Skip to content

feat: Add a "Code Mode" tool to Rig #1439

@FayCarsons

Description

@FayCarsons
  • I have looked for existing issues (including closed) about this

Feature Request

The Rig team has been discussing adding a JavaScript execution tool. This would enable a model to write JavaScript, with a custom API exposing functionality on the Rust side, instead of standard structured JSON tool calling.

Motivation

In our own experiments, we've found supplying tools via an embedded JavaScript runtime (Boa, specifically) to be highly effective, with agents able to focus more clearly, use fewer tokens, and keep the context concise. We think there should be a general, though opinionated, way to do this in Rig.

Proposal

The current architecture is expected to look like:

  • You define a Rust API, either a module for stateless APIs, or a type (which becomes this in JS) for stateful
  • We provide a macro which transforms this into boilerplate that exposes this API in a Boa.js JavaScript engine
  • The model responds with structured outputs such as { code : string, description : string }
  • The code field is passed to the runtime
  • Code executes and the output is made available to your harness

Some questions remain:

  • Tools integration: Is this built into our existing tool system, or just driven by structured outputs?
  • Async: Is it worth the complexity? Or are users okay with blocking in their API
  • Ease of use vs customization: Which is the priority, or can we manage both?
  • Safety: Boa has no network or filesystem access by default, do we provide opt-in escape hatches? And how do we surface the risks to users who enable them?

We would love input on the architecture or open questions above, as well as any use-cases we may not have considered.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions