Skip to content

refactor(ai): decide freeform formats in the AI package from the model's capabilities - #65898

Merged
rekram1-node merged 1 commit into
devfrom
freeform-capability
Nov 24, 2026
Merged

rekram1-node merged 1 commit into
devfrom
freeform-capability

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #65849 (merged).

Whether a tool goes out as raw text, and with which grammar, was decided in two places: core dropped freeform when the model's catalog didn't list the tool's format (session/model-request.ts), then packages/ai checked for lark to decide whether the options line gets a grammar. Now packages/ai makes both calls from the model's freeform formats, and core only passes those formats through.

 // core/session/model-request.ts
-tools: Array.from(hooked, ([name, t]) => ({
-  ...t,
-  name,
-  freeform: t.freeform && model.capabilities.freeform?.includes(t.freeform.type) ? t.freeform : undefined,
-})),
+tools: Array.from(hooked, ([name, t]) => ({ ...t, name })),

 // core/model-resolver.ts: always set, so a model without freeform formats gets JSON tools
-capabilities: model.capabilities.freeform ? { ...base, tools: { ...base?.tools, freeform: ... } } : base,
+capabilities: { ...base, tools: { ...base?.tools, freeform: model.capabilities.freeform ?? [] } },

 // ai/protocols/openai-freeform.ts
-export const resolve = (tool, lark = true) => {
+export const resolve = (tool, formats?) => {
+  if (formats !== undefined && !formats.includes(tool.freeform.type)) return undefined   // JSON tool
+  const lark = formats === undefined || formats.includes("lark")
model's formats tool goes out as
[] (catalog lists none) JSON tool
doesn't include the tool's format JSON tool
includes it, no lark custom tool; an options line is described and parsed, without a grammar
includes it and lark custom tool, with the generated grammar when there's an options line
unset (direct @opencode/ai callers that don't say) every format, as before

Trade-offs

  • model.request plugin hooks now see a tool's declared freeform even when the model can't take it, instead of undefined. The AI package still sends that tool as JSON.
  • Core chat models get their formats only through ModelResolver's catalog path; models built through the AI SDK path don't use OpenAI custom tools, so nothing changes for them.

Checks

  • packages/ai: full bun test (2304 pass), new case for resolve matching formats; bun typecheck.
  • packages/core: model-resolver (new case: catalog formats, [] by default), session-model-request-hooks (formats pass through), tool-execute, session-runner; bun typecheck and typecheck:tsc.
  • bun run check at the root.
  • Live with OPENCODE_FLAGS=full_codemode on openai/gpt-6.2-sol: execute still went out as a custom tool with the grammar; GPT wrote // @options: {"background": true} and the call ran in the background.

Base automatically changed from freeform-options to dev November 24, 2026 00:11
@rekram1-node
rekram1-node enabled auto-merge (squash) November 24, 2026 00:12
@rekram1-node
rekram1-node merged commit 553c141 into dev Nov 24, 2026
10 checks passed
@rekram1-node
rekram1-node deleted the freeform-capability branch November 24, 2026 00:19
beyondChang pushed a commit to beyondChang/opencode that referenced this pull request Nov 24, 2026
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