Skip to content

fix(hook): trace subagents launched by subagents - #102

Merged
hassiebp merged 1 commit into
langfuse:mainfrom
pushkar:fix/nested-subagent-tracing
Oct 6, 2026
Merged

hassiebp merged 1 commit into
langfuse:mainfrom
pushkar:fix/nested-subagent-tracing

Conversation

@pushkar

@pushkar pushkar commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Subagents launched by another subagent were never traced. This passes the subagent transcript map down so they nest under the agent that launched them.

Problem

emit_subagent_observations walked an agent's turns with subagent_transcripts_by_tool_use_id=None. An Agent call inside a subagent therefore got a Tool: Agent span but no span of its own: none of its generations or tool calls were emitted, even though its transcript (spawnDepth: 2) is on disk and already in the map.

Fix

  • emit_subagent_observations takes the map and hands it to emit_turn_observations for the agent's turns.
  • Both regular-subagent call sites pass it in: synchronous agents and deferred async ones.
  • Workflow agents are unchanged.

Testing

  • test_nested_subagents_document_current_non_recursive_emission_behavior asserted the gap. It's now test_nested_subagents_emit_inner_agent_under_outer_agent and requires the inner agent's span under the outer agent, with a generation under it. It fails before the fix and passes after.
  • uv run --group dev pytest: 279 passed, also on Python 3.10. ruff check --select F,E9 is clean.
  • Live run against a self-hosted Langfuse: a parent agent that starts a nested agent now traces as Subagent: <inner> ← Subagent: <outer> ← Conversational Turn, including the inner agent's Bash call.

emit_subagent_observations walked an agent's turns with no subagent
transcript map, so an Agent call inside a subagent produced a Tool span
but never the inner agent's own span, generations or tools. Pass the
map through so nested agents nest under their launching agent.
Copilot AI balanced review requested due to automatic review settings October 5, 2026 09:21

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@hassiebp
hassiebp merged commit d7e0882 into langfuse:main Oct 6, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants