From 7ac4fcae61ac0bdecb377c389f9d49d61556d5d6 Mon Sep 17 00:00:00 2001 From: Andrew Maguire Date: Thu, 11 Jun 2026 10:44:48 +0100 Subject: [PATCH 1/2] feat(agent): guide cloud agents to use the PostHog memory MCP tool MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Appends persistent-memory guidance to every cloud-run system prompt so cloud agents recall durable context across runs and persist new learnings via the PostHog `memory` MCP tool — the shared, semantically-searchable memory store used by Max/PostHog AI. The tool itself is added server-side in PostHog/posthog (the cloud agent already forwards every PostHog MCP tool, so no allowlist change is needed here). Generated-By: PostHog Code Task-Id: b2ae2f32-aa94-4532-b069-b03875e73a58 --- packages/agent/src/server/agent-server.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/agent/src/server/agent-server.ts b/packages/agent/src/server/agent-server.ts index 0d2a8fc48..2dcba303a 100644 --- a/packages/agent/src/server/agent-server.ts +++ b/packages/agent/src/server/agent-server.ts @@ -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 @@ -1696,6 +1696,23 @@ 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. + */ + 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.`; + } + private buildCloudSystemPrompt( prUrl?: string | null, slackThreadUrl?: string | null, From cb84a33a853d3ae268d638a30b256507042bc049 Mon Sep 17 00:00:00 2001 From: Andrew Maguire Date: Thu, 11 Jun 2026 11:02:51 +0100 Subject: [PATCH 2/2] docs(agent): note memory tool is available to both cloud runtimes Clarifies that the memory MCP tool guidance correctly applies to both Claude and Codex cloud runs: newSession passes the PostHog MCP server via mcpServers for both runtimes, and the Codex adapter forwards those servers to the Codex CLI, so buildCodexInstructions reusing this text is intentional. Addresses a P2 review note from greptile-apps. Generated-By: PostHog Code Task-Id: b2ae2f32-aa94-4532-b069-b03875e73a58 --- packages/agent/src/server/agent-server.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/agent/src/server/agent-server.ts b/packages/agent/src/server/agent-server.ts index 2dcba303a..f1b12dc2d 100644 --- a/packages/agent/src/server/agent-server.ts +++ b/packages/agent/src/server/agent-server.ts @@ -1700,6 +1700,11 @@ 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 `