Trace Format
The Explorer supports agent traces made up of sequences of events like messages, tool calls and environment outputs. The required format is compatible with the OpenAI chat data structure with function calling support.
This documents shows pseudo-code based class definitions to specify the format more formally, but trace data is expected to be JSON serialized.
Event
role
string
The role of the event, e.g., user
, assistant
, system
or something else.
content
string
The content of the event, e.g., agent reasoning and intermediate results.
tool_calls
list[ToolCall]
A list of tool calls made by the agent in this event.
Examples
Message with Tool Call
Simple Message
ToolCall
id
string
A unique identifier for the tool call.
type
string
The type of the tool call, e.g., function
.
function
Function
The function call made by the agent.
-
name
stringThe name of the function called.
-
arguments
dictThe arguments passed to the function, encoded as a JSON dictionary.
Example
ToolOutput
A special event type for tool outputs, associated with a previous ToolCall
.
role
string
The role of the event, e.g., tool
.
content
string
The content of the tool output, e.g., the result of a function call.
tool_call_id
string
The identifier of a previous ToolCall that this output corresponds to.
Example
Full Trace Example
The format suitable for the Invariant SDK is a list of Event
objects. Here is an example of a trace with a user asking for their inbox, the assistant fetching the inbox, and the assistant listing the inbox contents.
[
{
"role": "user",
"content": "What's in my inbox?"
},
{
"role": "assistant",
"content": "Here are the latest emails.",
"tool_calls": [
{
"id": "1",
"type": "function",
"function": {
"name": "get_inbox",
"arguments": {}
}
}
]
},
{
"role": "tool",
"tool_call_id": "1",
"content": "1. Subject: Hello, From: Alice, Date: 2024-01-0, 2. Subject: Meeting, From: Bob, Date: 2024-01-02"
},
{
"role": "assistant",
"content": "You have 2 new emails."
}
]