feat(core): use freeform tool input on models that support it (#61703)

This commit is contained in:
Aiden Cline
2026-11-10 15:15:25 -06:00
committed by GitHub
Unverified
parent 64bd35afa9
commit 53f2d631df
27 changed files with 279 additions and 33 deletions
@@ -1033,6 +1033,8 @@ effect: (ctx) =>
Call `yield* ctx.tool.reload()` after changing source data captured by the callback. Reload replays active transforms
without changing their order; it does not rerun the plugin effect.
Effect tools accept the same [freeform input declaration](/build/plugins/server#freeform-tool-input) as Promise tools. If the model does not advertise that format, the tool keeps its normal object input.
Tools have an `id` containing their effective name, and `get()` returns `undefined` when that ID is not present. Use
`update` and `remove` with the effective tool name, including its namespace (`acme_greeting` above). Dots in
namespaces and unsupported characters in tool names become `_`. Missing names are ignored; creating a tool requires
@@ -1013,6 +1013,25 @@ execute: async ({ url }, context) => {
}
```
#### Freeform tool input
A direct tool with exactly one required string field can let the model write that string without a JSON wrapper. Set `freeform` to `{ type: "text" }`, `{ type: "regex", pattern }`, or `{ type: "lark", grammar }`.
```ts
editor.add({
name: "ticket",
description: "Look up a ticket by ID",
options: { codemode: false },
input: Schema.Struct({ id: Schema.String }),
freeform: { type: "regex", pattern: "OPS-[0-9]+" },
execute: async ({ id }) => ({ content: await lookup(id) }),
})
```
If the selected model's API lists `regex` in models.dev, the model can write `OPS-42` directly. Otherwise Core omits **only** `freeform`: the model still has the `ticket` tool and calls it with `{"id":"OPS-42"}`. Missing or empty format lists mean no freeform support. The executor receives `{ id }` either way.
Inside Code Mode (`codemode: true`), a freeform tool takes its string directly, as in `await tools.ticket("OPS-42")`. `await tools.ticket({ id: "OPS-42" })` also works.
Call `reload()` after changing source data captured by the callback. Reload replays the active transforms without
changing their order; it does not rerun plugin setup.
+4 -1
View File
@@ -212,6 +212,7 @@ Use `modelID` to give an API model a friendlier catalog ID:
"name": "Coding default",
"capabilities": {
"tools": true,
"freeform": ["text", "lark"],
"input": ["text", "image"],
"output": ["text"],
},
@@ -229,10 +230,12 @@ Use `modelID` to give an API model a friendlier catalog ID:
Here, `openai/coding-default` is the selectable reference and `gpt-6.1-sol` is sent to the provider. For a model that is not
already in the catalog, OpenCode assumes:
- Tool support, text and image input, and text output.
- JSON tool support, text and image input, and text output. No freeform tool input unless `capabilities.freeform` lists the format.
- A 200,000-token context limit and 32,000-token output limit.
- An unspecified input limit.
OpenCode recognizes `text`, `regex`, and `lark`. Other format names from models.dev are ignored without dropping the model or its tools. If a proxy in front of a catalog model rejects freeform tools, set `capabilities.freeform` to `[]` on that model.
These are fallback assumptions, not detected capabilities. Set accurate `capabilities` and `limit` values when known;
explicit values replace the fallbacks. Add `disabled: true` to hide a model from the available catalog: