Skip to content

feat(telemetry): record tool definitions on the llm_node span - #6621

Open
biztex wants to merge 2 commits into
livekit:mainfrom
biztex:feat/llm-span-tool-definitions
Open

feat(telemetry): record tool definitions on the llm_node span#6621
biztex wants to merge 2 commits into
livekit:mainfrom
biztex:feat/llm-span-tool-definitions

Conversation

@biztex

@biztex biztex commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #6620

Problem

The llm_node span records the full chat context (lk.chat_ctx) but only the names of function tools (lk.function_tools). Tool descriptions and parameter schemas never reach OTel backends (Langfuse, Jaeger, ...), so a trace cannot show what the LLM was actually offered on a turn — a badly-worded tool description or a schema mismatch is invisible when tracing back a conversation that went wrong. Reported by a user in the community Slack running Langfuse via set_tracer_provider.

Change

Adds lk.function_tool_definitions to the llm_node span: a JSON attribute carrying each tool's name, description, and parameters schema — the same shape providers receive (build_legacy_openai_schema(..., internally_tagged=True) for function tools, raw_schema for raw tools).

  • lk.function_tools (names) is unchanged, for backward compatibility with anything keying on it.
  • Telemetry can never break generation: a tool whose schema fails to build is recorded by name only.

Tests

New hermetic tests/test_llm_span_tool_definitions.py (unit-marked): definition shape for decorated and raw tools, JSON round-trip, and an end-to-end span assertion driving perform_llm_inference with a fake LLM node against an in-memory span exporter (the global tracer provider is restored afterwards).

The llm_node span records the full chat context but only the names of function
tools (lk.function_tools). Tool descriptions and parameter schemas never reach
OTel backends, so a trace cannot show what the LLM was actually offered on a
turn - a badly-worded tool description or a schema mismatch is invisible when
tracing back a conversation that went wrong.

Add lk.function_tool_definitions: a JSON attribute with each tool's name,
description and parameters schema - the same shape providers receive
(build_legacy_openai_schema for function tools, raw_schema for raw tools).
lk.function_tools stays unchanged for backward compatibility, and a tool whose
schema fails to build falls back to name-only so telemetry can never break
generation.

Fixes livekit#6620
@biztex
biztex requested a review from a team as a code owner July 30, 2026 15:20
devin-ai-integration[bot]

This comment was marked as resolved.

The per-tool guard covered schema building but json.dumps ran outside it, so
a tool definition carrying a non-JSON value could abort the model turn for
the sake of optional debugging data. Serialize with default=str and fall back
to the name list if serialization still fails; the span attribute degrades,
generation never breaks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telemetry: llm_node span records tool names only - descriptions/schemas never reach Langfuse/OTel backends

1 participant