← Back to Pull requests

feat(llmobs): capture hosted tool calls in openai, openai-agents and anthropic #11448

Open
oathead opened this pull request with 384 lines diff across 4 files
View on GitHub
oathead oathead commented on Nov 25, 2026 16:53 UTC
Author

What does this PR do?

Records provider-hosted tool calls on LLM spans as a tool call plus a tool result, matching dd-trace-py (DataDog/dd-trace-py#22103, DataDog/dd-trace-py#22104), including the size bounds added there in review.

  • OpenAI Responses web_search_call, file_search_call and code_interpreter_call items become one assistant message with the call and its result:

  • - web_search: arguments are the allowlisted action keys (type, query, queries, url, pattern); the result is {status, sources: [{url, title?}]}.
    - file_search: arguments {queries}; the result is {status, results: [{file_id, filename, score}]}.
    - code_interpreter: arguments {code, container_id}; the result is {status, outputs}, each logs output capped at 4096 characters.
    - toolId is the item id and the result type is tool_result, as in Python.
  • One helper (getHostedToolMessage in llmobs/plugins/openai/utils.js) serves both the OpenAI plugin and the OpenAI Agents integration, on input and output. agents-core passes a prior search back as {type: 'hosted_tool_call', providerData}, so that wrapper is unwrapped first.

  • Anthropic tool blocks match loosely (includes('tool_use') / includes('tool_result')), as dd-trace-py does, in requests, responses and streams. server_tool_use, web_search_tool_result and web_fetch_tool_result are now recorded. Search results keep url and title, never encrypted_content. Web fetch results keep url, title, retrieved_at and page text capped at 4096 characters; a PDF or other binary source becomes [document omitted: <media type>] instead of base64.
  • Motivation

    Hosted tools run inside the model call, so the app never calls them and no tool span exists. Before this change:

  • the OpenAI plugin turned a web_search_call into an empty assistant message;

  • the OpenAI Agents integration dropped it entirely;

  • the Anthropic plugin dropped server tool blocks.
  • Users could see that a search was billed (web_search_count, #10510), but not what was searched or whether it failed. MLflow and other tools already show these steps.

    Additional Notes

    Tests:

  • New unit specs for the helper (openai-utils.spec.js: allowlist, logs cap at the 4096/4097 boundary) and the Anthropic formatter (anthropic-utils.spec.js: web search, web fetch text cap, PDF marker, fetch error). The new specs fail without the source changes.

  • OpenAI Agents spec, Runner.run non-streaming and streaming, including a second turn that passes the search back as input. 14 passing on agents 0.7.0 and 0.21.0. The 4 new tests fail without the source change.

  • OpenAI and Anthropic plugin specs: 1763 passing, 0 failing, against the existing web search cassettes. The two existing assertions that pinned the old output (an empty message / dropped blocks) were updated.

  • eslint is clean on the changed files.
  • Open points for review:

  • Overlaps the Anthropic part of draft #10233.

  • Suggested label: semver-minor (adds data to LLM spans).
  • 🤖 Generated with Claude Code

    Diff: 384 lines (+288 / -96) across 4 files Reviewer: None requested Review duration: 8054m
    All Vouch review confidence checks passed
    Residual risk 0.33 = Change Risk (0.60) × (1 − Review Confidence (0.44)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.60 · 384 lines diff across 4 files
    0.60
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 10%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.356
    Shallow Review Depth shallow_review_depth
    0.344
    No Reviewer Assigned no_reviewer_assigned
    0.120
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #11448"
    general weight: 0.35
    Reviewers
    None requested
    Assignees
    oathead oathead
    Labels
    risk: low confidence: 44.2% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 60% (MEDIUM) · Higher = larger blast radius
    60%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.2% · Lower = rushed or shallow review
    44.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 33.5% · Safe to merge
    33.5%