Open
Conversation
- Team-aware Turn lifecycle: defer emission while team is active - Agent grouping spans with shutdown_response sentinel - check_team_dedup protocol for lead/teammate dedup - New hooks: TeammateIdle, TaskCompleted (11 total) - parse_transcript replaces per-line jq loops (O(N) → O(1)) - Uppercase OpenInference span kinds, rename subagent.* → agent.* - Performance: batched state reads, del_states, get_or_set_state Co-Authored-By: Claude Opus 4.6 (1M context) <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.
Add agent team tracing support
parse_transcriptpipeline with requestId-based dedupTeammateIdleandTaskCompleted(11 hooks total)What changed
Team-aware Turn lifecycle (stop.sh, common.sh, user_prompt_submit.sh, session_end.sh)
stop.shdefers the Turn span instead of emitting it.close_active_turn()incommon.shhandles emission when the next prompt arrives or the session ends.last_trace_id/last_trace_span_idare preserved after Turn emission so late-arriving teammate hooks (SubagentStop, TaskCompleted) can find their parent trace.Agent grouping spans (post_tool_use.sh, subagent_stop.sh)
post_tool_use.shlazy-inits an AGENT grouping span peragent_idand re-parents tool spans under it. Handles TeamCreate/TeamDelete detection, shutdown_response grouping, and a race fix that preemptively marks agents active on Agent/SendMessage calls.subagent_stop.shreuses the pre-created grouping span when the agent used tools, or creates one if it didn't. Teammate vs subagent distinction for span naming and start-time estimation. Transcript offset tracking avoids re-parsing for teammates with multiple work periods.agent_<id>_shutdown_complete) prevents duplicate grouping spans between the two hooks.Team dedup (common.sh)
check_team_dedup(): teammate marks first, lead checks and skips. Prevents duplicate spans when both fire for the same event. Used in post_tool_use and task_completed.New hooks
teammate_idle.sh— Cachesteam_namein session state (no span emitted)task_completed.sh— Emits CHAIN span with task metadata, team context, and dedupplugin.json— Registers both hooks, updates description to 11 hooksToken counting rewrite (common.sh, stop.sh, subagent_stop.sh)
parse_transcript()replaces per-line while loops with a singlejq -rscpipeline (O(N) jq invocations → O(1))requestId— only the final cumulative count per group is usedcache_read_input_tokensandcache_creation_input_tokensin totalsSpan kind / attribute corrections (breaking)
"tool"→"TOOL","chain"→"CHAIN","LLM"→"AGENT"subagent.id→agent.id,subagent.type→agent.nameagent.role(lead/teammate/subagent) andteam.nameto all span typesspan_kindfrom attributes instead of hardcoding"CHAIN"doubleValuePerformance improvements
get_timestamp_ms: triesdate +%s%3N→perl -MTime::HiRes→python3→date +%s000 (avoids python3 on most systems)generate_trace_id/generate_span_idhelpers replace repeated inline pipelinespost_tool_use.sh(single jq call for 8+ fields)del_states()replaces sequential del_state callsget_or_set_state()atomic check-then-set in one lockinit_stateidempotency guardsend_spanaccepts span name to skip jq parse for loggingget_state/del_state/inc_stateuse--arginstead of string interpolationOther changes
build_spanJSON-escapes span names (handles quotes, backslashes, tabs)session_start.shhard-resets state file to prevent stale statenotification.shfiltersidle_promptnotificationsjq -n→jq -ncacross all hooksBreaking changes
Existing Arize/Phoenix dashboards that filter on
openinference.span.kindvalues ("tool","chain","LLM") orsubagent.*attributes will need to be updated to the new uppercase/renamed values.Test plan
TeammateIdlecaches team_name without emitting a spanTaskCompletedemits a CHAIN span with correct parentspan_kindreflects actual span kind (TOOL, AGENT, CHAIN) not hardcoded CHAINARIZE_DRY_RUN=trueprints correct span structure🤖 Generated with Claude Code