Skip to content
This repository was archived by the owner on Jan 19, 2026. It is now read-only.

Commit 280873e

Browse files
committed
feat: update docs for python package
1 parent 0186e70 commit 280873e

4 files changed

Lines changed: 52 additions & 86 deletions

File tree

β€Žexamples/langchain/posthog_agent_example.pyβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async def analyze_product_usage():
3333

3434
# Initialize the LLM
3535
llm = ChatOpenAI(
36-
model="gpt-4o-mini",
36+
model="gpt-5-mini",
3737
temperature=0,
3838
api_key=os.getenv("OPENAI_API_KEY")
3939
)
@@ -59,7 +59,7 @@ async def analyze_product_usage():
5959
agent=agent,
6060
tools=tools,
6161
verbose=False,
62-
max_iterations=5,
62+
max_iterations=30,
6363
)
6464

6565
# Invoke the agent with an analysis request

β€Žexamples/langchain/pyproject.tomlβ€Ž

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,17 @@ description = "PostHog LangChain integration example"
55
readme = "README.md"
66
requires-python = ">=3.11"
77
dependencies = [
8-
"posthog-agent-toolkit",
98
"langchain>=0.3.0",
109
"langchain-openai>=0.2.0",
1110
"langchain-core>=0.3.0",
1211
"python-dotenv>=1.0.0",
12+
"posthog-agent-toolkit>=0.1.0",
1313
]
1414

15-
[tool.uv.sources]
16-
posthog-agent-toolkit = { path = "../../python", editable = true }
17-
1815
[tool.ruff]
1916
line-length = 120
2017
target-version = "py311"
2118

2219
[tool.black]
2320
line-length = 120
24-
target-version = ['py311']
21+
target-version = ['py311']

β€Žexamples/langchain/uv.lockβ€Ž

Lines changed: 11 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žpython/README.mdβ€Ž

Lines changed: 37 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,57 @@
1-
# PostHog MCP Server - Python Implementation
1+
# posthog-agent-toolkit
22

3-
Python wrapper of the MCP server tools to make using PostHog easier in agents.
3+
Tools to give agents access to your PostHog data, manage feature flags, create insights, and more.
44

5-
## Setup
5+
This is a Python wrapper around the PostHog MCP (Model Context Protocol) server, providing easy integration with AI frameworks like LangChain.
66

7-
### 1. Install Dependencies with uv
8-
9-
For production:
10-
11-
```bash
12-
uv sync
13-
```
14-
15-
For development (includes schema generation tools):
7+
## Installation
168

179
```bash
18-
uv sync --dev
10+
pip install posthog-agent-toolkit
1911
```
2012

21-
### 2. Alternative: Create Virtual Environment Manually
13+
## Quick Start
2214

23-
If you prefer to use pip:
15+
The toolkit provides integrations for popular AI frameworks:
2416

25-
```bash
26-
python3 -m venv venv
27-
source venv/bin/activate # On Windows: venv\Scripts\activate
28-
pip install -e .
29-
```
17+
### Using with LangChain
3018

31-
## Development
19+
```python
20+
from langchain_openai import ChatOpenAI
21+
from langchain.agents import AgentExecutor, create_tool_calling_agent
22+
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
23+
from posthog_agent_toolkit.integrations.langchain.toolkit import PostHogAgentToolkit
3224

33-
### Schema Generation
25+
# Initialize the PostHog toolkit
26+
toolkit = PostHogAgentToolkit(
27+
personal_api_key="your_posthog_personal_api_key",
28+
url="https://mcp.posthog.com/mcp" # or your own, if you are self hosting the MCP server
29+
)
3430

35-
The Python implementation uses Pydantic models generated from the TypeScript Zod schemas:
31+
# Get the tools
32+
tools = await toolkit.get_tools()
3633

37-
```bash
38-
# From the root directory
39-
pnpm run schema:build # Generate both JSON schema and Python models
40-
```
34+
# Initialize the LLM
35+
llm = ChatOpenAI(model="gpt-5-mini")
4136

42-
This generates type-safe Pydantic models in `schema/tool_inputs.py` based on the shared JSON schema.
37+
# Create a prompt
38+
prompt = ChatPromptTemplate.from_messages([
39+
("system", "You are a data analyst with access to PostHog analytics"),
40+
("human", "{input}"),
41+
MessagesPlaceholder("agent_scratchpad"),
42+
])
4343

44-
### Project Structure
44+
# Create and run the agent
45+
agent = create_tool_calling_agent(llm=llm, tools=tools, prompt=prompt)
46+
executor = AgentExecutor(agent=agent, tools=tools)
4547

48+
result = await executor.ainvoke({
49+
"input": "Analyze our product usage by getting the top 5 most interesting insights and summarising the data from them."
50+
})
4651
```
47-
python/
48-
β”œβ”€β”€ pyproject.toml # Project configuration and dependencies
49-
β”œβ”€β”€ uv.lock # Locked dependency versions (generated by uv)
50-
β”œβ”€β”€ schema/
51-
β”‚ └── tool_inputs.py # Generated Pydantic models
52-
└── scripts/
53-
└── generate-pydantic-models.sh # Schema generation script
54-
```
55-
56-
### Running Commands
57-
58-
All Python commands should be run through uv:
5952

60-
```bash
61-
# Run tests
62-
uv run pytest
63-
64-
# Format code
65-
uv run ruff format .
66-
67-
# Lint code
68-
uv run ruff check --fix .
69-
```
53+
**[β†’ See full LangChain example](https://github.com/posthog/mcp/tree/main/examples/langchain)**
7054

71-
### Dependencies
55+
## Available Tools
7256

73-
Dependencies are managed in `pyproject.toml`.
57+
For a list of all available tools, please see the [docs](https://posthog.com/docs/model-context-protocol).

0 commit comments

Comments
Β (0)