Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion agentrace/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ def parse_session(path: Path) -> Session:
continue
btype = block.get("type")
if btype == "tool_use" and block.get("name") in ("Agent", "Task"):
uses[block["id"]] = {"input": block.get("input") or {}, "ts": rec.get("timestamp")}
bid = block.get("id")
if bid:
uses[bid] = {"input": block.get("input") or {}, "ts": rec.get("timestamp")}
elif btype == "tool_result":
tid = block.get("tool_use_id")
if tid:
Expand Down
18 changes: 18 additions & 0 deletions tests/test_agentrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,24 @@ def test_non_agent_tools_are_ignored(tmp_path):
assert parse_session(p).runs == []


def test_tool_use_without_id_is_skipped(tmp_path):
"""A tool_use block missing an id should be skipped rather than crashing with KeyError."""
p = tmp_path / "s.jsonl"
p.write_text(
json.dumps(
{
"message": {
"content": [
{"type": "tool_use", "name": "Agent", "input": {"prompt": "p"}}
]
}
}
)
)
s = parse_session(p)
assert s.runs == []


# --------------------------------------------------------------------------- checks


Expand Down
Loading