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
30 changes: 28 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,39 @@ 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)
event_dict = {
"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
original_events = getattr(drift_detector, "original_events", [])
while next_index < len(original_events) and original_events[next_index].get("event_type") != "decision":
next_index += 1
self._drift_compare_index = next_index
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