Skip to content

Build your personal knowledge base with Trilium Notes

feat(llm): show the query of Codex's web searches

Elian Doran6faded795d48
diff --git a/apps/server/src/services/llm/providers/acp_agent.ts b/apps/server/src/services/llm/providers/acp_agent.ts
index baa72d37e1..1a55945741 100644
--- a/apps/server/src/services/llm/providers/acp_agent.ts
+++ b/apps/server/src/services/llm/providers/acp_agent.ts
@@ -882,6 +882,12 @@ export function createUpdateCollector(
if (!toolCallId || toolName === undefined) {
break; // not a call announced this turn
}
+ // An agent can fill in a built-in call's input only as it runs (Codex
+ // announces a web search before its query); the chat replaces the input.
+ const input = mcpToolCall(update) ? undefined : describeBuiltIn?.(update)?.toolInput;
+ if (input && Object.keys(input).length > 0) {
+ emit({ type: "tool_use", toolCallId, toolName, toolInput: input });
+ }
if (update.status === "completed" || update.status === "failed") {
emit({
type: "tool_result",
diff --git a/apps/server/src/services/llm/providers/codex_agent.spec.ts b/apps/server/src/services/llm/providers/codex_agent.spec.ts
index 38a4398a6f..60da999109 100644
--- a/apps/server/src/services/llm/providers/codex_agent.spec.ts
+++ b/apps/server/src/services/llm/providers/codex_agent.spec.ts
@@ -316,6 +316,12 @@ describe("CodexAgentProvider web search", () => {
update({ sessionUpdate: "tool_call", toolCallId: "search-1", kind: "search", title: "Web search", status: "in_progress", rawInput: { type: "webSearch", query: "" } });
// codex-acp 1.13.1 reports a finished search with no content, only its final title.
update({ sessionUpdate: "tool_call_update", toolCallId: "search-1", title: "Web search: weather Sibiu", status: "completed", rawInput: { type: "webSearch", query: "weather Sibiu" } });
+ // An opened page, which names its URL in the action.
+ update({ sessionUpdate: "tool_call", toolCallId: "search-2", kind: "search", title: "Web search", status: "in_progress", rawInput: { type: "webSearch", query: "", action: null } });
+ update({
+ sessionUpdate: "tool_call_update", toolCallId: "search-2", title: "Open page: https://www.kernel.org/", status: "completed",
+ rawInput: { type: "webSearch", query: "https://www.kernel.org/", action: { type: "openPage", url: "https://www.kernel.org/" } }
+ });
// The search's results, as the PostToolUse hook posts them; the marker below cites one of them and one it never returned.
await decide?.({
hook_event_name: "PostToolUse", session_id: "sess-1", tool_name: "webrun",
@@ -335,9 +341,16 @@ describe("CodexAgentProvider web search", () => {
{},
{ hookSpecificOutput: { hookEventName: "PreToolUse", permissionDecision: "deny", permissionDecisionReason: "Web search is turned off for this chat." } }
]);
- expect(searching).toContainEqual({ type: "tool_use", toolCallId: "search-1", toolName: "web_search", toolInput: { type: "webSearch", query: "" } });
- // A finished call the chat would otherwise show as still running.
- expect(searching).toContainEqual({ type: "tool_result", toolCallId: "search-1", toolName: "web_search", result: "Web search: weather Sibiu", isError: false });
+ // Announced without a query, then shown with the query or page once the adapter reports it,
+ // and finished with a result the chat does not read as a call still running.
+ expect(searching.filter(c => c.type === "tool_use" || c.type === "tool_result")).toEqual([
+ { type: "tool_use", toolCallId: "search-1", toolName: "web_search", toolInput: {} },
+ { type: "tool_use", toolCallId: "search-1", toolName: "web_search", toolInput: { query: "weather Sibiu" } },
+ { type: "tool_result", toolCallId: "search-1", toolName: "web_search", result: "Web search: weather Sibiu", isError: false },
+ { type: "tool_use", toolCallId: "search-2", toolName: "web_search", toolInput: {} },
+ { type: "tool_use", toolCallId: "search-2", toolName: "web_search", toolInput: { url: "https://www.kernel.org/" } },
+ { type: "tool_result", toolCallId: "search-2", toolName: "web_search", result: "Open page: https://www.kernel.org/", isError: false }
+ ]);
expect(searching.map(c => (c.type === "text" ? c.content : "")).join("")).toBe("Cloudy, 12\u00b0C. Low chance of rain.");
// The marker becomes a Trilium citation for the result the search returned.
expect(searching.filter(c => c.type === "citation")).toEqual([
diff --git a/apps/server/src/services/llm/providers/codex_agent.ts b/apps/server/src/services/llm/providers/codex_agent.ts
index 932373869a..71919fc95e 100644
--- a/apps/server/src/services/llm/providers/codex_agent.ts
+++ b/apps/server/src/services/llm/providers/codex_agent.ts
@@ -132,9 +132,21 @@ export class CodexAgentProvider extends AcpAgentProvider {
return update.toolCallId?.startsWith("mcp_startup.") ?? false;
}
- /** The web search, which the adapter reports with the kind `search`, under the name the other providers' searches carry. */
+ /**
+ * The web search, under the name the other providers' searches carry, with
+ * its query or the page it opens, where the chat looks for a detail. The
+ * adapter announces a search with the kind `search` and an empty query, and
+ * reports the query only in later updates, which carry no kind.
+ */
protected describeBuiltInTool(update: AcpToolCallUpdate): BuiltInToolDisplay | undefined {
- return update.kind === "search" ? { toolName: "web_search" } : undefined;
+ const input = update.rawInput as { type?: unknown; query?: unknown; action?: { type?: unknown; url?: unknown } | null } | undefined;
+ if (update.kind !== "search" && input?.type !== "webSearch") {
+ return undefined;
+ }
+ if (input?.action?.type === "openPage" && typeof input.action.url === "string") {
+ return { toolName: "web_search", toolInput: { url: input.action.url } };
+ }
+ return { toolName: "web_search", toolInput: typeof input?.query === "string" && input.query ? { query: input.query } : {} };
}
/**