Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions src/agent/model-family-policy.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, test } from "bun:test";
import { resolveModelFamilyPolicy } from "./model-family-policy.js";
import { buildSubAgentSystemPrompt } from "./prompts.js";

describe("resolveModelFamilyPolicy", () => {
test("defaults are permissive for an unrecognized provider", () => {
Expand Down Expand Up @@ -388,4 +389,72 @@ describe("resolveModelFamilyPolicy", () => {
}
}
});

describe("deepseek-v4 bake-in (CL-10242)", () => {
function v4(
input: {
orchestrator?: boolean;
directorId?: string;
} = {},
) {
return resolveModelFamilyPolicy({
providerName: "vast",
model: "deepseek-v4-flash",
...(input.orchestrator !== undefined
? { orchestrator: input.orchestrator }
: {}),
...(input.directorId !== undefined
? { directorId: input.directorId }
: {}),
});
}

test("orchestrators get the d1 primary residual, no leaf role body", () => {
const p = v4({ orchestrator: true });
expect(p.family).toBe("deepseek-v4");
expect(p.promptResidual).toBeDefined();
expect(p.promptResidual).toContain("DeepSeek V4 Flash");
expect(p.leafRoleBody).toBeUndefined();
});

test("coder leaves get the tuned slim coder body, no residual", () => {
const p = v4({ orchestrator: false, directorId: "coder" });
expect(p.family).toBe("deepseek-v4");
expect(p.leafRoleBody).toBeDefined();
expect(p.leafRoleBody).toContain("Coder");
expect(p.promptResidual).toBeUndefined();
});

test("reviewer leaves get the tuned slim reviewer body", () => {
const p = v4({ orchestrator: false, directorId: "reviewer" });
expect(p.family).toBe("deepseek-v4");
expect(p.leafRoleBody).toBeDefined();
expect(p.leafRoleBody).toContain("Reviewer");
expect(p.promptResidual).toBeUndefined();
});

test("explorer leaves get the g2 leaf residual only", () => {
const p = v4({ orchestrator: false, directorId: "explorer" });
expect(p.family).toBe("deepseek-v4");
expect(p.promptResidual).toBeDefined();
expect(p.promptResidual).toContain("DeepSeek V4 Flash");
expect(p.leafRoleBody).toBeUndefined();
});

test("a leaf without a tuned director id gets the default policy, no body/residual", () => {
const p = v4({ orchestrator: false });
expect(p.family).toBe("deepseek-v4");
expect(p.leafRoleBody).toBeUndefined();
expect(p.promptResidual).toBeUndefined();
});

test("the slim coder body lands in the assembled sub-agent prompt via the extensions seam", () => {
const p = v4({ orchestrator: false, directorId: "coder" });
const slimBody = p.leafRoleBody;
expect(slimBody).toBeDefined();
const prompt = buildSubAgentSystemPrompt([slimBody as string]);
expect(prompt).toContain("You are Coder");
expect(prompt).toContain("implement one brief");
});
});
});
83 changes: 83 additions & 0 deletions src/agent/model-family-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ export interface ModelFamilyPolicy {
* disturb the cached prompt prefix. Undefined for families that need none.
*/
promptResidual?: string | undefined;
/**
* Replaces the director body (formatDirectorSystemPrompt) on a leaf worker
* for families with a tuned slim body for that role. Undefined keeps the
* shared director body. run.ts feeds it into the extensions list in place
* of the stock director body.
*/
leafRoleBody?: string | undefined;
}

const DEFAULT_WRAP_UP_NUDGE_TEXT =
Expand Down Expand Up @@ -200,10 +207,66 @@ const ASTRA_POLICY: Omit<ModelFamilyPolicy, "family"> = {
promptResidual: ASTRA_PROMPT_RESIDUAL,
};

// DeepSeek V4 winning d1+slim config, baked in from the handoff prompt files
// (corbits-dsv4-handoff/prompts/): d1_primary.txt, body_coder.txt,
// body_reviewer.txt, g2_leaf.txt. Inline constants — the brief keeps these in
// the policy, not the prompt-variance package. The model-family-policy switch
// routes them; the orchestration/leaf carve-outs mirror the grok branch.
export const DSV4_D1_PRIMARY_RESIDUAL = `
Operating notes (DeepSeek V4 Flash):
- Your context is the expensive one: workers do the reading, building, and checking. Read only what you need to route and to name files in a brief (one glob or grep, or one or two reads); do not read code to plan the fix yourself.
- Route: any code change (fix, feature, refactor, even one line) goes to coder; verification of that change goes to reviewer after the coder reports; codebase questions that need more than two reads go to explorer; a question answerable from one or two reads you answer directly. Set \`agent\` to the id directly; do not call search_agents.
- Write each brief so the worker can start without rediscovering anything: goal (copy the user's requirements verbatim, including exact formats, names, and messages), files (repo-relative paths to change and to leave alone), constraints in do_not (no edits to tests or locked files, no new deps, no extra tests or files unless asked), success_criteria (observable checks, one per requirement), and the exact test command.
- After the coder reports, spawn reviewer with the same success_criteria, the test command, and the coder's changed paths. If the reviewer reports a defect, send it back to the same coder with send_input, then have the reviewer re-check once.
- Always call wait_agents on a worker you spawned before ending your turn; never end the turn with a worker still running.
- Do not edit files yourself and do not re-read changed files or re-run tests after a report: the reviewer's verdict is the verification.
- Files go through the file tools, not the shell: read, grep, glob. glob refuses ** unless \`path\` is a subdirectory: use {"path": "src", "pattern": "**/*.ts"}, never {"pattern": "src/**/*.ts"}.
- Final reply: what changed (files), who verified it and how, anything left open, in five lines or fewer. Do not restate the request.
`.trim();

export const DSV4_BODY_CODER = `
Identity: agent id \`coder\`. You are Coder, the builder for Corbits Code, running on DeepSeek V4 Flash. You implement one brief, then report. A separate reviewer verifies your work.

- Start from the brief: it names the goal, the files, the constraints, the success criteria, and the test command. Read those files, make the change, run the test command once, report.
- Read a file before editing it, unless you just created or edited it. Use edit for targeted changes and write for new files.
- Use read, not cat/head/tail in bash; read with no offset/limit returns the whole file, so read each file once. Use grep, not shell grep or rg. Use glob, not find or ls.
- glob refuses ** unless \`path\` is a subdirectory: {"path": "src", "pattern": "**/*.ts"} works; {"pattern": "src/**/*.ts"} is refused.
- Use bash for tests, builds, and programs. A bash result that starts with \`exit code N\` failed: read it and fix the cause before moving on.
- Make the smallest change at the root cause. Keep public signatures and existing behavior the brief does not mention. Add no tests, files, refactors, or docs the brief did not ask for.
- Build structured output (JSON, CSV, YAML) with the language's serializer (JSON.stringify, json.dumps), never by string interpolation.
- Do not re-verify beyond the brief's test command and one direct check per success criterion; the reviewer does the rest.
- Report with the Report envelope (Summary / Findings / Blockers / Paths). In Findings, give each success criterion as pass/fail with the command and its exit status. Paths lists every file you changed.
`.trim();

export const DSV4_BODY_REVIEWER = `
Identity: agent id \`reviewer\`. You are Reviewer, the verifier for Corbits Code, running on DeepSeek V4 Flash. You check a change against the brief's success criteria. You never edit product code.

- Run the brief's test command once. Then check each success criterion with the smallest direct evidence: read the changed lines, and run one targeted command (call the function or CLI with python3 -c / node -e) for behavior the tests do not cover, including exact output formats.
- Report a defect only with evidence: path:line, the input, expected vs actual.
- Do not add files to the repo; use inline commands and leave the working tree as you found it.
- Use read, grep, and glob for files, not shell cat/grep/find. glob refuses ** unless \`path\` is a subdirectory: {"path": "src", "pattern": "**/*.ts"}.
- A bash result that starts with \`exit code N\` failed: say what failed.
- Report with the Report envelope (Summary / Findings / Blockers / Paths). Summary: PASS or FAIL in one line. Findings: one line per success criterion (pass/fail + evidence), then any defects. Keep the whole report under 15 lines.
`.trim();

export const DSV4_G2_LEAF_RESIDUAL = `
Operating notes (DeepSeek V4 Flash):
- Files go through the file tools, not the shell: read to view a file, grep to search contents, glob to find files. bash is for running tests, builds, and programs only.
- glob refuses ** unless \`path\` is a subdirectory. Put the directory in \`path\`, never at the front of the pattern: {"path": "src", "pattern": "**/*.ts"} works; {"pattern": "src/**/*.ts"}, {"pattern": "tests/**/*"} and {"pattern": "**/*"} are refused. At the root, survey with {"pattern": "*.*"} and {"pattern": "*/*"}.
- read takes a file path, never a directory; list a directory with glob ({"path": "src", "pattern": "*"}). Do not guess file names: glob or grep first.
- read with no offset/limit returns the whole file; read each file once and do not page past its end.
- Do exactly what the brief asks. No extra tests, files, refactors, or docs unless the brief requires them; when the brief or the operator says no tests, write none.
- Produce structured output (JSON, CSV, YAML) with the language's serializer (JSON.stringify, json.dumps), never by string interpolation.
- Stay proportional: a few targeted checks cover a small change. Once the success criteria are verified, stop; do not build harnesses for exotic inputs the brief never mentions.
- Run the project's own test command once after your last edit, then write the report.
`.trim();

