posthog icon indicating copy to clipboard operation
posthog copied to clipboard

feat(ph-ai): subagent tool

Open kappa90 opened this issue 1 month ago • 8 comments

Problem

This PR adds a new "subagent" tool that allows the chat agent to delegate independent tasks to autonomous subagents that run in parallel.

Changes

  • Added a new SubagentTool that can be used to delegate tasks to autonomous subagents
  • Created a new Temporal workflow SubagentWorkflow for processing subagent activities
  • Implemented Redis stream handling for subagent communication
  • Added feature flag control via has_subagent_tool_feature_flag
  • Updated the frontend to support and display subagent tool calls

How did you test this code?

Locally + tests coming soon

Changelog: (features only) Is this feature complete?

Could be in the changelog

kappa90 avatar Nov 25 '25 13:11 kappa90

This stack of pull requests is managed by Graphite. Learn more about stacking.

kappa90 avatar Nov 25 '25 13:11 kappa90

Wiz Scan Summary

Scanner Findings
Vulnerability Finding Vulnerabilities -
Data Finding Sensitive Data 1 Info
Secret Finding Secrets -
IaC Misconfiguration IaC Misconfigurations -
SAST Finding SAST Findings -
Total 1 Info

View scan details in Wiz

To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension.

wiz-7ad640923b[bot] avatar Nov 25 '25 13:11 wiz-7ad640923b[bot]

Size Change: +27 B (0%)

Total Size: 3.7 MB

ℹ️ View Unchanged
Filename Size Change
frontend/dist/toolbar.js 3.7 MB +27 B (0%)

compressed-size-action

github-actions[bot] avatar Nov 25 '25 16:11 github-actions[bot]

I made these updates:

  • We now pass a SubagentType to the subagent workflow, right now it's fixed to GENERAL_PURPOSE but for example I'll have a read-only subagent for research
  • Added a SubagentUpdateEvent which streams a subagent tool call
  • If it's a subagent, the checkpointer is set to False, and we don't track chat with ai
  • No new conversation for subagents, it's the same from the parent, this simplifies the read_data:artifacts PR I did on top of this one
  • Subagents have a new prompt 😉 😉

kappa90 avatar Nov 26 '25 16:11 kappa90

Main fixes:

  • New subagent tool prompt
  • new workflow for all chat agents
  • workflow can determine an agent type, which registers certain modes and mode registries
  • you can pass use_checkpointer to the workflow to turn on/off the checkpointer

kappa90 avatar Dec 02 '25 20:12 kappa90

Query snapshots: Backend query snapshots updated

Changes: 1 snapshots (1 modified, 0 added, 0 deleted)

What this means:

  • Query snapshots have been automatically updated to match current output
  • These changes reflect modifications to database queries or schema

Next steps:

  • Review the query changes to ensure they're intentional
  • If unexpected, investigate what caused the query to change

Review snapshot changes →

posthog-bot avatar Dec 06 '25 00:12 posthog-bot

Visual regression: Storybook UI snapshots updated

Changes: 6 snapshots (6 modified, 0 added, 0 deleted)

What this means:

  • Snapshots have been automatically updated to match current rendering
  • Next CI run will switch to CHECK mode to verify stability
  • If snapshots change again, CHECK mode will fail (indicates flapping)

Next steps:

  • Review the changes to ensure they're intentional
  • Approve if changes match your expectations
  • If unexpected, investigate component rendering

Review snapshot changes →

posthog-bot avatar Dec 06 '25 15:12 posthog-bot

Edits:

  • Subagent tool is now called task, the prompt has been improved accordingly
  • Task tool accepts agent modes as parameters
  • Fixed a problem with running parallel subagent, they would go in a deadlock due to the memory nodes being sync, fixed in this PR: https://github.com/PostHog/posthog/pull/42888
  • You can now set a parent_span_id on a chat agent workflow, that will then track traces as a span rather than as a new trace, through a modified CallbackHandler, needed for the subagent flow
  • Cancelling a workflow now cancels all subagent workflows
  • Artifacts from subagents are not added to the stream, but rather summarized in the tool call result

kappa90 avatar Dec 06 '25 20:12 kappa90

🔍 Migration Risk Analysis

We've analyzed your migrations for potential risks.

Summary: 1 Safe | 0 Needs Review | 0 Blocked

✅ Safe

Brief or no lock, backwards compatible

ee.0036_add_is_internal_to_conversation
  └─ #1 ✅ AddField
     Adding nullable field requires brief lock
     model: conversation, field: is_internal

📚 How to Deploy These Changes Safely

AddField:

This operation acquires a brief lock but doesn't rewrite the table.

Deployment uses lock timeouts with automatic retries, so lock contention will cause retries rather than connection pile-up.

Last updated: 2025-12-12 17:04 UTC (eed44ee)

github-actions[bot] avatar Dec 12 '25 16:12 github-actions[bot]

Merge activity

  • Dec 12, 5:33 PM UTC: @kappa90 merged this pull request with Graphite.

kappa90 avatar Dec 12 '25 17:12 kappa90