Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(mock): recognize prompt-rendered agent tool catalogues

Steven Enamakel64a487793b32
diff --git a/scripts/mock-api/routes/llm.mjs b/scripts/mock-api/routes/llm.mjs
index 7eb0749544..d911621202 100644
--- a/scripts/mock-api/routes/llm.mjs
+++ b/scripts/mock-api/routes/llm.mjs
@@ -14,15 +14,24 @@ import {
resolveThreadKey,
} from "./llm/shared.mjs";
-// The scripted `llmForcedResponses` FIFO models the *interactive* agent turn,
-// which always advertises tools (the orchestrator's delegate_* tools). Ancillary
-// completions that share the endpoint but carry no tools — thread-title/summary
-// generation via `chat_with_system` (tools: None), fired fire-and-forget and
-// racing the visible turn — must NOT drain the queue, or the scripted responses
-// desync and the turn falls through to the dynamic fallback
-// (tinyhumansai/openhuman#4517).
+// The scripted `llmForcedResponses` FIFO models the *interactive* agent turn.
+// Older harnesses advertised tools in the OpenAI request. Current harnesses
+// render that same catalogue in the stable system prompt to preserve the
+// provider's prompt-cache prefix, and deliberately omit the duplicate request
+// field. Ancillary completions that share the endpoint but carry neither form
+// of catalogue — thread-title/summary generation via `chat_with_system`, fired
+// fire-and-forget and racing the visible turn — must not drain the queue, or
+// scripted responses desynchronise and the turn falls through to the dynamic
+// fallback (tinyhumansai/openhuman#4517).
function isPrimaryTurn(parsedBody) {
- return Array.isArray(parsedBody?.tools) && parsedBody.tools.length > 0;
+ if (Array.isArray(parsedBody?.tools) && parsedBody.tools.length > 0) return true;
+
+ return (parsedBody?.messages ?? []).some(
+ message =>
+ (message?.role === "system" || message?.role === "developer") &&
+ typeof message?.content === "string" &&
+ message.content.includes("## Tools")
+ );
}
function requestRuleMatches(rule, ctx) {