Skip to content
Open
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
2 changes: 2 additions & 0 deletions agent_debugger_sdk/core/context/trace_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ async def restore(
ctx._restored_state = restored_state
ctx.replayed_events: list[dict[str, Any]] = []
ctx._drift_detector = None
ctx._drift_events: list[Any] = []
ctx._drift_compare_index = 0
ctx._hook_errors: list[Exception] = []
ctx._restored_target: Any = None

Expand Down
33 changes: 31 additions & 2 deletions agent_debugger_sdk/core/recorders.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ async def record_decision(
self,
reasoning: str,
confidence: float,
evidence: list[dict[str, Any]],
chosen_action: str,
*,
evidence: list[dict[str, Any]] | None = None,
evidence_event_ids: list[str] | None = None,
upstream_event_ids: list[str] | None = None,
alternatives: list[dict[str, Any]] | None = None,
Expand All @@ -114,14 +115,42 @@ async def record_decision(
name=name,
reasoning=reasoning,
confidence=max(0.0, min(1.0, confidence)),
evidence=evidence,
evidence=evidence or [],
evidence_event_ids=evidence_event_ids or [],
alternatives=alternatives or [],
chosen_action=chosen_action,
importance=0.7,
upstream_event_ids=upstream_event_ids or [],
)
await self._emit_event(event)

# Detect drift against the original execution if a detector is active
drift_detector = getattr(self, "_drift_detector", None)
if drift_detector is not None:
drift_index = getattr(self, "_drift_compare_index", 0)
original_events = getattr(drift_detector, "original_events", [])
# Advance to the current decision event before comparing, skipping non-decision events
while drift_index < len(original_events) and original_events[drift_index].get("event_type") != "decision":
drift_index += 1
event_dict = {
Comment on lines +127 to +135

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Acknowledged. The SDK behavior changes (evidence keyword-only + drift detection in record_decision) are prerequisites for the tests to exercise correctly — the tests validate this runtime behavior. The PR description has been noted; if desired, the title can be updated to reflect the dual scope (runtime fix + test coverage).

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

PR title and description updated to reflect the dual scope: the SDK behavior changes (keyword-only evidence, drift detection in record_decision, drift state init on restore()) are now called out explicitly alongside the unit tests.

"event_type": "decision",
"data": {
"chosen_action": chosen_action,
"action": chosen_action,
"confidence": event.confidence,
},
}
drift = drift_detector.compare(event_dict, drift_index)
# Advance to the next decision event in the baseline, skipping non-decision events
next_index = drift_index + 1
while next_index < len(original_events) and original_events[next_index].get("event_type") != "decision":
next_index += 1
self._drift_compare_index = next_index
Comment on lines +130 to +148

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in acdacd5. Before calling compare(), we now advance drift_index forward past any non-decision events in original_events. This ensures the comparison always targets an actual decision event position, preventing silent missed drift when non-decision events appear before the first (or any subsequent) decision in the baseline.

if drift is not None:
drift_events_list = getattr(self, "_drift_events", None)
if drift_events_list is not None:
drift_events_list.append(drift)

return event.id

async def record_tool_call(
Expand Down
Loading