integrating-with-posthog-ai
Skill721 starsChanged 2 months agoMITView on GitHub
Wire a PostHog product surface into the PostHog AI agent from the frontend. Use when attaching scene or entity context, injecting instructions to steer the agent, reacting to the agent calling a tool, applying an agent edit back into an open form, or rendering a product tool card in a thread.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- PostHog/posthogword for word, first seen Oct 4, 2026
Other versions1 project uses a version of this.
Word for word · 1
- PostHog/posthog★ 40k100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository119 other files it gives its agents.
- AGENTS.mdAGENTS.md
- common/AGENTS.mdAGENTS.md
- proto/AGENTS.mdAGENTS.md
- rust/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- common/CLAUDE.mdCLAUDE.md
- proto/CLAUDE.mdCLAUDE.md
- rust/CLAUDE.mdCLAUDE.md
- .cursor/rules/django-python.mdcCursor rule
- .cursor/rules/react-typescript.mdcCursor rule
- .cursor/rules/rust.mdcCursor rule
- adding-activity-loggingSkill
- adding-api-scopesSkill
- adding-inbound-webhooksSkill
- adding-inbox-sourcesSkill
- adding-ingestion-warningsSkill
- adding-mcp-store-serversSkill
- adding-personhog-rpcSkill
- adding-product-alertingSkill
- adding-project-secret-api-key-authSkill
- adopting-generated-api-typesSkill
- analyzing-experiment-precompute-canarySkill
- analyzing-experiment-query-performanceSkill
- analyzing-insights-across-teamsSkill
- announcing-behavior-changesSkill
- auditing-llm-gateway-paritySkill
- auditing-warehouse-source-coverageSkill
- authenticating-to-clickhouseSkill
- authoring-ci-workflowsSkill
- autoresolving-pr-conflictsSkill
- building-product-empty-statesSkill
- clickhouse-migrationsSkill
- debugging-ci-failuresSkill
- debugging-local-replaySkill
- debugging-local-task-agent-runsSkill
- debugging-mcp-analyticsSkill
- debugging-signals-pipelineSkill
- debugging-table-access-deniedSkill
- depot-ciSkill
- depot-container-buildsSkill
- depot-github-runnersSkill
- developing-subscriptionsSkill
- django-migrationsSkill
- django-startup-timeSkill
- documenting-warehouse-sourcesSkill
- editing-agents-mdSkill
- establishing-code-ownershipSkill
- extending-hobby-smoke-testsSkill
- extending-personhog-test-harnessSkill
- finding-llm-gateway-migration-candidatesSkill
- fixing-flaky-testsSkill
- gating-production-deploysSkill
- gating-sensitive-actionsSkill
- generating-clickhouse-query-performance-reportsSkill
- hogliSkill
- implementing-mcp-toolsSkill
- implementing-mcp-ui-appsSkill
- implementing-warehouse-sourcesSkill
- improving-drf-endpointsSkill
- improving-mcp-toolsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 35
Always a domain-scoped api/<module> entry, never a deep path, and there is deliberately no root barrel:
- Distinctive: line 49
If a pointer must vary (which id is open, which step is selected), put it on an untrusted item and have the static instruction refer to it …
- Very specific: line 57
If that is genuinely the task, read products/posthog_ai/frontend/README.md and AGENTS.md first, and copy one of the two reference …
- Very specific: line 61
The LangGraph runtime is frozen: No new useMaxTool registrations, no new MaxUIContext fields, no new maxContext selectors on scene logics.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Integrating a product with PostHog AI
The user-facing doc is products/posthog_ai/README.md. This skill is how to do the work: pick the right seam, avoid the two mistakes that matter, and stop before the deep end.
First: is this a frontend job at all?
There is no backend integration API. An integration has two halves, and the frontend half depends on the backend half:
- Capability — the agent reads and writes your entities through MCP tools. If no tool can resolve the thing you want to talk about, start there:
/implementing-mcp-tools,products/<name>/mcp/tools.yaml. - Cooperation — the frontend seams below.
Injected context carries references, not data. A reference the agent cannot resolve with a tool is a dead end, so confirm the tool exists before you inject the ref.
Pick the seam
| The job | Seam | Import from | Use it? | Reference |
| The agent should know what the user is looking at, including unsaved work | Attached context | api/logics | Recommended | injecting-context.md |
| Steer how the agent behaves here — which tools to prefer, what "this" means on this page, or hand it a skill | Trusted instructions | api/logics | Recommended | injecting-instructions.md |
| The page should update when the agent does something | Tool-event bus | api/logics | Recommended | reacting-to-tool-calls.md |
| Your tool's calls should render as a real card, not the generic fallback | Tool registry | api/tools | Recommended | rendering-widgets.md |
| Build your own agent UI out of the thread, composer, and stream primitives | Run primitives | api/runSurface, api/primitives | Not recommended — see below | products/posthog_ai/frontend/README.md |
The first four are the product integration. The fifth exists for the three surfaces that host an agent run — the Max scene, the signals inbox, and the tasks runner — not for products that want to cooperate with one. Reaching for it by default is the main way this goes wrong.
Whole scene at once: useSceneAgentPanel({ sceneKey, contextItems, headlines }) from frontend/src/scenes/max/useSceneAgentPanel.ts bundles context, welcome headlines, and gated auto-open of the side panel. Start there for a scene; drop to the individual hooks for one component. products/workflows/frontend/Workflows/WorkflowScene.tsx is the exemplar.
The import rule
Always a domain-scoped api/<module> entry, never a deep path, and there is deliberately no root barrel:
import { useAttachedContext, useMcpToolApplyBack } from 'products/posthog_ai/frontend/api/logics'Pick the narrowest module. api/logics and api/types are headless; api/primitives drags in markdown and virtualization; api/tools initializes the registry from built-ins and the central manifest at module load, so importing it is a side effect that is not tree-shaken. A status badge that imports the wrong tier doubles its chunk.
The two mistakes that matter
1. Putting variable data in trusted context. type: 'instructions' items land in <posthog_trusted_context> — guidance the agent follows. Everything else lands in <posthog_untrusted_context>, behind hardening prose. So:
- Instructions carry only your own build-time strings. Never a user-entered name, an ingested value, or anything interpolated from one. A crafted entity name in trusted context is a prompt injection against whoever reads the thread next.
- Untrusted context is where user data belongs, and injecting it freely is the point — the user's unsaved editor state is usually the most useful thing you have.
- If a pointer must vary (which id is open, which step is selected), put it on an untrusted item and have the static instruction refer to it by field name.
2. Sending object shapes instead of identifiers. The context block rides on every message in the conversation. Send { type, key, label } and let the agent fetch details through your MCP tools. The exception is unsaved state the agent cannot fetch — budget it (workflowAgentContext.ts caps at 64k chars and elides rather than truncates) and redact secrets, which sit in cleartext in live form state even though saved secrets never reach the frontend.
Stop at seam 4
The run primitives are public — RunSurface, ReadonlyRunSurface, EmbeddedRunner, the Thread atoms, runStreamLogic — but building a custom agent UI on them is not a product integration. It means owning stream binding, composer and queue state, permission routing, and the eager-vs-lazy tier choice that decides your bundle size. There is no default layout.
If that is genuinely the task, read products/posthog_ai/frontend/README.md and AGENTS.md first, and copy one of the two reference implementations (the signals inbox detail views, or scenes/TaskTracker/components/TaskRunChat.tsx) rather than composing from scratch.
Do not touch
- The LangGraph runtime is frozen. No new
useMaxToolregistrations, no newMaxUIContextfields, no newmaxContextselectors on scene logics. Use attached context and the tool-event bus instead. - The coupling gate. Nothing under
products/posthog_ai/frontendmay importscenes/max,maxThreadLogic,maxContextLogic, or the conversations API. Max is a consumer of that surface, not a dependency of it. If the surface is missing something you need, lift it to a generic prop or selector there — never special-case a consumer inside it.
Verify
pnpm --filter=@posthog/frontend typescript:checkfor the types.- Run the app and open the side panel on your page. Context is invisible by design, so check it landed: an attached item that is not
hiddenshows as a chip in the composer's context bar, and the agent should be able to answer a question about the thing you attached without being told its id. - For a reactivity seam, ask the agent to make the change and confirm the open page updates. Then reload the page — your handler must not fire again, because replay events are suppressed by default.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

