Skip to main content
Callback Handler streams to stdout on new llm token.

react_agent.utils.request_logging.LoggingCallbackHandler Objects

View Source Callback Handler that logs all events to a file in JSON format.

LoggingCallbackHandler.__init__

View Source Initialize the callback handler.

LoggingCallbackHandler.on_llm_start

View Source Run when LLM starts running. Arguments:
  • serialized - The serialized LLM.
  • prompts - The prompts to run.
  • **kwargs - Additional keyword arguments.

LoggingCallbackHandler.on_chat_model_start

View Source Run when LLM starts running. Arguments:
  • serialized - The serialized LLM.
  • messages - The messages to run.
  • **kwargs - Additional keyword arguments.

LoggingCallbackHandler.on_llm_end

View Source Run when LLM ends running. Arguments:
  • response - The response from the LLM.
  • **kwargs - Additional keyword arguments.

LoggingCallbackHandler.on_llm_error

View Source Run when LLM errors. Arguments:
  • error - The error that occurred.
  • **kwargs - Additional keyword arguments.

LoggingCallbackHandler.on_chain_start

View Source Run when a chain starts running. Arguments:
  • serialized - The serialized chain.
  • inputs - The inputs to the chain.
  • **kwargs - Additional keyword arguments.

LoggingCallbackHandler.on_chain_end

View Source Run when a chain ends running. Arguments:
  • outputs - The outputs of the chain.
  • **kwargs - Additional keyword arguments.

LoggingCallbackHandler.on_chain_error

View Source Run when chain errors. Arguments:
  • error - The error that occurred.
  • **kwargs - Additional keyword arguments.

LoggingCallbackHandler.on_tool_start

View Source Run when the tool starts running. Arguments:
  • serialized - The serialized tool.
  • input_str - The input string.
  • **kwargs - Additional keyword arguments.

LoggingCallbackHandler.on_agent_action

View Source Run on agent action. Arguments:
  • action - The agent action.
  • **kwargs - Additional keyword arguments.

LoggingCallbackHandler.on_tool_end

View Source Run when tool ends running. Arguments:
  • output - The output of the tool.
  • **kwargs - Additional keyword arguments.

LoggingCallbackHandler.on_tool_error

View Source Run when tool errors. Arguments:
  • error - The error that occurred.
  • **kwargs - Additional keyword arguments.

LoggingCallbackHandler.on_text

View Source Run on an arbitrary text. Arguments:
  • text - The text to print.
  • **kwargs - Additional keyword arguments.

LoggingCallbackHandler.on_agent_finish

View Source Run on the agent end. Arguments:
  • finish - The agent finish.
  • **kwargs - Additional keyword arguments.

react_agent.utils.request_logging.LLMRequestLogger Objects

View Source Logger utility to capture and store detailed HTTP requests and responses to/from LLMs. It creates structured JSON log files containing full request/response headers, bodies, methods, and status codes for analysis and troubleshooting.

LLMRequestLogger.__init__

View Source Initialize the logger, create the log directory, and register a file handler with JSON formatting.

LLMRequestLogger.log_request

View Source Log structured details of an outgoing HTTP request. Arguments:
  • request - The outgoing httpx.Request instance.

LLMRequestLogger.log_response

View Source Log structured details of an incoming HTTP response along with its original request. Arguments:
  • response - The incoming httpx.Response instance.

react_agent.utils.request_logging.LLMRequestLogger.LogRequest Objects

View Source Custom wrapper for httpx.Request that hooks initialization to log request details immediately.

LogRequest.__init__

View Source Initialize the request wrapper and log request method, URL, headers, and body.

react_agent.utils.request_logging.LLMRequestLogger.LogResponse Objects

View Source Custom wrapper for httpx.Response to intercept and optionally log streamed bytes.

LogResponse.iter_bytes

View Source Iterate over response bytes synchronously, yielding each chunk. Yields:
  • bytes - Chunks of the response body.

LogResponse.aiter_bytes

View Source Iterate over response bytes asynchronously, yielding each chunk. Yields:
  • bytes - Chunks of the response body.

react_agent.utils.request_logging.LLMRequestLogger.LogTransport Objects

View Source Custom synchronous HTTP transport wrapper to intercept and wrap responses in LogResponse.

LogTransport.__init__

View Source Initialize the synchronous transport wrapper. Arguments:
  • transport - The underlying httpx.BaseTransport instance to wrap.

LogTransport.handle_request

View Source Synchronously handle an HTTP request and wrap the resulting response in LogResponse. Arguments:
  • request - The outgoing HTTP request.
Returns:
  • httpx.Response - The logged HTTP response.

react_agent.utils.request_logging.LLMRequestLogger.AsyncLogTransport Objects

View Source Custom asynchronous HTTP transport wrapper to intercept and wrap responses in LogResponse.

AsyncLogTransport.__init__

View Source Initialize the asynchronous transport wrapper. Arguments:
  • transport - The underlying httpx.AsyncBaseTransport instance to wrap.

AsyncLogTransport.handle_async_request

View Source Asynchronously handle an HTTP request and wrap the resulting response in LogResponse. Arguments:
  • request - The outgoing HTTP request.
Returns:
  • httpx.Response - The logged HTTP response.