Skip to content

Commit e4bb6d6

Browse files
authored
chore: add readme for ts package (#111)
1 parent 7a0b38e commit e4bb6d6

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ __pycache__/
1717

1818
.env
1919

20-
dist/
20+
dist/
21+
22+
.venv/

typescript/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# @posthog/agent-toolkit
2+
3+
Tools to give agents access to your PostHog data, manage feature flags, create insights, and more.
4+
5+
## Installation
6+
7+
```bash
8+
npm install @posthog/agent-toolkit
9+
```
10+
11+
## Quick Start
12+
13+
The toolkit provides integrations for popular AI frameworks:
14+
15+
### Using with Vercel AI SDK
16+
17+
```typescript
18+
import { openai } from "@ai-sdk/openai";
19+
import { PostHogAgentToolkit } from "@posthog/agent-toolkit/integrations/ai-sdk";
20+
import { generateText } from "ai";
21+
22+
const toolkit = new PostHogAgentToolkit({
23+
posthogPersonalApiKey: process.env.POSTHOG_PERSONAL_API_KEY!,
24+
posthogApiBaseUrl: "https://us.posthog.com" // or https://eu.posthog.com if you are hosting in the EU
25+
});
26+
27+
const result = await generateText({
28+
model: openai("gpt-4"),
29+
tools: toolkit.getTools(),
30+
prompt: "Analyze our product usage by getting the top 5 most interesting insights and summarising the data from them."
31+
});
32+
```
33+
34+
**[→ See full Vercel AI SDK example](https://github.com/posthog/mcp/tree/main/examples/ai-sdk)**
35+
36+
### Using with LangChain.js
37+
38+
```typescript
39+
import { ChatOpenAI } from "@langchain/openai";
40+
import { PostHogAgentToolkit } from "@posthog/agent-toolkit/integrations/langchain";
41+
import { AgentExecutor, createToolCallingAgent } from "langchain/agents";
42+
import { ChatPromptTemplate, MessagesPlaceholder } from "@langchain/core/prompts";
43+
44+
const toolkit = new PostHogAgentToolkit({
45+
posthogPersonalApiKey: process.env.POSTHOG_PERSONAL_API_KEY!,
46+
posthogApiBaseUrl: "https://us.posthog.com" // or https://eu.posthog.com if you are hosting in the EU
47+
});
48+
49+
const tools = toolkit.getTools();
50+
const llm = new ChatOpenAI({ model: "gpt-4" });
51+
52+
const prompt = ChatPromptTemplate.fromMessages([
53+
["system", "You are a data analyst with access to PostHog analytics"],
54+
["human", "{input}"],
55+
new MessagesPlaceholder("agent_scratchpad"),
56+
]);
57+
58+
const agent = createToolCallingAgent({ llm, tools, prompt });
59+
const executor = new AgentExecutor({ agent, tools });
60+
61+
const result = await executor.invoke({
62+
input: "Analyze our product usage by getting the top 5 most interesting insights and summarising the data from them."
63+
});
64+
```
65+
66+
**[→ See full LangChain.js example](https://github.com/posthog/mcp/tree/main/examples/langchain-js)**
67+
68+
## Available Tools
69+
70+
For a list of all available tools, please see the [docs](https://posthog.com/docs/model-context-protocol).

0 commit comments

Comments
 (0)