8181from .models import (
8282 EvaluateJsRequest ,
8383 EvaluateJsResult ,
84+ LLMStepData ,
8485 Snapshot ,
8586 SnapshotOptions ,
8687 TabInfo ,
@@ -792,9 +793,26 @@ async def emit_step_end(
792793 verify_signals : dict [str , Any ] | None = None ,
793794 post_url : str | None = None ,
794795 post_snapshot_digest : str | None = None ,
796+ llm_data : dict [str , Any ] | LLMStepData | None = None ,
795797 ) -> dict [str , Any ]:
796798 """
797799 Emit a step_end event using TraceEventBuilder.
800+
801+ Args:
802+ action: Action name/type executed in this step
803+ success: Whether the action execution succeeded
804+ error: Error message if action failed
805+ outcome: Outcome description of the action
806+ duration_ms: Duration of action execution in milliseconds
807+ attempt: Attempt number (0-based)
808+ verify_passed: Whether verification passed
809+ verify_signals: Additional verification signals
810+ post_url: URL after action execution
811+ post_snapshot_digest: Digest of post-action snapshot
812+ llm_data: LLM interaction data for this step. Can be:
813+ - LLMStepData: Structured model with response_text, response_hash, usage, model
814+ - dict: Raw dict with response_text, response_hash, usage keys
815+ - None: No LLM data (defaults to empty dict)
798816 """
799817 goal = self ._step_goal or ""
800818 pre_snap = self ._step_pre_snapshot or self .last_snapshot
@@ -850,6 +868,15 @@ async def emit_step_end(
850868 "signals" : signals ,
851869 }
852870
871+ # Convert LLMStepData to dict if needed
872+ llm_data_dict : dict [str , Any ]
873+ if llm_data is None :
874+ llm_data_dict = {}
875+ elif isinstance (llm_data , LLMStepData ):
876+ llm_data_dict = llm_data .to_trace_dict ()
877+ else :
878+ llm_data_dict = llm_data
879+
853880 step_end_data = TraceEventBuilder .build_step_end_event (
854881 step_id = self .step_id or "" ,
855882 step_index = int (self .step_index ),
@@ -858,7 +885,7 @@ async def emit_step_end(
858885 pre_url = str (pre_url or "" ),
859886 post_url = str (post_url or "" ),
860887 snapshot_digest = pre_digest ,
861- llm_data = {} ,
888+ llm_data = llm_data_dict ,
862889 exec_data = exec_data ,
863890 verify_data = verify_data ,
864891 pre_elements = None ,
0 commit comments