feat(hook): trace Task subagents into the same Langfuse session#16
Open
LeonardoDaviti wants to merge 1 commit into
Open
feat(hook): trace Task subagents into the same Langfuse session#16LeonardoDaviti wants to merge 1 commit into
LeonardoDaviti wants to merge 1 commit into
Conversation
Subagents spawned via the Task tool run in isolated sub-sessions with their own transcripts under <session>/subagents/agent-*.jsonl. The hook only parsed the parent transcript, so all subagent model calls, tool use and cost were dropped — only the orchestrator model appeared and session cost was undercounted. Sweep the subagents/ directory on Stop/SessionEnd and feed each subagent transcript through the existing incremental pipeline (read_new_jsonl -> build_turns -> emit_turn), emitting it as a separate trace in the same session, linked to the spawning Task tool_use via `parent_tool_use_id` metadata and `subagent` / `agent:<type>` / `parent_tool:<id>` tags. Idempotent via per-file offset state; recurses for nested subagents (spawnDepth > 1). emit_turn gains optional trace_name/root_name/extra_tags/extra_metadata so subagent traces reuse the same emission logic. main() no longer early-returns when the parent transcript has no new rows, so subagents are still swept. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Subagents spawned via the Task tool run in isolated sub-sessions with their own transcripts under /subagents/agent-*.jsonl. The hook only parsed the parent transcript, so all subagent model calls, tool use and cost were dropped — only the orchestrator model appeared and session cost was undercounted.
Sweep the subagents/ directory on Stop/SessionEnd and feed each subagent transcript through the existing incremental pipeline (read_new_jsonl -> build_turns -> emit_turn), emitting it as a separate trace in the same session, linked to the spawning Task tool_use via
parent_tool_use_idmetadata andsubagent/agent:<type>/parent_tool:<id>tags. Idempotent via per-file offset state; recurses for nested subagents (spawnDepth > 1).emit_turn gains optional trace_name/root_name/extra_tags/extra_metadata so subagent traces reuse the same emission logic. main() no longer early-returns when the parent transcript has no new rows, so subagents are still swept.