Docs
SDKs
Trace

Trace

A Trace object is used to log conversational data to the Weavel server.

Methods

log_message

ParameterTypeOptionalDescription
typestringnoThe role of message.
contentstringnoThe message content.
trace_data_idstringyesThe message(trace_data) identifier
timestampdatetimeyesThe timestamp.
unit_namestringyesThe unit name.
metadataDict[str, Any]yesThe metadata to be added.

Example Usage

trace.log_message("system", "you are a helpful assistant.")
 
trace.log_message("assistant", res, unit_name="test_assistant")
 
trace.log_message("user", user_message)

log_message method of Trace object is used to log messages to the Weavel server.
You can log system messages, assistant messages, and user messages.

Adding Metadata

trace.log_message(
    "assistant",
    assistant_message,
    metadata={
        "module": "planning_module",
        "model": "gpt-4o",
        "document_types": "medical",
        "function_call": "search_document"
    }
)

Including metadata is recommended if there is additional information about the AI's response.
This metadata will be automatically analyzed and visualized on the Weavel platform.
For example, you can add metadata about the AI model name, retrieved document types, used module or functions to generate the response, etc.

You can also add identifier of message by using trace_data_id parameter, if you want to update the metadata of the message later.

log_inner_step

ParameterTypeOptionalDescription
contentstringnoThe message content.
timestampdatetimeyesThe timestamp.
unit_namestringyesThe unit name.
metadataDict[str, Any]yesThe metadata to be added.

You can log inner steps of a trace, other than messages, by using the log_inner_step method.
For example, you can log the retrieved data of a RAG step before logging the generated assistant message.