Force agents to act so weak models can't complete a no-op

The whole premise is cheap models + skills + a team — so the control plane,
not the model, must guarantee action. Every adapter hardcoded
tool_choice:"auto", letting a weak model answer the kickoff with prose and
"succeed" having hired no one, delegated nothing, and said nothing.

Now the agent loop compels a tool call on the opening turn (tool_choice
plumbed through every backend: OpenAI/Responses/Chat, Anthropic, Codex,
Copilot, Azure, Custom, Gemini ANY mode, Bedrock any). If the forced turn
still yields no tool call, the run fails loudly instead of recording a
deceptive success — surfacing the problem (let it crash) rather than a
silent dead company. After it has acted, the model chooses freely.

Tested: a stub that rambles on "auto" but acts when forced now posts a
kickoff message; a prose-only first turn fails the run.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 4.8 committed 2026-06-10 21:43:49 -04:00
1 parent fa01aa682f
commit ef9ee463c9
9 files changed
+107 -35

No files matched your search

@@ -1,11 +1,11 @@
/** AWS Bedrock Converse API encoding/decoding (ported from Pi's bedrock handler). */
import { isRecord, type JsonRecord } from "../provider-http";
import type { AgentTurnMessage, ToolCall, ToolDefinition } from "../provider-tool-turn";
import type { AgentTurnMessage, ToolCall, ToolChoice, ToolDefinition } from "../provider-tool-turn";
export function bedrockToolConfig(tools: ToolDefinition[]): JsonRecord {
export function bedrockToolConfig(tools: ToolDefinition[], toolChoice?: ToolChoice): JsonRecord {
return {
tools: tools.map((tool) => ({ toolSpec: { name: tool.name, description: tool.description, inputSchema: { json: tool.parameters } } })),
toolChoice: { auto: {} },
toolChoice: toolChoice === "required" ? { any: {} } : { auto: {} },
};
}
@@ -4,7 +4,7 @@
* Antigravity request wrapper in google-gemini-cli.
*/
import { isRecord, type JsonRecord, type ProviderEventStreamMessage } from "../provider-http";
import { type AgentTurnMessage, type AgentTurnResult, type ToolCall, type ToolDefinition } from "../provider-tool-turn";
import { type AgentTurnMessage, type AgentTurnResult, type ToolCall, type ToolChoice, type ToolDefinition } from "../provider-tool-turn";
const ANTIGRAVITY_SYSTEM_INSTRUCTION =
"You are Antigravity, a powerful agentic AI coding assistant designed by the Google Deepmind team working on Advanced Agentic Coding." +
@@ -64,6 +64,7 @@ export function antigravityRequestBody(input: {
instructions: string | null;
messages: AgentTurnMessage[];
tools: ToolDefinition[];
toolChoice?: ToolChoice;
requestId: string;
}): JsonRecord {
const request: JsonRecord = {
@@ -79,7 +80,7 @@ export function antigravityRequestBody(input: {
};
if (input.tools.length > 0) {
request.tools = geminiToolDefs(input.model, input.tools);
request.toolConfig = { functionCallingConfig: { mode: "AUTO" } };
request.toolConfig = { functionCallingConfig: { mode: input.toolChoice === "required" ? "ANY" : "AUTO" } };
}
return { project: input.projectId, model: input.model, request, requestType: "agent", userAgent: "antigravity", requestId: input.requestId };
}
@@ -90,12 +91,13 @@ export function vertexRequestBody(input: {
instructions: string | null;
messages: AgentTurnMessage[];
tools: ToolDefinition[];
toolChoice?: ToolChoice;
}): JsonRecord {
const body: JsonRecord = { contents: toGeminiContents(input.model, input.messages) };
if (input.instructions) body.systemInstruction = { parts: [{ text: input.instructions }] };
if (input.tools.length > 0) {
body.tools = geminiToolDefs(input.model, input.tools);
body.toolConfig = { functionCallingConfig: { mode: "AUTO" } };
body.toolConfig = { functionCallingConfig: { mode: input.toolChoice === "required" ? "ANY" : "AUTO" } };
}
return body;
}
@@ -41,7 +41,7 @@ export async function runOpenAiResponsesTurn(input: ProviderToolTurnInput): Prom
model: input.model,
input: toResponsesInput(input.messages),
tools: responsesToolDefs(input.tools),
tool_choice: "auto",
tool_choice: input.toolChoice ?? "auto",
store: false,
...(input.instructions ? { instructions: input.instructions } : {}),
};
@@ -58,7 +58,7 @@ export function makeChatCompletionsTurn(endpoint: string, label: string): (input
model: input.model,
messages: toChatMessages(input.instructions, input.messages),
tools: chatToolDefs(input.tools),
tool_choice: "auto",
tool_choice: input.toolChoice ?? "auto",
stream: false,
};
const response = await postJson(endpoint, { authorization: `Bearer ${requireApiKey(input.credential, label)}` }, body);
@@ -74,6 +74,7 @@ export async function runAnthropicTurn(input: ProviderToolTurnInput): Promise<Ag
model: input.model,
max_tokens: 4096,
tools: anthropicToolDefs(input.tools),
...(input.toolChoice === "required" ? { tool_choice: { type: "any" } } : {}),
messages: toAnthropicMessages(input.messages),
...(input.instructions ? { system: input.instructions } : {}),
};
@@ -93,6 +94,7 @@ export async function runClaudeProTurn(input: ProviderToolTurnInput): Promise<Ag
model: input.model,
max_tokens: 4096,
tools: anthropicToolDefs(input.tools),
...(input.toolChoice === "required" ? { tool_choice: { type: "any" } } : {}),
messages: toAnthropicMessages(input.messages),
system,
};
@@ -121,7 +123,7 @@ export async function runCodexTurn(input: ProviderToolTurnInput): Promise<AgentT
input: toResponsesInput(input.messages),
text: { verbosity: "medium" },
include: ["reasoning.encrypted_content"],
tool_choice: "auto",
tool_choice: input.toolChoice ?? "auto",
parallel_tool_calls: true,
tools: responsesToolDefs(input.tools, null),
};
@@ -144,7 +146,7 @@ export async function runCopilotTurn(input: ProviderToolTurnInput): Promise<Agen
model: input.model,
input: toResponsesInput(input.messages),
tools: responsesToolDefs(input.tools),
tool_choice: "auto",
tool_choice: input.toolChoice ?? "auto",
store: false,
};
const response = await postJson(`${baseUrl}/responses`, {
@@ -165,7 +167,7 @@ export async function runCustomOpenAiTurn(input: ProviderToolTurnInput): Promise
model: input.model,
messages: toChatMessages(input.instructions, input.messages),
tools: chatToolDefs(input.tools),
tool_choice: "auto",
tool_choice: input.toolChoice ?? "auto",
stream: false,
};
const response = await postJson(`${input.credential.baseUrl}/chat/completions`, { authorization: `Bearer ${requireApiKey(input.credential, "Custom OpenAI-compatible provider")}` }, body);
@@ -181,6 +183,7 @@ export async function runCustomAnthropicTurn(input: ProviderToolTurnInput): Prom
model: input.model,
max_tokens: 4096,
tools: anthropicToolDefs(input.tools),
...(input.toolChoice === "required" ? { tool_choice: { type: "any" } } : {}),
messages: toAnthropicMessages(input.messages),
...(input.instructions ? { system: input.instructions } : {}),
};
@@ -201,6 +204,7 @@ export async function runAntigravityTurn(input: ProviderToolTurnInput): Promise<
instructions: input.instructions,
messages: input.messages,
tools: input.tools,
toolChoice: input.toolChoice,
requestId,
});
const response = await postEventStream(`${ANTIGRAVITY_ENDPOINT}/v1internal:streamGenerateContent?alt=sse`, {
@@ -220,7 +224,7 @@ export async function runAzureTurn(input: ProviderToolTurnInput): Promise<AgentT
model: input.credential.deployment,
messages: toChatMessages(input.instructions, input.messages),
tools: chatToolDefs(input.tools),
tool_choice: "auto",
tool_choice: input.toolChoice ?? "auto",
stream: false,
};
const url = `${input.credential.baseUrl}/openai/deployments/${input.credential.deployment}/chat/completions?api-version=2024-10-21`;
@@ -237,7 +241,7 @@ export async function runBedrockTurn(input: ProviderToolTurnInput): Promise<Agen
const converse: JsonRecord = {
messages: toBedrockMessages(input.messages),
inferenceConfig: { maxTokens: 4096 },
toolConfig: bedrockToolConfig(input.tools),
toolConfig: bedrockToolConfig(input.tools, input.toolChoice),
...(input.instructions ? { system: [{ text: input.instructions }] } : {}),
};
const bodyString = JSON.stringify(converse);
@@ -259,7 +263,7 @@ export async function runVertexTurn(input: ProviderToolTurnInput): Promise<Agent
const { projectId, region, serviceAccountJson } = input.credential;
if (!projectId || !region || !serviceAccountJson) throw new Error("Vertex AI credential is incomplete.");
const token = await getGcpAccessToken(serviceAccountJson);
const body = vertexRequestBody({ model: input.model, instructions: input.instructions, messages: input.messages, tools: input.tools });
const body = vertexRequestBody({ model: input.model, instructions: input.instructions, messages: input.messages, tools: input.tools, toolChoice: input.toolChoice });
const url = `https://${region}-aiplatform.googleapis.com/v1/projects/${projectId}/locations/${region}/publishers/google/models/${input.model}:generateContent`;
const response = await postJson(url, { authorization: `Bearer ${token}` }, body);
const parsed = parseGeminiResponse(response.data);