Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(product-assistant): better Trends generation #25484

Draft
wants to merge 75 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
ef47d15
chore: deps
skoob13 Oct 9, 2024
12cb441
feat: initial graph
skoob13 Oct 9, 2024
a140d0d
feat: partial toolkit
skoob13 Oct 9, 2024
fe077b7
Update query snapshots
github-actions[bot] Oct 9, 2024
c40c9b1
Update query snapshots
github-actions[bot] Oct 9, 2024
50131c7
feat: tools
skoob13 Oct 9, 2024
46d96be
Update query snapshots
github-actions[bot] Oct 9, 2024
888725e
Update query snapshots
github-actions[bot] Oct 9, 2024
5b18198
feat: tool validation
skoob13 Oct 10, 2024
357b65a
feat: team query runner
skoob13 Oct 10, 2024
2d6f8b1
feat: tool loop
skoob13 Oct 10, 2024
6bd460a
feat: trend generation step
skoob13 Oct 10, 2024
90b6e30
refactor: stateful nodes
skoob13 Oct 10, 2024
6dd42e1
Merge branch 'feat/trends-agent' of github.com:PostHog/posthog into f…
skoob13 Oct 10, 2024
ab8761e
Update query snapshots
github-actions[bot] Oct 10, 2024
a701c38
Update query snapshots
github-actions[bot] Oct 10, 2024
d86cf52
Update query snapshots
github-actions[bot] Oct 10, 2024
8bfd076
feat: handle unformatted response
skoob13 Oct 10, 2024
18a535c
feat: pydantic schemas for state
skoob13 Oct 10, 2024
c879e8d
fix: state
skoob13 Oct 10, 2024
e3b8c69
feat: initial properties
skoob13 Oct 10, 2024
432e06c
Merge branch 'feat/trends-agent' of github.com:PostHog/posthog into f…
skoob13 Oct 10, 2024
97131b8
Update query snapshots
github-actions[bot] Oct 10, 2024
4a87b38
Update query snapshots
github-actions[bot] Oct 10, 2024
0db66fe
feat: support multiple arguments in tools
skoob13 Oct 11, 2024
c621378
feat: retrieve event properties
skoob13 Oct 11, 2024
b534431
chore: docs
skoob13 Oct 11, 2024
2110985
Merge branch 'feat/trends-agent' of github.com:PostHog/posthog into f…
skoob13 Oct 11, 2024
999f365
feat: entity validation in entity prop values retrieval
skoob13 Oct 11, 2024
2f4a90b
Update query snapshots
github-actions[bot] Oct 11, 2024
dc6194e
Update query snapshots
github-actions[bot] Oct 11, 2024
5b81a53
Update query snapshots
github-actions[bot] Oct 11, 2024
0ad38bf
fix: steps joining
skoob13 Oct 11, 2024
ba48f5a
feat: session retrieval
skoob13 Oct 11, 2024
5784c01
Merge branch 'feat/trends-agent' of github.com:PostHog/posthog into f…
skoob13 Oct 11, 2024
02483bb
Update query snapshots
github-actions[bot] Oct 11, 2024
69e002b
Update query snapshots
github-actions[bot] Oct 11, 2024
b466036
feat: wip conversations
skoob13 Oct 14, 2024
184a2e1
feat: agent conversation
skoob13 Oct 14, 2024
935a277
Merge branch 'master' of github.com:PostHog/posthog into feat/trends-…
skoob13 Oct 15, 2024
14b01e5
feat: reconstruct message history
skoob13 Oct 15, 2024
712e221
Merge branch 'feat/trends-agent' of github.com:PostHog/posthog into f…
skoob13 Oct 15, 2024
ce7d100
chore: __init__.py
skoob13 Oct 16, 2024
e662927
chore: execution limits
skoob13 Oct 17, 2024
7b8e03e
feat: migrating to a new assistant
skoob13 Oct 17, 2024
9227519
feat: streaming (wip)
skoob13 Oct 17, 2024
8ebf5df
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 17, 2024
707f6ec
refactor: query endpoint
skoob13 Oct 18, 2024
939247f
Merge branch 'master' of github.com:PostHog/posthog into feat/trends-…
skoob13 Oct 18, 2024
f589afa
feat: streaming
skoob13 Oct 18, 2024
e9b64b2
fix: streaming of plans
skoob13 Oct 18, 2024
507766b
merge
skoob13 Oct 18, 2024
e63d194
Update query snapshots
github-actions[bot] Oct 18, 2024
e47471a
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
3d371a8
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
e5fda3b
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
0605516
Update query snapshots
github-actions[bot] Oct 18, 2024
c39c19c
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
0a63d97
Update UI snapshots for `chromium` (2)
github-actions[bot] Oct 18, 2024
16411eb
Update query snapshots
github-actions[bot] Oct 18, 2024
dc04a7d
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
5abc6f1
Update UI snapshots for `chromium` (2)
github-actions[bot] Oct 18, 2024
518ed05
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
90b0a56
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
e62ae94
Update query snapshots
github-actions[bot] Oct 18, 2024
e187e5c
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
0087853
Update query snapshots
github-actions[bot] Oct 18, 2024
ecb78aa
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
6aac927
Update query snapshots
github-actions[bot] Oct 18, 2024
7ad390a
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
38e05a8
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
a431bcc
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
3aaffb5
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
7bbd2c9
Update query snapshots
github-actions[bot] Oct 18, 2024
e17cfc8
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions ee/hogai/assistant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from typing import cast