export function resolveModelFamilyPolicy(input: {
providerName: string;
model?: string;
orchestrator?: boolean;
/** Leaf director id (coder, reviewer, explorer, …) for role-tuned families. */
directorId?: string;
}): ModelFamilyPolicy {
const family = detectModelFamily(input);
const orchestrator = input.orchestrator === true;
Expand Down Expand Up @@ -240,6 +303,26 @@ export function resolveModelFamilyPolicy(input: {
// Primary and leaf alike, like gpt: no orchestrator carve-out. Generic
// gpt prompts are byte-identical — only astra carries the residual.
return { family, ...ASTRA_POLICY };
case "deepseek-v4": {
// Winning d1+slim config: d1 primary residual on orchestrators, g2 leaf
// residual on explorer leaves, tuned slim coder/reviewer bodies.
const directorId = input.directorId;
return {
family,
...DEFAULT_POLICY,
promptResidual: orchestrator
? DSV4_D1_PRIMARY_RESIDUAL
: directorId === "explorer"
? DSV4_G2_LEAF_RESIDUAL
: undefined,
leafRoleBody:
!orchestrator && directorId === "coder"
? DSV4_BODY_CODER
: !orchestrator && directorId === "reviewer"
? DSV4_BODY_REVIEWER
: undefined,
};
}
default:
return { family: "default", ...DEFAULT_POLICY };
}
Expand Down
11 changes: 8 additions & 3 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ import {
GROK_SESSION_ID_OPTION,
} from "../provider/grok-responses.js";
import { BIFROST_PROVIDER } from "../provider/bifrost-adapter.js";
import { DEEPSEEK_V4_PROVIDER } from "../provider/deepseek-v4-adapter.js";
import { isDeepSeekV4Model } from "../provider/deepseek-v4-effort.js";
import { isOllamaProviderId, ollamaOpenAIBaseURL } from "../provider/ollama.js";
import { selectableGoModelIds } from "../provider/model-catalogs.js";
import {
Expand Down Expand Up @@ -265,8 +267,9 @@ export function resolveMcpServers(
}

// Build the OpenAI-compatible InferenceSource the runtime consumes. `id` is the
// user-facing name for this source (e.g. "zen"); `provider` is always
// "openai-compatible" so the inference registry routes it to the right adapter.
// user-facing name for this source (e.g. "zen"); `provider` routes to the
// openai-compatible adapter, or the deepseek-v4 per-family adapter for V4
// models, so the inference registry picks the right adapter.
export function buildOpenAISource(fields: {
id: string;
baseURL: string;
Expand All @@ -287,7 +290,9 @@ export function buildOpenAISource(fields: {
registerSourceSecret(fields.id, fields.apiKey);
return {
id: fields.id,
provider: "openai-compatible",
provider: isDeepSeekV4Model(fields.model)
? DEEPSEEK_V4_PROVIDER
: "openai-compatible",
baseURL: isOllamaProviderId(fields.id)
? ollamaOpenAIBaseURL(fields.baseURL)
: normalizeOpenAICompatibleBaseURL(fields.baseURL),
Expand Down
30 changes: 30 additions & 0 deletions src/config/inference-sources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -794,3 +794,33 @@ describe("session source bundles", () => {
expect(bundle.defaultSource).toBe("openai");
});
});

describe("deepseek-v4 provider stamping (PR A)", () => {
function v4SourceFor(model: string) {
return buildInferenceSourceForRef(
{ provider: "ds", model },
{
sessionId: "s1",
catalog: [
{
name: "ds",
baseURL: "https://ds.example/v1",
apiKey: "k",
models: [model],
},
],
},
undefined,
);
}

test("a deepseek-v4-* model stamps provider 'deepseek-v4'", () => {
const source = v4SourceFor("deepseek-v4-pro");
expect(source?.provider).toBe("deepseek-v4");
});

test("non-V4 custom models stay provider 'openai-compatible'", () => {
const source = v4SourceFor("gpt-5");
expect(source?.provider).toBe("openai-compatible");
});
});
Loading
Loading