Pull subagent identity from a parent's tool_result record. Claude Code writes a ``toolUseResult`` dict on the user-side record that closes out an Agent/Task tool invocation. It carries ``agentId`` (matching the subagent jsonl's records) and ``agentType`` (the human-readable type suc
(record)
| 261 | |
| 262 | |
| 263 | def extract_agent_dispatch(record): |
| 264 | """Pull subagent identity from a parent's tool_result record. |
| 265 | |
| 266 | Claude Code writes a ``toolUseResult`` dict on the user-side record that |
| 267 | closes out an Agent/Task tool invocation. It carries ``agentId`` (matching |
| 268 | the subagent jsonl's records) and ``agentType`` (the human-readable type |
| 269 | such as 'general-purpose' or 'Explore') plus aggregate stats. |
| 270 | """ |
| 271 | if record.get("type") != "user": |
| 272 | return None |
| 273 | tur = record.get("toolUseResult") |
| 274 | if not isinstance(tur, dict): |
| 275 | return None |
| 276 | agent_id = tur.get("agentId") |
| 277 | agent_type = tur.get("agentType") |
| 278 | if not agent_id or not agent_type: |
| 279 | return None |
| 280 | return { |
| 281 | "agent_id": agent_id, |
| 282 | "agent_type": agent_type, |
| 283 | "dispatched_in_session": record.get("sessionId"), |
| 284 | "completed_at": record.get("timestamp", ""), |
| 285 | "status": tur.get("status"), |
| 286 | "total_tokens": tur.get("totalTokens"), |
| 287 | "total_duration_ms": tur.get("totalDurationMs"), |
| 288 | "tool_use_count": tur.get("totalToolUseCount"), |
| 289 | } |
| 290 | |
| 291 | |
| 292 | def upsert_agents(conn, agents): |
no outgoing calls
no test coverage detected