ARTICLE DETAIL

资讯详情

深耕网站视觉设计与运营推广的一线实战洞察。

PostHog AI 平台扩展实战:基于 MaxTool 与 Taxonomy Agent 的完整接入指南

PostHog AI 平台扩展实战:基于 MaxTool 与 Taxonomy Agent 的完整接入指南 PostHog AI 平台扩展实战基于 MaxTool 与 Taxonomy Agent 的完整接入指南【免费下载链接】posthog:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.项目地址: https://gitcode.com/GitHub_Trending/po/posthog导读本文围绕 PostHog 开源仓库中ee/hogaiPostHog AI 平台的官方扩展文档系统讲解两条核心扩展路径MaxTool让 AI Agent 在前后端执行任意操作的产品工具如执行 SQL、增删改查仪表盘与Taxonomy Agent浏览团队事件/属性分类体系的 RAG 式小智能体并进一步覆盖查询类型扩展、访问控制与危险操作审批机制。读完本文你将掌握从后端定义、前端挂载、注册元数据到调试迭代、权限收敛的完整 MaxTool 开发闭环以及将 Taxonomy Agent 接入 MaxTool 的完整代码范式全部内容均可在本仓库源码中逐一验证。一、PostHog AI 与 MaxTool一个让 Agent 操作你的产品的扩展框架ee/hogai目录承载着 PostHog AI 平台及其核心能力。其中面向产品团队的核心扩展接口是MaxTool借助 MaxTool API你可以让 AI Agent 在你的产品中做任何事——既执行后端动作也控制前端 UI。MaxTool 的设计遵循前后端分离的两段式结构后端定义一个 Python 类包含工具的元数据工具是什么、如何用、何时用、接受哪些参数——这些元数据最终会注入 LLM 的上下文同时包含工具的实际实现逻辑。前端挂载点一个 React 组件使工具可用——只有被自动化 UI 存在时工具才能被调用。一个工具内部还可以再包含一次 LLM 调用基于根节点传入的参数 前端传入的上下文针对该工具的任务定制一段 prompt 让 LLM 执行。开发 MaxTool 需要配置相应的环境变量API Key仓库中相关说明在ee/hogai/README.md。二、定义一个新的 MaxTool后端部分2.1 文件约定与自动发现按约定创建产品的max_tools.py文件如不存在则新建products/your product/backend/max_tools.py遵循该约定的max_tools.py会被系统自动发现并加载。从源码看自动发现逻辑位于ee/hogai/registry.py_import_max_tools负责导入全部已注册的 MaxToolee/hogai/test/test_tool.py中test_all_tools_have_access_control_or_are_exempt正是通过它遍历所有工具做访问控制校验。2.2 工具类骨架从 Args Schema 到_arun_impl在max_tools.py中定义一个继承自MaxTool的工具类。以下是官方文档给出的完整模板from pydantic import BaseModel, Field from ee.hogai.llm import MaxChatOpenAI from ee.hogai.tool import MaxTool # Define your tools arguments schema class YourToolArgs(BaseModel): parameter_name: str Field(descriptionDescription of the parameter) class YourToolOutput(BaseModel): result_data: int class YourTool(MaxTool): name: str your_tool_name # Must match a value in AssistantTool enum description: str What this tool does context_prompt_template: str Context about the tool state: {context_var} args_schema: type[BaseModel] YourToolArgs async def _arun_impl(self, parameter_name: str) - tuple[str, YourToolOutput]: # Implement tool logic here # Access context with self.context (must have context_var from template) # If you use Djangos ORM, ensure you utilize its asynchronous capabilities. # Optional: Use LLM to process inputs or generate structured outputs model MaxChatOpenAI(modelgpt-4o, temperature0.2).with_structured_output(YourToolOutput).with_retry() response model.ainvoke({question: What is PostHog?}) # Process and return results as (message, structured_data) return Tool execution completed, response对照ee/hogai/tool.py的MaxTool基类可以确认以下几个关键契约返回值必须是二元组(content, artifact)_arun_impl返回tuple[str, Any]其中 artifact 会成为ui_payload传给前端。基类强制response_format content_and_artifact见 tool.py 类属性定义。异步优先基类中_run_impl已被标记为 DEPRECATED_arun_impl才是标准入口_run/_arun会自动先做资源级权限检查再执行上下文注入与危险操作审批见下文。子类命名约束__init_subclass__强制子类类名必须以Tool结尾否则抛出ValueError(The name of a MaxTool subclass must end with Tool, for clarity)。工具名强校验name必须是AssistantTool枚举的合法值否则会在类定义阶段报错提示去schema-assistant-messages.ts修正或执行pnpm schema:build。注册即自动发生__init_subclass__会把工具注册进CONTEXTUAL_TOOL_NAME_TO_TOOL注册表CONTEXTUAL_TOOL_NAME_TO_TOOL[accepted_name] cls。context_prompt_template的作用是把工具的状态上下文以占位符形式注入根节点的上下文消息从而强引导根节点决定何时、是否使用该工具。其底层实现format_context_prompt_injection只替换{合法标识符}形式的占位符{{/}}作为字面花括号转义保留缺失的 key 会被替换为None——这些行为在 test_tool.py 的TestMaxTool中都有对应测试包括模板中含 Hog/JS 代码块fun onEvent(event) { ... }时不会被误解析的用例。2.3 在工具内部使用 LLMMaxChatOpenAI与MaxChatAnthropicee/hogai/llm.py为 LangChain 的 OpenAI/Anthropic 模型提供了 PostHog 定制的子类自动注入项目/组织/用户上下文每次调用都会把项目名、时区、当前时间、组织名、用户名/邮箱、部署区域等信息作为系统提示词的末尾注入PROJECT_ORG_USER_CONTEXT_PROMPT包括 App 内部 URL 必须使用根相对路径等约束。可通过inject_contextFalse关闭。自动重试默认max_retries 3stream_usage True。计费标记billableTrue时本次生成会被标记为$ai_billable计入 AI 计费 credit工具级与 workflow 级如 impersonation可叠加控制未计费时会累加posthog_ai_billing_skipped_total指标。代理绕行MaxChatAnthropic支持bypass_proxyTrue以绕过 egress 代理Smokescreen专供私有 LLM gateway 使用。2.4 注册工具名到AssistantTool联合类型把你的工具名加入frontend/src/queries/schema/schema-assistant-messages.ts中的AssistantTool联合类型schema-assistant-messages.ts然后运行pnpm schema:buildAssistantTool是一个字符串字面量联合类型目前包含search_session_recordings、execute_sql、upsert_dashboard、read_taxonomy、filter_session_recordings、create_insight、call_mcp_server等几十个工具名。它是前后端强一致性的契约层——后端工具名的合法值由它约束前端挂载的name也由它约束。2.5 定义前端工具元数据TOOL_DEFINITIONS在frontend/src/scenes/max/max-constants.tsx的TOOL_DEFINITIONS中补充工具元数据export const TOOL_DEFINITIONS: ... { // ... existing tools ... your_tool_name: { name: Do something, description: Do something to blah blah, product: Scene.YourProduct, // or null for the rare global tool flag: FEATURE_FLAGS.YOUR_FLAG, // optional indication that this is flagged }, }该元数据既用于场景 UI 展示这个能力可用也用于 Max 面板向用户解释工具能力。以真实的search_session_recordings为例max-constants.tsxsearch_session_recordings: { name: Search recordings, description: Search recordings quickly, product: Scene.Replay, icon: iconForType(session_replay), displayFormatter: (toolCall) { if (toolCall.status completed) { return Searched recordings } return Searching recordings... }, },2.6 仓库内置示例工具ee/hogai/tools目录下是官方示例集合文档点名了两个execute_sqltool.pySQL 生成与执行。其create_tool_class工厂方法会用 SQL 表达式文档、支持函数/聚合文档动态拼装系统提示词EXECUTE_SQL_SYSTEM_PROMPT_arun_impl支持filtersHogQLFilters、viz_title、viz_description、display图表类型、chart_settings等参数外部数据连接connection_id存在时会把查询标记connectionId并跳过本地 ClickHouse 校验交由 runner 按连接 schema 校验。upsert_dashboardtool.py创建与编辑仪表盘。参数用action判别联合区分create/update它声明了资源级权限[(dashboard, editor)]并把更新会删除已有 insight的操作用is_dangerous_operation标记为危险操作走用户审批流见第五节。三、在前端挂载工具MaxTool组件3.1 组件用法使用MaxTool组件包裹能从 AI 协助中受益的 UI 元素组件实现见 MaxTool.tsximport { MaxTool } from scenes/max/MaxTool function YourComponent() { return ( MaxTool nameyour_tool_name // Must match backend tool name - enforced by the AssistantTool enum displayNameHuman-friendly name context{{ // Context data passed to backend - can be empty if there truly is no context context_var: relevantData, }} callback{(toolOutput) { // Handle structured output from tool updateUIWithToolResults(toolOutput) }} initialMaxPromptOptional initial prompt for Max onMaxOpen{() { // Optional actions when Max panel opens }} {/* Your UI component that will have Max assistant */} YourUIComponent / /MaxTool ) }挂载完成后工具会自动以TOOL_DEFINITIONS元数据为基础在场景 UI 和 Max 面板中显示为可用能力帮助用户理解该能力。3.2 真实挂载案例会话录制筛选文档推荐参考frontend/src/scenes/session-recordings/filters/RecordingsUniversalFiltersEmbed.tsxREADME 中描述其挂载search_session_recordings当前代码实际挂载的是同族的filter_session_recordings两者都在AssistantTool联合类型中。核心代码RecordingsUniversalFiltersEmbed.tsxMaxTool identifierfilter_session_recordings context{{ current_filters: filters, current_session_id: currentSessionRecordingId, }} callback{applyFilters} initialMaxPromptShow me recordings where suggestions{[ Show recordings of people who visited signup in the last 24 hours, Show recordings showing user frustration, Show recordings of people who faced bugs, ]} onMaxOpen{() setIsFiltersExpanded(false)} classNamegrow LemonButton ....../LemonButton CurrentFilterIndicator / /MaxTool可以看到context中传入的current_filters与current_session_id正好对应后端SearchSessionRecordingsTool的context_prompt_template占位符Current recordings filters are: {current_filters}.\nCurrent session ID being viewed: {current_session_id}.。前后端上下文通过contextprop 与context_prompt_template的占位符一一对应形成完整链路见 max_tools.py。注意MaxTool.tsx的 docstring 已标注该组件被标记为 deprecated未来将由 context-aware AI 取代开发新功能前建议与 team-posthog-ai 沟通——这一点属于从源码注释可确认的现状规划新工具时值得留意。四、迭代与调试工具初版落地后文档强调test the heck out of it像普通用户一样把所有用法都试一遍并持续调优四个面工具名name工具描述description上下文消息的 promptcontext_prompt_template前端传入的 context开发期间获得完整可观测性的方式是使用本地 PostHog AI 可观测性面板http://localhost:8010/ai-observability/traces其中每一条trace 代表提交给 Max 的一条人类消息展示为回答该消息所执行的完整步骤序列。这在调试多步骤工具如 Taxonomy Agent 的多次工具调用时尤为关键。五、访问控制两级权限模型MaxTool 支持资源级与对象级两级访问控制两者在权限不足时都抛出MaxToolAccessDeniedError定义于ee/hogai/tool_errors.py。主访问检查逻辑位于products/access_control/backend/facade/user_access_control.pyUserAccessControl类MaxTool.user_access_control属性即为其实例见 tool.py。5.1 资源级访问控制根据用户对某类资源的权限限制工具执行例如用户没有 editor 权限时禁止创建 feature flag。在_arun_impl()被调用之前自动执行_run/_arun会先调用_check_resource_access。在工具中覆写get_required_resource_access()def get_required_resource_access(self): return [(feature_flag, editor)] # Single resource # Or multiple: return [(dashboard, editor), (insight, viewer)]如果你的工具需要接入访问控制把它从ee/hogai/test/test_tool.py的TOOLS_WITHOUT_ACCESS_CONTROL豁免集合中移除。支持的资源类型见posthog/scopes.py的APIScopeObject例如feature_flag、dashboard、insight、experiment、survey访问级别为none、viewer、editor、manager。5.2 对象级访问控制限制对特定对象实例的访问如某个具体仪表盘或 insight。在获取对象后调用check_object_access()async def _arun_impl(self, dashboard_id: str) - tuple[str, Any]: dashboard await Dashboard.objects.aget(iddashboard_id) await self.check_object_access(dashboard, editor, resourcedashboard, actionedit) # ... rest of implementationcheck_object_access底层走UserAccessControl.check_access_level_for_object资源名缺省时从obj._meta.model_name推导用于错误信息。5.3 豁免机制若工具不需要访问控制只读、不涉及受保护资源需显式加入TOOLS_WITHOUT_ACCESS_CONTROL并注明原因。测试test_all_tools_have_access_control_or_are_exempt会强制这一纪律所有已注册工具要么声明get_required_resource_access()返回非空列表要么出现在豁免集合中否则测试失败。当前豁免列表test_tool.py中的典型条目与理由包括search、read_taxonomy、todo_write、switch_mode、manage_memories—— 不查看/修改受保护资源read_data、list_data、create_notebook、finalize_plan—— 在_arun_impl内做动态/条件访问检查或无受保护资源修改diagnose_proxy—— 在_arun_impl内部显式检查OrganizationMembership.Level ADMIN资源级 RBAC 无法识别成员级别。5.4 危险操作审批Dangerous Operation除访问控制外MaxTool还内建了危险操作审批流ee/hogai/tool.py的is_dangerous_operation/format_dangerous_operation_preview/_handle_dangerous_operation工具可覆写is_dangerous_operation声明某些操作需要用户批准审批请求通过 LangGraph 的interrupt()暂停执行并返回ApprovalRequest含proposal_id、tool_name、preview、payload给前端用户批准/拒绝后以ApprovalResumePayload恢复。源码中特别处理了一个安全细节审批人修改过的参数必须写回调用方原 kwargs 引用确保执行的是用户批准过的操作而不是最初请求的操作——TestDangerousOperationBindsApprovedArguments测试验证了这一行为用户把count200改成count5后工具实际执行的是 5。upsert_dashboard是危险操作审批的典型实践更新仪表盘若会删除已有 insight则is_dangerous_operation返回Trueformat_dangerous_operation_preview会生成包含仪表盘名、新增/删除 insight 清单带数量与名称的富文本预览供用户在审批卡片上确认。5.5 错误体系ee/hogai/tool_errors.py定义了分层的工具错误test_tool.py的TestMaxToolErrorHierarchy验证了其契约异常类型retry_strategyretry_hintMaxToolError基类never空MaxToolFatalErrornever空MaxToolTransientErroronceYou may retry this operation once without changes.MaxToolRetryableErroradjustedYou may retry with adjusted inputs.MaxToolAccessDeniedError继承自 FatalErrornever提示联系项目管理员错误摘要to_summary(max_length)会以类名: 消息格式截断输出防止超长错误污染上下文。六、LLM 工具的最佳实践文档给出四条经验法则从前端提供关于当前状态的全面上下文context 越完整LLM 决策越准用多样化的输入和边界情况测试保持 prompt 清晰结构化给出显式规则允许用户既从零开始完成任务也能对已有结果进行细化。七、扩展新的查询类型Query Executor 体系PostHog AI 可以从前端上下文读取多种查询类型trends、funnels、retention、HogQL 查询等。要新增查询类型支持需要同时扩展QueryExecutor与Root node。注意这不会扩展查询类型的生成能力那需要与 PostHog AI 团队沟通。7.1 更新查询执行器与格式化器ee/hogai/context/insight/在context/insight/format/下新增一个实现查询结果 → AI 可读格式的格式化类并确保从context/insight/format/__init__.py导入导出。现有格式化器包括trends.py、funnel.py、lifecycle.py、paths.py、retention.py、stickiness.py、boxplot.py、sql.py。在context/insight/query_executor.py的_compress_results()方法中新增格式化分支elif isinstance(query, YourNewAssistantQuery | YourNewQuery): return YourNewResultsFormatter(query, response[results]).format()在context/insight/prompts.py为你的查询类型添加示例 prompt向 LLM 解释结果格式。现有示例 prompt 包括TRENDS_EXAMPLE_PROMPT、FUNNEL_STEPS_EXAMPLE_PROMPT、FUNNEL_TIME_TO_CONVERT_EXAMPLE_PROMPT、FUNNEL_TRENDS_EXAMPLE_PROMPT、LIFECYCLE_EXAMPLE_PROMPT、PATHS_EXAMPLE_PROMPT、RETENTION_EXAMPLE_PROMPT、SQL_EXAMPLE_PROMPT、STICKINESS_EXAMPLE_PROMPT、BOX_PLOT_EXAMPLE_PROMPT以及兜底的FALLBACK_EXAMPLE_PROMPT。更新context/insight/query_executor.py的get_example_prompt()函数以处理新类型if isinstance(viz_message.answer, YourNewAssistantQuery): return YOUR_NEW_EXAMPLE_PROMPTget_example_prompt的现有实现query_executor.py会按查询类型分发到对应示例funnel 还会根据funnelVizType细分STEPS / TIME_TO_CONVERT / TRENDSboxplot 由 trends 派生。7.2 创建格式化器类按现有格式化器的模式创建format/your_formatter.pyclass YourNewResultsFormatter: def __init__(self, query: YourNewQuery, results: dict, team: Optional[Team] None, utc_now_datetime: Optional[datetime] None): self._query query self._results results self._team team self._utc_now_datetime utc_now_datetime def format(self) - str: # Format your query results for AI consumption # Return a string representation optimized for LLM understanding pass7.3 添加测试在test/test_query_executor.py为新查询类型添加测试用例在test/format/test_format.py为新格式化器添加测试用例测试须同时覆盖成功执行与错误处理路径。7.4 关键设计考虑源码印证查询执行AssistantQueryExecutor类负责完整查询生命周期包括异步轮询与错误处理基于posthog.clickhouse.client.execute_async.get_query_status与ExecutionMode阻塞/非阻塞执行模式见 query_executor.py 的导入与arun_and_format_query结果格式化每种查询类型需要专门的格式化器把原始结果转为 AI 可读格式存在NULL_MARKER、TRUNCATED_MARKER等约定标记错误处理自定义格式化失败时回退到原始 JSONused_fallback标志会驱动使用FALLBACK_EXAMPLE_PROMPT上下文感知Root node 提供 UI 上下文dashboards、insights、events、actions帮助 AI 理解当前状态记忆集成系统可访问 core memory 与 onboarding 状态提供上下文响应。八、Taxonomy Agent构建 RAG 式分类体系智能体Taxonomy Agent 用于构建小型的、聚焦的、agentic RAG 式智能体它们浏览团队的分类体系事件 events、实体属性 entity properties、事件属性 event properties并产出结构化答案。8.1 快速开始四步搭建第 1 步定义结构化输出智能体必须返回的 schemafrom pydantic import BaseModel class MaxToolTaxonomyOutput(BaseModel): # The schema that the agent should return as a response # See an example: from posthog.schema import MaxRecordingUniversalFilters第 2 步创建 toolkit添加一个类型化的final_answer工具可选把属性输出格式改为 YAML以及任意自定义工具本例为hello_worldfrom pydantic import BaseModel, Field from ee.hogai.chat_agent.taxonomy.toolkit import TaxonomyAgentToolkit from ee.hogai.chat_agent.taxonomy.tools import base_final_answer from posthog.models import Team class final_answer(base_final_answer[MaxToolTaxonomyOutput]): # Usually the final answer tool will be different for each max_tool based on the expected output. __doc__ base_final_answer.__doc__ # Inherit from the base final answer or create your own. class hello_world(BaseModel): Tool for saying hello to the user, should be used in the very beginning of the conversation. Use it before you use any other tool. name: str Field(descriptionThe name of the person to say hello to.) def hello_world_tool(name: str) - str: return fHello, {name}! class YourToolkit(TaxonomyAgentToolkit): def __init__(self, team: Team): super().__init__(team) # You must override this method if you are adding a custom tool that is only applicable to your usecase def handle_tools(self, tool_name: str, tool_input: TaxonomyTool) - tuple[str, str]: Override the handle_tools method to add custom tools. if tool_name hello_world: result hello_world_tool(tool_input.arguments.name) return tool_name, result return super().handle_tools(tool_name, tool_input) def _get_custom_tools(self) - list: return [final_answer, hello_world] # Optional: prefer YAML over XML for property lists, but not a must to override # If not overriden XML will be used def _format_properties(self, props: list[tuple[str, str | None, str | None]]) - str: return self._format_properties_yaml(props)底层TaxonomyAgentToolkittoolkit.py内置了 taxonomy 查询能力EventTaxonomyQuery事件分类与ActorsPropertyTaxonomyQuery实体属性分类分别由EventTaxonomyQueryRunner与ActorsPropertyTaxonomyQueryRunner执行并支持虚拟属性组virtual_properties.py、属性值采样、XML/YAML 两种属性格式化等能力。第 3 步定义循环节点与工具节点并在图中绑定from langchain_core.prompts import ChatPromptTemplate from posthog.models import Team, User from ee.hogai.chat_agent.taxonomy.nodes import TaxonomyAgentNode, TaxonomyAgentToolsNode from ee.hogai.chat_agent.taxonomy.agent import TaxonomyAgent from ee.hogai.chat_agent.taxonomy.types import TaxonomyAgentState class LoopNode(TaxonomyAgentNode[TaxonomyAgentState, TaxonomyAgentState[MaxToolTaxonomyOutput]]): def __init__(self, team: Team, user: User, toolkit_class: type[YourToolkit]): super().__init__(team, user, toolkit_classtoolkit_class) def _get_system_prompt(self) - ChatPromptTemplate: To allow for maximum flexibility you override the system prompt to tailor the taxonomy search agent to your needs. The taxonomy agent comes with some prepackaged default prompts. Check them here ee/hogai/chat_agent/taxonomy/prompts.py system [ Here you add your custom prompt, you can define things like taxonomy operators, filter logic, or any other instruction you need for your usecase., *super()._get_default_system_prompts(), # You can reuse the default prompts we provide if they match your criteria ] return ChatPromptTemplate([(system, m) for m in system], template_formatmustache) class ToolsNode(TaxonomyAgentToolsNode[TaxonomyAgentState, TaxonomyAgentState[MaxToolTaxonomyOutput]]): This is the tool node where the tool call flow and the tool execution is handled. You can override the methods to your needs, although in most cases you shall not need to do so. def __init__(self, team: Team, user: User, toolkit_class: type[YourToolkit]): super().__init__(team, user, toolkit_classtoolkit_class) class YourTaxonomyGraph(TaxonomyAgent[TaxonomyAgentState, TaxonomyAgentState[MaxToolTaxonomyOutput]]): def __init__(self, team: Team, user: User, tool_call_id: str): super().__init__( team, user, tool_call_id, loop_node_classLoopNode, tools_node_classToolsNode, toolkit_classYourToolkit, )第 4 步调用它通常从一个MaxTool中调用graph YourTaxonomyGraph(teamself._team, userself._user) graph_context { change: Show me recordings of users in Germany that used a mobile device while performing a payment, output: None, tool_progress_messages: [], **self.context, } result await graph.compile_full_graph().ainvoke(graph_context) # Currently we support Pydantic objects or str as an output type if isinstance(result[output], MaxToolTaxonomyOutput): content ✅ Updated taxonomy selection payload result[output] else: content ❌ Need more info to proceed payload MaxToolTaxonomyOutput.model_validate(result[output])8.2 真实案例会话录制筛选products/replay/backend/max_tools.pyproducts/replay/backend/max_tools.py是一个把 Taxonomy Agent 接入MaxTool的完整生产范例max_tools.pySessionReplayFilterOptionsToolkit覆写_get_custom_tools返回类型化final_answer[MaxRecordingUniversalFilters]并覆写_format_properties用 YAML 输出属性SessionReplayFilterNode在默认系统提示词前叠加PRODUCT_DESCRIPTION_PROMPT、SESSION_REPLAY_EXAMPLES_PROMPT、FILTER_FIELDS_TAXONOMY_PROMPT、DATE_FIELDS_PROMPT等产品专属 promptSessionReplayFilterOptionsGraph将上述节点与 toolkit 绑定为完整 graphSearchSessionRecordingsTool(MaxTool)的_arun_impl调用_invoke_graph把用户请求change与当前筛选器 JSON 组装成 user prompt调用graph.compile_full_graph().ainvoke(graph_context)若输出不是MaxRecordingUniversalFilters实例则回退使用最近一次工具调用的输入并结合当前筛选器做model_validate。该工具同时声明资源级权限[(session_recording, viewer)]并定义了context_prompt_template把当前筛选器与会话 ID 注入根节点形成前端 context → 根节点决策 → 子 graph 执行 → 结构化输出回填 UI的完整闭环。九、总结从ee/hogai/README.md及其对应的源码实现可以看到PostHog AI 的扩展面清晰收敛为三条主线MaxTool以后端 Python 类 前端 React 挂载的双端契约为核心配合AssistantTool枚举、TOOL_DEFINITIONS元数据、资源级/对象级访问控制与危险操作审批把任何产品能力封装为 AI Agent 可调用、可解释、可审计的工具查询类型扩展通过AssistantQueryExecutor 格式化器 示例 prompt 的三件套让 AI 读懂任意新的分析查询结果含失败回退 JSON 的健壮性设计Taxonomy Agent以TaxonomyAgent/TaxonomyAgentNode/TaxonomyAgentToolsNode/TaxonomyAgentToolkit为骨架的 agentic RAG 小智能体可快速接入 MaxTool实现对团队分类体系的结构化问答。无论是为自有产品添加让 Max 帮你干活的能力还是为会话录制、仪表盘、SQL 等既有工具调优提示词与权限本文的代码范式与源码路径都可直接作为开发起点并配合本地http://localhost:8010/ai-observability/traces做全链路 trace 调试。【免费下载链接】posthog:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.项目地址: https://gitcode.com/GitHub_Trending/po/posthog创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表