MCPcopy
hub / github.com/phuryn/claude-usage / extract_agent_dispatch

Function extract_agent_dispatch

scanner.py:263–289  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

261
262
263def 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
292def upsert_agents(conn, agents):

Callers 2

parse_jsonl_fileFunction · 0.85
scanFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected