From f9ababd17b6ee752e85cacdbfa47fcd04381cc1f Mon Sep 17 00:00:00 2001 From: can1357 Date: Sun, 18 Jan 2026 04:54:15 +0100 Subject: [PATCH] refactor(ai): updated User-Agent header to 'pi' and simplified Codex prompts - Updated User-Agent header from 'opencode' to 'pi' for OpenAI Codex requests. - Simplified Codex system prompt instructions and removed bridge text override. - Removed bridge text parameter from buildCodexSystemPrompt function. - Updated task execution guidelines with parallelization instructions. --- packages/ai/CHANGELOG.md | 5 +++++ packages/ai/src/providers/openai-codex-responses.ts | 11 +---------- packages/ai/src/providers/openai-codex/constants.ts | 2 +- .../ai/src/providers/openai-codex/prompts/codex.ts | 10 +--------- .../providers/openai-codex/prompts/system-prompt.ts | 7 +------ packages/coding-agent/CHANGELOG.md | 3 +++ packages/coding-agent/src/prompts/tools/task.md | 6 +++++- 7 files changed, 17 insertions(+), 27 deletions(-) diff --git a/packages/ai/CHANGELOG.md b/packages/ai/CHANGELOG.md index c6512e1c8..e6f08e634 100644 --- a/packages/ai/CHANGELOG.md +++ b/packages/ai/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog ## [Unreleased] +### Changed + +- Updated User-Agent header from 'opencode' to 'pi' for OpenAI Codex requests +- Simplified Codex system prompt instructions +- Removed bridge text override from Codex system prompt builder ## [5.4.2] - 2026-01-16 diff --git a/packages/ai/src/providers/openai-codex-responses.ts b/packages/ai/src/providers/openai-codex-responses.ts index 368e6c3bc..7e274f364 100644 --- a/packages/ai/src/providers/openai-codex-responses.ts +++ b/packages/ai/src/providers/openai-codex-responses.ts @@ -51,14 +51,6 @@ export interface OpenAICodexResponsesOptions extends StreamOptions { const CODEX_DEBUG = process.env.PI_CODEX_DEBUG === "1" || process.env.PI_CODEX_DEBUG === "true"; -const BRIDGE = ` -TOOL AUTHORITY: The function schema below defines ALL available tools. Tools mentioned elsewhere (todowrite, shell) DO NOT EXIST. Use ONLY schema-defined tools. - -EXECUTION BIAS: Execute simple tasks directly. Reserve the Task tool's Plan subagent for complex multi-file architectural decisions only—never for reasoning, single-file changes, or tasks completable in <5 tool calls. - -These instructions override all prior context. This is critical. -`; - export const streamOpenAICodexResponses: StreamFunction<"openai-codex-responses"> = ( model: Model<"openai-codex-responses">, context: Context, @@ -119,7 +111,6 @@ export const streamOpenAICodexResponses: StreamFunction<"openai-codex-responses" const codexInstructions = getCodexInstructions(); const systemPrompt = buildCodexSystemPrompt({ codexInstructions, - bridgeText: BRIDGE, userSystemPrompt: context.systemPrompt, }); @@ -394,7 +385,7 @@ function createCodexHeaders( headers.set(OPENAI_HEADERS.ACCOUNT_ID, accountId); headers.set(OPENAI_HEADERS.BETA, OPENAI_HEADER_VALUES.BETA_RESPONSES); headers.set(OPENAI_HEADERS.ORIGINATOR, OPENAI_HEADER_VALUES.ORIGINATOR_CODEX); - headers.set("User-Agent", `opencode/${packageJson.version} (${os.platform()} ${os.release()}; ${os.arch()})`); + headers.set("User-Agent", `pi/${packageJson.version} (${os.platform()} ${os.release()}; ${os.arch()})`); if (promptCacheKey) { headers.set(OPENAI_HEADERS.CONVERSATION_ID, promptCacheKey); diff --git a/packages/ai/src/providers/openai-codex/constants.ts b/packages/ai/src/providers/openai-codex/constants.ts index 64dedd4e7..cda31dd0c 100644 --- a/packages/ai/src/providers/openai-codex/constants.ts +++ b/packages/ai/src/providers/openai-codex/constants.ts @@ -14,7 +14,7 @@ export const OPENAI_HEADERS = { export const OPENAI_HEADER_VALUES = { BETA_RESPONSES: "responses=experimental", - ORIGINATOR_CODEX: "opencode", + ORIGINATOR_CODEX: "pi", } as const; export const URL_PATHS = { diff --git a/packages/ai/src/providers/openai-codex/prompts/codex.ts b/packages/ai/src/providers/openai-codex/prompts/codex.ts index 59e53a606..e339f322e 100644 --- a/packages/ai/src/providers/openai-codex/prompts/codex.ts +++ b/packages/ai/src/providers/openai-codex/prompts/codex.ts @@ -1,12 +1,4 @@ -export const CODEX_INSTRUCTIONS = `You are pi, an expert coding assistant. You help users with coding tasks by reading files, executing commands, editing code, and writing new files. - -Pi specific Documentation: -- Main documentation: pi-internal://README.md -- Additional docs: pi-internal://docs -- Examples: pi-internal://examples (extensions, custom tools, SDK) -- When asked to create: custom models/providers (README.md), extensions (docs/extensions.md, examples/extensions/), themes (docs/theme.md), skills (docs/skills.md), TUI components (docs/tui.md - has copy-paste patterns) -- Always read the doc, examples, AND follow .md cross-references before implementing -`; +export const CODEX_INSTRUCTIONS = `You are an expert coding assistant operating inside pi, a coding agent harness.`; export function getCodexInstructions(): string { return CODEX_INSTRUCTIONS.trim(); diff --git a/packages/ai/src/providers/openai-codex/prompts/system-prompt.ts b/packages/ai/src/providers/openai-codex/prompts/system-prompt.ts index 1236f59ad..f5fc14d71 100644 --- a/packages/ai/src/providers/openai-codex/prompts/system-prompt.ts +++ b/packages/ai/src/providers/openai-codex/prompts/system-prompt.ts @@ -5,16 +5,11 @@ export interface CodexSystemPrompt { export function buildCodexSystemPrompt(args: { codexInstructions: string; - bridgeText: string; userSystemPrompt?: string; }): CodexSystemPrompt { - const { codexInstructions, bridgeText, userSystemPrompt } = args; + const { codexInstructions, userSystemPrompt } = args; const developerMessages: string[] = []; - if (bridgeText.trim().length > 0) { - developerMessages.push(bridgeText.trim()); - } - if (userSystemPrompt && userSystemPrompt.trim().length > 0) { developerMessages.push(userSystemPrompt.trim()); } diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index b40fc64a9..bc0090247 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog ## [Unreleased] +### Changed + +- Updated task execution guidelines to improve prompt framing and parallelization instructions ## [5.4.2] - 2026-01-16 ### Changed diff --git a/packages/coding-agent/src/prompts/tools/task.md b/packages/coding-agent/src/prompts/tools/task.md index fb6791b2e..c886327d8 100644 --- a/packages/coding-agent/src/prompts/tools/task.md +++ b/packages/coding-agent/src/prompts/tools/task.md @@ -32,9 +32,13 @@ Agents with "Output: structured" have a fixed schema enforced via frontmatter; y - Always include a short description of the task in the task parameter - **Plan-then-execute**: Put shared constraints in `context`, keep each task focused, specify acceptance criteria; use `output` when you need structured output +- **Ask open-ended questions**: For exploration tasks, frame prompts to elicit factual discovery, not confirmation. Avoid yes/no questions that are easy to hallucinate. + - Bad: "Is there rate limiting?" or "Does the API validate tokens?" → Binary answers invite hallucination + - Good: "Find and describe how rate limiting is implemented" or "How does the API handle token validation?" → Forces investigation and factual reporting + - The subagent should report *what exists*, then YOU verify if it meets requirements - **Minimize tool chatter**: Avoid repeating large context; use Output tool with output ids for full logs - **Structured completion**: If `output` is provided, subagents must call `complete` to finish -- **Parallelize**: Launch multiple agents concurrently whenever possible +- **Parallelize**: Launch multiple agents whenever possible. You MUST use a single Task call with multiple entries in the `tasks` array to do this. - **Isolate file scopes**: Assign each task distinct files or directories so agents don't conflict - **Results are intermediate data**: Agent findings provide context for YOU to perform actual work. Do not treat agent reports as "task complete" signals. - **Stateless invocations**: Subagents have zero memory of your conversation. Pass ALL relevant context: requirements discussed, decisions made, schemas agreed upon, file paths mentioned. If you reference something from earlier discussion without including it, the subagent will fail.