Socket
Book a DemoInstallSign in
Socket

@posthog/agent-toolkit

Package Overview
Dependencies
Maintainers
14
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@posthog/agent-toolkit

PostHog tools for AI agents

npmnpm
Version
0.2.1
Version published
Maintainers
14
Created
Source

@posthog/agent-toolkit

Tools to give agents access to your PostHog data, manage feature flags, create insights, and more.

Installation

npm install @posthog/agent-toolkit

Quick Start

The toolkit provides integrations for popular AI frameworks:

Using with Vercel AI SDK

import { openai } from "@ai-sdk/openai";
import { PostHogAgentToolkit } from "@posthog/agent-toolkit/integrations/ai-sdk";
import { generateText } from "ai";

const toolkit = new PostHogAgentToolkit({
    posthogPersonalApiKey: process.env.POSTHOG_PERSONAL_API_KEY!,
    posthogApiBaseUrl: "https://us.posthog.com" // or https://eu.posthog.com if you are hosting in the EU
});

const result = await generateText({
    model: openai("gpt-4"),
    tools: toolkit.getTools(),
    prompt: "Analyze our product usage by getting the top 5 most interesting insights and summarising the data from them."
});

→ See full Vercel AI SDK example

Using with LangChain.js

import { ChatOpenAI } from "@langchain/openai";
import { PostHogAgentToolkit } from "@posthog/agent-toolkit/integrations/langchain";
import { AgentExecutor, createToolCallingAgent } from "langchain/agents";
import { ChatPromptTemplate, MessagesPlaceholder } from "@langchain/core/prompts";

const toolkit = new PostHogAgentToolkit({
    posthogPersonalApiKey: process.env.POSTHOG_PERSONAL_API_KEY!,
    posthogApiBaseUrl: "https://us.posthog.com" // or https://eu.posthog.com if you are hosting in the EU
});

const tools = toolkit.getTools();
const llm = new ChatOpenAI({ model: "gpt-4" });

const prompt = ChatPromptTemplate.fromMessages([
    ["system", "You are a data analyst with access to PostHog analytics"],
    ["human", "{input}"],
    new MessagesPlaceholder("agent_scratchpad"),
]);

const agent = createToolCallingAgent({ llm, tools, prompt });
const executor = new AgentExecutor({ agent, tools });

const result = await executor.invoke({
    input: "Analyze our product usage by getting the top 5 most interesting insights and summarising the data from them."
});

→ See full LangChain.js example

Available Tools

For a list of all available tools, please see the docs.

Keywords

posthog

FAQs

Package last updated on 11 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts