Relax source grounding and pin owner Codex model
This commit is contained in:
parent
9978fd3ef5
commit
2c32b8df1f
16 changed files with 37 additions and 84 deletions
|
|
@ -86,6 +86,7 @@ const envSchema = z.object({
|
|||
OWNER_CODEX_MODE: z.string().min(1).default("local_exec_owner_only"),
|
||||
CODEX_EXECUTABLE: z.string().min(1).default("codex"),
|
||||
CODEX_EXEC_ARGS: z.string().default(""),
|
||||
CODEX_MODEL: z.string().min(1).default("gpt-5.4"),
|
||||
CODEX_MODEL_REASONING_EFFORT: z.enum(["low", "medium", "high", "xhigh"]).default("low"),
|
||||
CODEX_EXEC_TIMEOUT_MS: z.coerce.number().int().positive().default(120000),
|
||||
STYLE_PACK_PATH: z.string().min(1).default("styles/void-default.md"),
|
||||
|
|
@ -116,6 +117,7 @@ export interface AppConfig {
|
|||
ownerCodexMode: OwnerCodexMode;
|
||||
codexExecutable: string;
|
||||
codexExecArgs: string[];
|
||||
codexModel: string;
|
||||
codexModelReasoningEffort: "low" | "medium" | "high" | "xhigh";
|
||||
codexExecTimeoutMs: number;
|
||||
stylePackPath: string;
|
||||
|
|
@ -285,6 +287,7 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): AppConfig {
|
|||
ownerCodexMode: parseOwnerCodexMode(parsed.OWNER_CODEX_MODE),
|
||||
codexExecutable: parsed.CODEX_EXECUTABLE,
|
||||
codexExecArgs: parseList(parsed.CODEX_EXEC_ARGS),
|
||||
codexModel: parsed.CODEX_MODEL,
|
||||
codexModelReasoningEffort: parsed.CODEX_MODEL_REASONING_EFFORT,
|
||||
codexExecTimeoutMs: parsed.CODEX_EXEC_TIMEOUT_MS,
|
||||
stylePackPath: resolve(parsed.STYLE_PACK_PATH),
|
||||
|
|
|
|||
|
|
@ -10,9 +10,7 @@ import {
|
|||
import {
|
||||
buildArtifacts,
|
||||
buildPrompt,
|
||||
buildSourceGroundingReminder,
|
||||
buildSystemPrompt,
|
||||
didUseSourceGrounding,
|
||||
} from "./local-llm-render";
|
||||
import {
|
||||
executeToolCall,
|
||||
|
|
@ -20,7 +18,6 @@ import {
|
|||
normalizeAssistantMessage,
|
||||
} from "./local-llm-tools";
|
||||
import {
|
||||
MAX_SOURCE_GROUNDING_RETRIES,
|
||||
MAX_TOOL_TURNS,
|
||||
type LocalLlmProviderOptions,
|
||||
type OllamaChatMessage,
|
||||
|
|
@ -96,8 +93,6 @@ export class LocalLlmProvider implements ProviderAdapter {
|
|||
const tools = this.options.toolbox ? buildToolDefinitions() : undefined;
|
||||
const toolTrace: ToolTraceRecord[] = [];
|
||||
const thinkingTrace: string[] = [];
|
||||
const sourceGroundingRequired = Boolean(request.contextBundle.sourceGrounding?.required);
|
||||
let sourceGroundingReminderCount = 0;
|
||||
|
||||
try {
|
||||
let finalPayload: OllamaChatResponse | undefined;
|
||||
|
|
@ -147,25 +142,6 @@ export class LocalLlmProvider implements ProviderAdapter {
|
|||
if (toolCalls.length === 0) {
|
||||
const candidateOutput = normalizeModelText(assistantMessage.content);
|
||||
|
||||
if (
|
||||
sourceGroundingRequired &&
|
||||
!didUseSourceGrounding(toolTrace) &&
|
||||
this.options.toolbox
|
||||
) {
|
||||
if (sourceGroundingReminderCount < MAX_SOURCE_GROUNDING_RETRIES) {
|
||||
sourceGroundingReminderCount += 1;
|
||||
messages.push({
|
||||
role: "user",
|
||||
content: buildSourceGroundingReminder(request.contextBundle),
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
finalOutputText =
|
||||
"This request needs actual source grounding before I can answer it cleanly. Ask again after I pull from the indexed repos, or use the deeper Codex lane.";
|
||||
break;
|
||||
}
|
||||
|
||||
finalOutputText = candidateOutput;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,18 +79,6 @@ export function buildPrompt(context: ContextBundle): string {
|
|||
].join("\n");
|
||||
}
|
||||
|
||||
export function buildSourceGroundingReminder(context: ContextBundle): string {
|
||||
return `${renderSourceGroundingInstructions(context, true)} Answer again only after using the source-side tools.`;
|
||||
}
|
||||
|
||||
export function didUseSourceGrounding(toolTrace: ToolTraceRecord[]): boolean {
|
||||
return toolTrace.some((trace) =>
|
||||
trace.tool === "list_indexed_repos" ||
|
||||
trace.tool === "search_sources" ||
|
||||
trace.tool === "get_source_context",
|
||||
);
|
||||
}
|
||||
|
||||
export function buildArtifacts(input: LocalLlmArtifactsInput): ProviderArtifact[] {
|
||||
return buildBaseArtifacts(input);
|
||||
}
|
||||
|
|
@ -140,16 +128,12 @@ function renderSourceGroundingInstructions(
|
|||
context: ContextBundle,
|
||||
reminder: boolean,
|
||||
): string {
|
||||
if (!context.sourceGrounding?.required) {
|
||||
return "Source-side grounding is optional here; use it when it clearly helps.";
|
||||
}
|
||||
|
||||
const matchedRepos =
|
||||
context.sourceGrounding.matchedRepoNames.length > 0
|
||||
context.sourceGrounding?.matchedRepoNames && context.sourceGrounding.matchedRepoNames.length > 0
|
||||
? ` Matched repos/projects: ${context.sourceGrounding.matchedRepoNames.join(", ")}.`
|
||||
: "";
|
||||
const reasons =
|
||||
context.sourceGrounding.reasons.length > 0
|
||||
context.sourceGrounding?.reasons && context.sourceGrounding.reasons.length > 0
|
||||
? ` Reasons: ${context.sourceGrounding.reasons.join(", ")}.`
|
||||
: "";
|
||||
const retry =
|
||||
|
|
@ -157,5 +141,13 @@ function renderSourceGroundingInstructions(
|
|||
? " The previous answer attempt was discarded because it did not touch the source-side tools."
|
||||
: "";
|
||||
|
||||
return `This prompt requires source-grounded evidence before you answer. Use list_indexed_repos, search_sources, or get_source_context first.${matchedRepos}${reasons}${retry}`;
|
||||
if (
|
||||
!context.sourceGrounding ||
|
||||
(context.sourceGrounding.matchedRepoNames.length === 0 &&
|
||||
context.sourceGrounding.reasons.length === 0)
|
||||
) {
|
||||
return "Source-side grounding is optional here; use it when it clearly helps.";
|
||||
}
|
||||
|
||||
return `This prompt may benefit from source-side grounding. Use list_indexed_repos, search_sources, or get_source_context if repo, lore, or source evidence would sharpen the answer.${matchedRepos}${reasons}${retry}`;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import {
|
|||
|
||||
export type OllamaThinkMode = boolean | "low" | "medium" | "high";
|
||||
export const MAX_TOOL_TURNS = 4;
|
||||
export const MAX_SOURCE_GROUNDING_RETRIES = 1;
|
||||
export const MAX_TOOL_RESULTS = MAX_RETRIEVAL_RESULT_LIMIT;
|
||||
export const MAX_CONTEXT_WINDOW = 20;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,10 +11,8 @@ import type {
|
|||
import {
|
||||
buildDefaultHandoffNotice,
|
||||
buildRequestPayload,
|
||||
didUseSourceGrounding,
|
||||
type HistoryLookupTool,
|
||||
MAX_HISTORY_TOOL_CALLS,
|
||||
MAX_SOURCE_GROUNDING_RETRIES,
|
||||
type OwnerCodexProviderOptions,
|
||||
type ToolCallRecord,
|
||||
} from "./owner-codex-shared";
|
||||
|
|
@ -176,25 +174,18 @@ export class OwnerCodexProvider implements ProviderAdapter {
|
|||
const artifacts: ProviderArtifact[] = [...baseArtifacts];
|
||||
const turnResults = [];
|
||||
let result;
|
||||
let sourceGroundingReminderCount = 0;
|
||||
const sourceGroundingRequired = Boolean(
|
||||
request.contextBundle.sourceGrounding?.required,
|
||||
);
|
||||
|
||||
for (
|
||||
let turn = 0;
|
||||
turn <= MAX_HISTORY_TOOL_CALLS + MAX_SOURCE_GROUNDING_RETRIES;
|
||||
turn += 1
|
||||
) {
|
||||
for (let turn = 0; turn <= MAX_HISTORY_TOOL_CALLS; turn += 1) {
|
||||
const codexPrompt = buildDiscordReplyPrompt(
|
||||
request.contextBundle,
|
||||
toolCalls,
|
||||
sourceGroundingReminderCount > 0,
|
||||
false,
|
||||
);
|
||||
|
||||
result = await runCodexExec({
|
||||
executable: this.options.executable,
|
||||
executableArgs: this.options.executableArgs,
|
||||
model: this.options.model,
|
||||
reasoningEffort: this.options.reasoningEffort,
|
||||
timeoutMs: this.options.timeoutMs,
|
||||
workingDirectory: this.options.workingDirectory,
|
||||
|
|
@ -246,16 +237,6 @@ export class OwnerCodexProvider implements ProviderAdapter {
|
|||
}
|
||||
|
||||
if (!result.toolRequest) {
|
||||
if (sourceGroundingRequired && !didUseSourceGrounding(result.traceEvents)) {
|
||||
if (sourceGroundingReminderCount < MAX_SOURCE_GROUNDING_RETRIES) {
|
||||
sourceGroundingReminderCount += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
result.handoffReason =
|
||||
"This question needed source-grounded evidence, but the reply lane never used the source tools.";
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -333,7 +333,11 @@ function renderSourceGroundingInstructions(
|
|||
context: ContextBundle,
|
||||
reminder: boolean,
|
||||
): string {
|
||||
if (!context.sourceGrounding?.required) {
|
||||
if (
|
||||
!context.sourceGrounding ||
|
||||
(context.sourceGrounding.matchedRepoNames.length === 0 &&
|
||||
context.sourceGrounding.reasons.length === 0)
|
||||
) {
|
||||
return "- Source-side grounding is optional here; use it when it clearly helps.";
|
||||
}
|
||||
|
||||
|
|
@ -349,7 +353,7 @@ function renderSourceGroundingInstructions(
|
|||
? " The previous answer attempt was discarded because it did not touch the source-side tools."
|
||||
: "";
|
||||
|
||||
return `- This prompt requires source-grounded evidence before you answer. Use list_indexed_repos, search_sources, or get_source_context first.${matchedRepos}${reasons}${retry}`;
|
||||
return `- This prompt may benefit from source-side grounding. Use list_indexed_repos, search_sources, or get_source_context if repo, lore, or source evidence would sharpen the answer.${matchedRepos}${reasons}${retry}`;
|
||||
}
|
||||
|
||||
function renderAgentMessageTrace(events: CodexTraceEvent[]): string {
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ const MAX_HISTORY_LIMIT = MAX_RETRIEVAL_RESULT_LIMIT;
|
|||
export async function runCodexExec(input: {
|
||||
executable: string;
|
||||
executableArgs: string[];
|
||||
model: string;
|
||||
reasoningEffort: "low" | "medium" | "high" | "xhigh";
|
||||
timeoutMs: number;
|
||||
workingDirectory: string;
|
||||
|
|
@ -54,6 +55,8 @@ export async function runCodexExec(input: {
|
|||
const args = [
|
||||
...input.executableArgs,
|
||||
"exec",
|
||||
"-m",
|
||||
input.model,
|
||||
"-c",
|
||||
'approval_policy="never"',
|
||||
"-c",
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ export const HANDOFF_SENTINEL = "VOIDBOT_HANDOFF_REQUIRED:";
|
|||
export const OWNER_NOTIFY_SENTINEL = "VOIDBOT_OWNER_NOTIFY:";
|
||||
export const TOOL_REQUEST_SENTINEL = "VOIDBOT_TOOL_REQUEST:";
|
||||
export const MAX_HISTORY_TOOL_CALLS = 4;
|
||||
export const MAX_SOURCE_GROUNDING_RETRIES = 1;
|
||||
export const MAX_NOTIFICATION_MESSAGE_LENGTH = 400;
|
||||
|
||||
export interface CodexUsageSnapshot {
|
||||
|
|
@ -35,6 +34,7 @@ export interface OwnerCodexProviderOptions {
|
|||
mode: OwnerCodexMode;
|
||||
executable: string;
|
||||
executableArgs: string[];
|
||||
model: string;
|
||||
reasoningEffort: "low" | "medium" | "high" | "xhigh";
|
||||
timeoutMs: number;
|
||||
workingDirectory: string;
|
||||
|
|
@ -133,16 +133,6 @@ export function buildDefaultHandoffNotice(jobId: string): string {
|
|||
return `This request needs the fuller local Codex flow. Check \`.voidbot/artifacts/${jobId}/handoff.md\` and \`.voidbot/artifacts/${jobId}/debug-trace.md\` in the local workspace.`;
|
||||
}
|
||||
|
||||
export function didUseSourceGrounding(events: CodexTraceEvent[]): boolean {
|
||||
return events.some(
|
||||
(event) =>
|
||||
event.kind === "mcp_tool_completed" &&
|
||||
(event.tool === "list_indexed_repos" ||
|
||||
event.tool === "search_sources" ||
|
||||
event.tool === "get_source_context"),
|
||||
);
|
||||
}
|
||||
|
||||
export function extractLatestUsage(
|
||||
events: CodexTraceEvent[],
|
||||
): CodexUsageSnapshot | undefined {
|
||||
|
|
|
|||
Loading…
Reference in a new issue