From e87695f2ef0126841e52fc481b7dd7654d7da06d Mon Sep 17 00:00:00 2001 From: Andrew Maguire Date: Wed, 14 Jan 2026 21:48:44 +0100 Subject: [PATCH] chore(docs): add OpenAI Agents SDK LLM analytics installation Add onboarding content for OpenAI Agents SDK integration with PostHog LLM analytics. Covers basic setup, multi-agent workflows, and tool usage. --- .../llm-analytics/openai-agents.tsx | 175 ++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 docs/onboarding/llm-analytics/openai-agents.tsx diff --git a/docs/onboarding/llm-analytics/openai-agents.tsx b/docs/onboarding/llm-analytics/openai-agents.tsx new file mode 100644 index 000000000000..27ec7af95a37 --- /dev/null +++ b/docs/onboarding/llm-analytics/openai-agents.tsx @@ -0,0 +1,175 @@ +import { useMDXComponents } from 'scenes/onboarding/OnboardingDocsContentWrapper' + +export const OpenAIAgentsInstallation = (): JSX.Element => { + const { + Steps, + Step, + CodeBlock, + CalloutBox, + ProductScreenshot, + OSButton, + Markdown, + Blockquote, + dedent, + snippets, + } = useMDXComponents() + + const NotableGenerationProperties = snippets?.NotableGenerationProperties + return ( + + + + Install the PostHog Python SDK with the OpenAI Agents SDK. + + + + + + + + Import and call the `instrument()` helper to register PostHog tracing with the OpenAI Agents SDK. This automatically captures all agent traces, spans, and LLM generations. + + + ", + host="" + ) + + # Register PostHog tracing with OpenAI Agents SDK + instrument( + client=posthog, + distinct_id="user_123", # optional + privacy_mode=False, # optional - redact inputs/outputs + groups={"company": "company_id"}, # optional + properties={"environment": "production"}, # optional + ) + `, + }, + ]} + /> + +
+ + **Note:** If you want to capture LLM events anonymously, **don't** pass a distinct ID to `instrument()`. See our docs on [anonymous vs identified events](https://posthog.com/docs/data/anonymous-vs-identified-events) to learn more. + +
+
+ + + + Run your OpenAI agents as normal. PostHog automatically captures traces for agent execution, tool calls, handoffs, and LLM generations. + + + + + + PostHog automatically captures `$ai_generation` events for LLM calls and `$ai_span` events for agent execution, tool calls, and handoffs. + + + {NotableGenerationProperties && } + + + + + PostHog captures the full trace hierarchy for complex agent workflows including handoffs and tool calls. + + + str: + """Get the weather for a city.""" + return f"The weather in {city} is sunny, 72F" + + weather_agent = Agent( + name="WeatherAgent", + instructions="You help with weather queries.", + tools=[get_weather] + ) + + triage_agent = Agent( + name="TriageAgent", + instructions="Route weather questions to the weather agent.", + handoffs=[weather_agent] + ) + + result = Runner.run_sync(triage_agent, "What's the weather in San Francisco?") + `, + }, + ]} + /> + + + This captures: + - Agent spans for `TriageAgent` and `WeatherAgent` + - Handoff spans showing the routing between agents + - Tool spans for `get_weather` function calls + - Generation spans for all LLM calls + + + + + + Under **LLM analytics**, you should see rows of data appear in the **Traces** and **Generations** tabs. + + +
+ + + + Check for LLM events in PostHog + +
+
+ ) +}