Langfuse launches AI Gateway Learn more
DocsMessages

Messages

The Messages tab of a trace shows its trace messages: the system, user, assistant, and tool messages its LLM calls received and returned, each listed once. Messages contain text, tool calls and results, reasoning, and files. Evaluators that run on a whole trace read the same messages.

Messages tab of a trace showing a collapsed system prompt, the user's question, reasoning, three tool calls, and the assistant's answer with a table

Messages are organized in threads, each a single sequence of messages. Most traces have one thread. Traces with sub-agents, guardrails, or parallel LLM calls can have several; see multi-threaded applications.

How messages are built

Only generation observations create messages. tool observations attach their result to the matching tool call.

Most applications resend the earlier messages with every LLM call. Langfuse shows each message once: from each generation's input, it adds only the messages not shown yet, then it adds the generation's output.

Generation 1  input:   User: Refund order 123.
              output:  Assistant: [calls refund_order]
Tool          output:  Refund succeeded.
Generation 2  input:   User: Refund order 123.
                       Assistant: [calls refund_order]
                       Tool: Refund succeeded.
              output:  Assistant: Your refund is on its way.

Messages:     User: Refund order 123.
              Assistant: [calls refund_order]
              Tool: Refund succeeded.
              Assistant: Your refund is on its way.

A message that repeats on purpose, such as a user writing "Thanks" twice, stays. A system prompt that stays the same shows only once, and a changed system prompt shows as a new system message.

Supported message formats

Langfuse reads messages from generation input and output in these formats. The Formatted view of an observation's input and output uses the same formats.

FormatCovers
OpenAIChat Completions and Responses APIs, and OpenAI-compatible APIs
AnthropicMessages API
GoogleGemini and Vertex AI
LangChainLangChain and LangGraph messages
Vercel AI SDKAI SDK prompts and responses
OpenTelemetry GenAIGenAI semantic conventions, including Microsoft Agent Framework spans
Pydantic AIPydantic AI message history
Semantic KernelSemantic Kernel GenAI events
agno and koogAgno and koog agent messages
Langfuse agent pluginsMessages from Langfuse plugins for coding agents

Providers without their own format, such as Amazon Bedrock, Mistral, and Cohere, are read by generic detection.

Langfuse detects formats by the shape of the payload, not by a provider label, so payloads that mix formats still work. The first format that recognizes the messages reads them. If none does, a string becomes a text message, and other values are kept as structured data.

Normalized messages

Every format becomes the same list of messages, each with a role and a list of parts. For example, this generation in the OpenAI format:

{
  "input": [{ "role": "user", "content": "What is 2 + 2?" }],
  "output": { "role": "assistant", "content": "4" }
}

becomes:

[
  { "role": "user", "parts": [{ "type": "text", "text": "What is 2 + 2?" }] },
  { "role": "assistant", "parts": [{ "type": "text", "text": "4" }] }
]

Roles are system, user, assistant, or tool. Part types are text, reasoning, tool-call, tool-result, and file, with data and custom for content no format maps.

OpenTelemetry attributes

During OpenTelemetry ingestion, Langfuse maps common message attributes to the observation's input and output, for example:

  • langfuse.observation.input and langfuse.observation.output, which take precedence over all others
  • gen_ai.input.messages and gen_ai.output.messages
  • gen_ai.prompt.* and gen_ai.completion.*
  • llm.input_messages.* and llm.output_messages.*
  • ai.prompt.messages from the Vercel AI SDK

See attribute mapping for the other observation attributes.

Multi-threaded applications

A trace has several threads when its LLM calls don't share message history, for example a guardrail check, sub-agents, or parallel calls.

Messages of a trip-planner trace with three labeled threads: 1.1 is a guardrail call, 1.2 is the main agent, and an arrow points from 1.2 to 1.3, the nested sub-agent it spawned. Nested threads such as 1.3 are hidden behind Show by default.

These rules decide which thread a generation joins and which threads you see:

  • A generation continues the newest thread whose messages its input repeats. Otherwise, it starts a new thread. A generation whose input drops earlier messages, for example after context compaction, also starts a new thread.
  • The Messages tab shows the threads at the shallowest nesting level of the trace tree. Deeper threads, such as a sub-agent's, are behind N nested threads hidden. Click Show to see them.
  • Threads are ordered by when they started and numbered 1.1, 1.2, and so on. The numbers count only the visible threads. Evaluators read all threads in that order, including nested ones, so the first thread can be a guardrail or sub-agent rather than the main agent's thread.

No messages

If the Messages tab is empty or incomplete, or trace evaluations skip a trace, check these causes. See Why does my trace have no messages? for details.

CauseFix
No generation observationsLog each LLM call as a generation
Generation input and output are emptySet them on the generation, not on a parent span
More than 1,000 generation and tool observations, or messages over 1 million characters in totalSplit the work into smaller traces

GitHub Discussions


Was this page helpful?

Last updated on