0xPlaygrounds / 0xPlaygrounds/rig
feat: Add a "Code Mode" tool to Rig
- Dominant language
- Rust
- Stars
- 8.6k
- Forks
- 959
- Avg merge
- 4h 32m
- Merged PRs (30d)
- 117
Description
- [x] 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](https://boajs.dev/), 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.
Contributor guide
Research direction
The issue proposes integrating a JavaScript runtime (Boa) into Rig's tool system. Start by examining the existing tool calling architecture in the codebase. Look for modules related to tool execution, structured outputs, and any existing Rust macro infrastructure. Understanding how to expose a Rust API to JavaScript via Boa is key. 'Done' means a design proposal or prototype that addresses the open questions about integration, async, safety, and ease of use.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, rust
- Domain
- ai-infra-agents, backend-api-design, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100