feat(orchestrator): pass model options through MCP thread targets (#3872)

This commit is contained in:
Alex authored and Julius Marminge committed 2026-08-07 13:24:46 +02:00
1 parent 189820e5e7
commit e282b480e0
5 files changed
+242 -5

No files matched your search

@@ -55,6 +55,55 @@ describe("orchestrator MCP contracts", () => {
expect(result.summary).toBe("Workspace inspected.");
});
it("decodes target model options in canonical and shorthand shapes", () => {
const canonical = decodeDelegateTaskInput({
task: "Say hello.",
target: {
providerInstanceId: "codex",
model: "gpt-5.6-luna",
options: [{ id: "reasoning", value: "low" }],
},
});
const shorthand = decodeDelegateTaskInput({
task: "Say hello.",
target: {
providerInstanceId: "codex",
model: "gpt-5.6-luna",
options: { reasoning: "low", fastMode: true },
},
});
expect(canonical.target?.options).toEqual([{ id: "reasoning", value: "low" }]);
expect(shorthand.target?.options).toEqual([
{ id: "reasoning", value: "low" },
{ id: "fastMode", value: true },
]);
});
it("rejects target model options that are not strings or booleans", () => {
expect(() =>
decodeDelegateTaskInput({
task: "Say hello.",
target: {
providerInstanceId: "codex",
model: "gpt-5.6-luna",
// Must fail loudly instead of being dropped like legacy persistence.
options: { reasoning: 3 },
},
}),
).toThrow();
expect(() =>
decodeDelegateTaskInput({
task: "Say hello.",
target: {
providerInstanceId: "codex",
model: "gpt-5.6-luna",
options: [{ id: "reasoning", value: null }],
},
}),
).toThrow();
});
it("decodes mixed prompted and empty thread batches", () => {
const request = decodeCreateThreadsInput({
clientRequestId: "threads-1",
+46
View File
@@ -1,4 +1,6 @@
import * as Effect from "effect/Effect";
import * as Schema from "effect/Schema";
import * as SchemaTransformation from "effect/SchemaTransformation";
import {
ContextTransferId,
@@ -22,16 +24,58 @@ import {
OrchestrationV2RunStatus,
OrchestrationV2TurnItemStatus,
} from "./orchestrationV2.ts";
import {
ProviderOptionDescriptor,
ProviderOptionSelection,
ProviderOptionSelectionValue,
} from "./model.ts";
import { ProviderDriverKind, ProviderInstanceId } from "./providerInstance.ts";
const OrchestratorMcpPrompt = TrimmedNonEmptyString.check(Schema.isMaxLength(120_000));
const OrchestratorMcpTitle = TrimmedNonEmptyString.check(Schema.isMaxLength(512));
const OrchestratorMcpClientRequestId = TrimmedNonEmptyString.check(Schema.isMaxLength(256));
/**
* Shorthand `{ id: value }` record form for target model options. Unlike the
* legacy-tolerant `ProviderOptionSelections` persistence schema, this decodes
* strictly: a value that is not a string or boolean fails the request rather
* than being silently dropped.
*/
const OrchestratorMcpTargetOptionsFromRecord = Schema.Record(
Schema.String,
ProviderOptionSelectionValue,
).pipe(
Schema.decodeTo(
Schema.Array(ProviderOptionSelection),
SchemaTransformation.transformOrFail({
decode: (record) =>
Effect.succeed(Object.entries(record).map(([id, value]) => ({ id, value }))),
encode: (selections: ReadonlyArray<ProviderOptionSelection>) =>
Effect.succeed(
Object.fromEntries(selections.map((selection) => [selection.id, selection.value])),
),
}),
),
);
export const OrchestratorMcpTargetOptions = Schema.Union([
Schema.Array(ProviderOptionSelection),
OrchestratorMcpTargetOptionsFromRecord,
]);
export type OrchestratorMcpTargetOptions = typeof OrchestratorMcpTargetOptions.Type;
export const OrchestratorMcpTarget = Schema.Struct({
providerInstanceId: Schema.optional(ProviderInstanceId),
driverKind: Schema.optional(ProviderDriverKind),
model: Schema.optional(TrimmedNonEmptyString),
/**
* Model option selections for the child (for example reasoning effort).
* Accepts the canonical `[{ id, value }]` array or the shorthand
* `{ id: value }` record; valid ids come from the option descriptors
* advertised by orchestrator_capabilities. When omitted, options inherit
* from the parent only when the child runs the parent's provider and model.
*/
options: Schema.optional(OrchestratorMcpTargetOptions),
});
export type OrchestratorMcpTarget = typeof OrchestratorMcpTarget.Type;
@@ -343,6 +387,8 @@ export const OrchestratorMcpProviderCapability = Schema.Struct({
Schema.Struct({
id: Schema.String,
label: Schema.NullOr(Schema.String),
/** Model options a target may select (for example reasoning effort). */
options: Schema.optional(Schema.Array(ProviderOptionDescriptor)),
}),
),
canRunChildTask: Schema.Boolean,