Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion packages/agent/src/server/agent-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,7 @@ export class AgentServer {
prUrl?: string | null,
slackThreadUrl?: string | null,
): string | { append: string } {
const cloudAppend = this.buildCloudSystemPrompt(prUrl, slackThreadUrl);
const cloudAppend = `${this.buildCloudSystemPrompt(prUrl, slackThreadUrl)}\n${this.buildMemoryInstructions()}`;
const userPrompt = this.config.claudeCode?.systemPrompt;

// String override: combine user prompt with cloud instructions
Expand Down Expand Up @@ -1696,6 +1696,28 @@ export class AgentServer {
);
}

/**
* Guidance for the shared, semantically-searchable PostHog memory store exposed through the
* `memory` MCP tool. Appended to every cloud-run system prompt so cloud agents recall durable
* context across runs and persist new learnings — the same memory store Max/PostHog AI uses.
*
* Applies to both cloud runtimes: `_doInitializeSession` passes the PostHog MCP server (which
* carries the `memory` tool) via `newSession({ mcpServers })` for Claude and Codex alike, and
* the Codex adapter forwards those servers to the Codex CLI, so the tool is callable on both.
* `buildCodexInstructions` reusing this text for Codex runs is therefore intentional.
*/
private buildMemoryInstructions(): string {
return `
# Persistent Memory
You have access to PostHog's persistent memory through the \`memory\` MCP tool — a shared,
semantically-searchable store of durable facts about this user, their company, product, and
preferences (the same memories used across PostHog AI). Memories persist across runs, so:
- Before non-trivial work, recall context with the \`memory\` tool using \`action: "query"\` (semantic search) to surface durable facts, decisions, and prior discussions.
- When you learn something durable — product setup, conventions, definitions, preferences, decisions — store it with \`action: "create"\`. Do this pre-emptively; you don't need to be asked. Query first to avoid duplicates.
- Use \`action: "update"\`/\`"delete"\` to keep memories accurate, and \`action: "list_metadata_keys"\` to keep metadata tags consistent.
- Memories are for durable facts, not transient task state. New memories become searchable once their embedding is processed.`;
}
Comment on lines +1709 to +1719

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Memory instructions reach Codex cloud runners too

buildMemoryInstructions() is appended unconditionally inside buildSessionSystemPrompt, and buildCodexInstructions (line 1651) re-uses that same output verbatim as the instructions field for Codex runs. The memory MCP tool is listed in mcpServers passed to newSession for both runtimes, but whether the Codex path actually negotiates and exposes MCP tools to the model is worth confirming — if it does not, Codex agents will reference a tool they cannot call. This is not a blocker given the architectural note in the PR description, but a quick check or comment clarifying that Codex also has memory available would make this assumption explicit.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/agent/src/server/agent-server.ts
Line: 1704-1714

Comment:
**Memory instructions reach Codex cloud runners too**

`buildMemoryInstructions()` is appended unconditionally inside `buildSessionSystemPrompt`, and `buildCodexInstructions` (line 1651) re-uses that same output verbatim as the `instructions` field for Codex runs. The `memory` MCP tool is listed in `mcpServers` passed to `newSession` for both runtimes, but whether the Codex path actually negotiates and exposes MCP tools to the model is worth confirming — if it does not, Codex agents will reference a tool they cannot call. This is not a blocker given the architectural note in the PR description, but a quick check or comment clarifying that Codex also has `memory` available would make this assumption explicit.

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


private buildCloudSystemPrompt(
prUrl?: string | null,
slackThreadUrl?: string | null,
Expand Down
Loading