middleware.tracing¶
Correlated turn tracing built from LangChain callback events.
Attributes¶
Classes¶
Normalized trace event captured from LangChain callbacks. |
|
Correlated view of one tool invocation within a model turn. |
|
Correlated trace artifact for one Research Agent turn. |
|
Append-only bounded trace buffer. |
|
Collect LangChain lifecycle callbacks into a trace sink. |
|
Correlate raw trace events into turn-level trace artifacts. |
Functions¶
|
Recursively coerce trace-related values into JSON-serializable data. |
|
Return one turn as a plain, JSON-friendly mapping. |
|
Build a versioned transcript document from correlated turns. |
Module Contents¶
- class middleware.tracing.TraceEvent¶
Normalized trace event captured from LangChain callbacks.
- payload: collections.abc.Mapping[str, Any]¶
- class middleware.tracing.TurnTraceToolCall¶
Correlated view of one tool invocation within a model turn.
- requested_arguments: Any = None¶
- result: Any = None¶
- tool_message: collections.abc.Mapping[str, Any] | None = None¶
- class middleware.tracing.TurnTrace¶
Correlated trace artifact for one Research Agent turn.
- input_summary: tuple[collections.abc.Mapping[str, Any], Ellipsis] = ()¶
- final_content: Any = None¶
- requested_tool_calls: tuple[collections.abc.Mapping[str, Any], Ellipsis] = ()¶
- invalid_tool_calls: tuple[collections.abc.Mapping[str, Any], Ellipsis] = ()¶
- tool_invocations: tuple[TurnTraceToolCall, Ellipsis] = ()¶
- response_metadata: collections.abc.Mapping[str, Any]¶
- class middleware.tracing.TraceSink(max_events: int = 500)¶
Append-only bounded trace buffer.
- append(event: TraceEvent) None¶
Append one normalized callback event.
- snapshot() tuple[TraceEvent, Ellipsis]¶
Return a copy of the buffered events in insertion order.
- class middleware.tracing.TraceRecorder(sink: TraceSink)¶
Bases:
langchain_core.callbacks.BaseCallbackHandlerCollect LangChain lifecycle callbacks into a trace sink.
- raise_error = False¶
Whether to raise an error if an exception occurs.
- sink¶
- on_chat_model_start(serialized: dict[str, Any], messages: list[list[Any]], *, run_id: uuid.UUID, parent_run_id: uuid.UUID | None = None, tags: list[str] | None = None, metadata: dict[str, Any] | None = None, **kwargs: Any) Any¶
Record the start of a chat model run with summarized input messages.
- on_llm_new_token(token: str | list[str | dict[str, Any]], *, chunk: Any = None, run_id: uuid.UUID, parent_run_id: uuid.UUID | None = None, tags: list[str] | None = None, **kwargs: Any) Any¶
Record streamed tokens and any tool-call chunks from the model.
- on_llm_end(response: Any, *, run_id: uuid.UUID, parent_run_id: uuid.UUID | None = None, tags: list[str] | None = None, **kwargs: Any) Any¶
Record the final model message, tool calls, and response metadata.
- on_tool_start(serialized: dict[str, Any], input_str: str, *, run_id: uuid.UUID, parent_run_id: uuid.UUID | None = None, tags: list[str] | None = None, metadata: dict[str, Any] | None = None, inputs: dict[str, Any] | None = None, **kwargs: Any) Any¶
Record the start of a tool invocation.
- class middleware.tracing.TurnTracer¶
Correlate raw trace events into turn-level trace artifacts.
- snapshot(events: collections.abc.Iterable[TraceEvent]) tuple[TurnTrace, Ellipsis]¶
Fold raw trace events into correlated per-turn artifacts.
- middleware.tracing.TURN_TRACE_TRANSCRIPT_FORMAT = 'turn_trace_transcript'¶
- middleware.tracing.TURN_TRACE_TRANSCRIPT_VERSION = 1¶
- middleware.tracing.normalize_trace_json_value(value: Any) Any¶
Recursively coerce trace-related values into JSON-serializable data.
- middleware.tracing.turn_trace_to_jsonable(turn: TurnTrace) dict[str, Any]¶
Return one turn as a plain, JSON-friendly mapping.
- middleware.tracing.turn_traces_to_json_document(turns: collections.abc.Iterable[TurnTrace]) dict[str, Any]¶
Build a versioned transcript document from correlated turns.