Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .changeset/mastra-thread-view-llm-io.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"braintrust": patch
---

fix(mastra): Transform LLM input/output for the Braintrust Thread view

The model-generation spans from the Mastra observability exporter
(`model_generation`, `model_step`, `model_chunk`) now log input as a bare
chat-message array (unwrapping Mastra's `{ messages: [...] }` container, or
wrapping a single `{ role, content }` object) and output as an
`{ role: 'assistant', content }` message (unwrapping Mastra's `{ text, ... }`),
so Braintrust's Thread view renders the conversation correctly. All three map to
the `llm` span type and are surfaced together in Thread view, so they share the
transform; the app's dedup coalesces them into one turn. Embedding (`rag_embedding`)
and non-model spans are unchanged.

Ports mastra-ai/mastra#10794 (fixes #9848).
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,26 @@
"type": "task"
},
{
"input": {
"messages": [
{
"content": "Answer weather questions with the provided mock forecast.",
"role": "system"
},
{
"content": [
{
"providerOptions": {
"mastra": {
"createdAt": 0
}
},
"text": "What is the weather in Paris?",
"type": "text"
}
],
"role": "user"
}
]
},
"input": [
{
"content": "Answer weather questions with the provided mock forecast.",
"role": "system"
},
{
"content": [
{
"providerOptions": {
"mastra": {
"createdAt": 0
}
},
"text": "What is the weather in Paris?",
"type": "text"
}
],
"role": "user"
}
],
"metadata": {
"entity_id": "weather-agent",
"entity_name": "Weather Agent",
Expand All @@ -67,10 +65,11 @@
],
"name": "llm: 'mock-model-id'",
"output": {
"content": "The forecast is sunny.",
"files": [],
"reasoning": [],
"role": "assistant",
"sources": [],
"text": "The forecast is sunny.",
"warnings": []
},
"type": "llm"
Expand All @@ -89,7 +88,8 @@
],
"name": "step: 0",
"output": {
"text": "The forecast is sunny.",
"content": "The forecast is sunny.",
"role": "assistant",
"toolCalls": []
},
"type": "llm"
Expand All @@ -103,7 +103,8 @@
"metric_keys": [],
"name": "chunk: 'text'",
"output": {
"text": "The forecast is sunny."
"content": "The forecast is sunny.",
"role": "assistant"
},
"type": "llm"
},
Expand Down Expand Up @@ -131,28 +132,26 @@
"type": "task"
},
{
"input": {
"messages": [
{
"content": "Answer weather questions with the provided mock forecast.",
"role": "system"
},
{
"content": [
{
"providerOptions": {
"mastra": {
"createdAt": 0
}
},
"text": "Stream the Paris forecast.",
"type": "text"
}
],
"role": "user"
}
]
},
"input": [
{
"content": "Answer weather questions with the provided mock forecast.",
"role": "system"
},
{
"content": [
{
"providerOptions": {
"mastra": {
"createdAt": 0
}
},
"text": "Stream the Paris forecast.",
"type": "text"
}
],
"role": "user"
}
],
"metadata": {
"entity_id": "weather-agent",
"entity_name": "Weather Agent",
Expand All @@ -167,10 +166,11 @@
],
"name": "llm: 'mock-model-id'",
"output": {
"content": "The forecast is sunny.",
"files": [],
"reasoning": [],
"role": "assistant",
"sources": [],
"text": "The forecast is sunny.",
"warnings": []
},
"type": "llm"
Expand All @@ -189,7 +189,8 @@
],
"name": "step: 0",
"output": {
"text": "The forecast is sunny.",
"content": "The forecast is sunny.",
"role": "assistant",
"toolCalls": []
},
"type": "llm"
Expand All @@ -203,7 +204,8 @@
"metric_keys": [],
"name": "chunk: 'text'",
"output": {
"text": "The forecast is sunny."
"content": "The forecast is sunny.",
"role": "assistant"
},
"type": "llm"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"type": "llm",
"children": [],
"output": {
"text": "The forecast is sunny."
"content": "The forecast is sunny.",
"role": "assistant"
},
"metadata": {
"entity_id": "weather-agent",
Expand All @@ -34,7 +35,8 @@
}
],
"output": {
"text": "The forecast is sunny.",
"content": "The forecast is sunny.",
"role": "assistant",
"toolCalls": []
},
"metadata": {
Expand All @@ -49,33 +51,32 @@
]
}
],
"input": {
"messages": [
{
"content": "Answer weather questions with the provided mock forecast.",
"role": "system"
},
{
"content": [
{
"providerOptions": {
"mastra": {
"createdAt": 0
}
},
"text": "What is the weather in Paris?",
"type": "text"
}
],
"role": "user"
}
]
},
"input": [
{
"content": "Answer weather questions with the provided mock forecast.",
"role": "system"
},
{
"content": [
{
"providerOptions": {
"mastra": {
"createdAt": 0
}
},
"text": "What is the weather in Paris?",
"type": "text"
}
],
"role": "user"
}
],
"output": {
"content": "The forecast is sunny.",
"files": [],
"reasoning": [],
"role": "assistant",
"sources": [],
"text": "The forecast is sunny.",
"warnings": []
},
"metadata": {
Expand Down Expand Up @@ -120,7 +121,8 @@
"type": "llm",
"children": [],
"output": {
"text": "The forecast is sunny."
"content": "The forecast is sunny.",
"role": "assistant"
},
"metadata": {
"entity_id": "weather-agent",
Expand All @@ -130,7 +132,8 @@
}
],
"output": {
"text": "The forecast is sunny.",
"content": "The forecast is sunny.",
"role": "assistant",
"toolCalls": []
},
"metadata": {
Expand All @@ -145,33 +148,32 @@
]
}
],
"input": {
"messages": [
{
"content": "Answer weather questions with the provided mock forecast.",
"role": "system"
},
{
"content": [
{
"providerOptions": {
"mastra": {
"createdAt": 0
}
},
"text": "Stream the Paris forecast.",
"type": "text"
}
],
"role": "user"
}
]
},
"input": [
{
"content": "Answer weather questions with the provided mock forecast.",
"role": "system"
},
{
"content": [
{
"providerOptions": {
"mastra": {
"createdAt": 0
}
},
"text": "Stream the Paris forecast.",
"type": "text"
}
],
"role": "user"
}
],
"output": {
"content": "The forecast is sunny.",
"files": [],
"reasoning": [],
"role": "assistant",
"sources": [],
"text": "The forecast is sunny.",
"warnings": []
},
"metadata": {
Expand Down
Loading
Loading