from langchain_core.messages import AIMessageChunk, BaseMessage
from langchain_core.outputs import Generation
from langgraph.graph.state import StateGraph

from ee.hogai.trends.nodes import CreateTrendsPlanNode, CreateTrendsPlanToolsNode, GenerateTrendsNode
from ee.hogai.utils import AssistantMessage, AssistantNodeName, AssistantState
from posthog.models.team.team import Team


class Assistant:
_team: Team
_graph: StateGraph

def __init__(self, team: Team):
self._team = team
self._graph = StateGraph(AssistantState)

def _compile_graph(self):
builder = self._graph

create_trends_plan_node = CreateTrendsPlanNode(self._team)
builder.add_node(CreateTrendsPlanNode.name, create_trends_plan_node.run)

create_trends_plan_tools_node = CreateTrendsPlanToolsNode(self._team)
builder.add_node(CreateTrendsPlanToolsNode.name, create_trends_plan_tools_node.run)

generate_trends_node = GenerateTrendsNode(self._team)
builder.add_node(GenerateTrendsNode.name, generate_trends_node.run)

builder.add_edge(AssistantNodeName.START, create_trends_plan_node.name)
builder.add_conditional_edges(create_trends_plan_node.name, create_trends_plan_node.router)
builder.add_conditional_edges(create_trends_plan_tools_node.name, create_trends_plan_tools_node.router)
builder.add_conditional_edges(GenerateTrendsNode.name, generate_trends_node.router)

return builder.compile()

def stream(self, messages: list[BaseMessage]):
assistant_graph = self._compile_graph()
generator = assistant_graph.stream(
{"messages": messages},
config={"recursion_limit": 24},
stream_mode="messages",
)

chunks = AIMessageChunk("")
parser = GenerateTrendsNode.output_parser

for message, state in generator:
if state["langgraph_node"] == AssistantNodeName.GENERATE_TRENDS:
if isinstance(message, AssistantMessage):
yield message
else:
message = cast(AIMessageChunk, message)
chunks += message
yield parser.parse_result([Generation(text=chunks.content)], partial=True)
55 changes: 0 additions & 55 deletions ee/hogai/generate_trends_agent.py

This file was deleted.

77 changes: 0 additions & 77 deletions ee/hogai/system_prompt.py

This file was deleted.

137 changes: 0 additions & 137 deletions ee/hogai/team_prompt.py

This file was deleted.

Empty file added ee/hogai/trends/__init__.py
Empty file.
Loading