Skip to content

Conversation

@JetoPistola
Copy link
Contributor

@JetoPistola JetoPistola commented Nov 13, 2025

Details

This PR adds a boolean field has_tool_spans to the Trace model to indicate whether a trace contains at least one span of type 'tool'. This enables the thread view to display a visual indicator (tool icon) when tool calls are present in a trace.

Backend Changes:

  • Added hasToolSpans boolean field to the Trace record with appropriate JSON annotations
  • Added HAS_TOOL_SPANS to the TraceField enum for field management
  • Implemented ClickHouse aggregation using countIf(s.type = 'tool') > 0 in TraceDAO queries
  • Added field to SQL SELECT templates with exclude support
  • Added row mapping logic with default value of false

Frontend Changes:

  • Added has_tool_spans?: boolean to the Trace interface
  • Updated TraceMessage component to display tool icon when has_tool_spans is true
  • Imported and positioned BaseTraceDataTypeIcon with SPAN_TYPE.tool
  • Tool icon appears at -left-6 position relative to message bubbles

The implementation follows the same pattern as llmSpanCount, ensuring consistency with existing span count calculations.

Change checklist

  • User facing
  • Documentation update

Issues

Testing

  • ✅ Backend compilation passed
  • ✅ Frontend TypeScript type checking passed
  • ✅ Frontend linting passed
  • Manual testing: Tool icon displays in thread view when traces contain tool-type spans

Documentation

  • No documentation changes required (backend API field is auto-documented via OpenAPI schema)
  • Field follows established pattern similar to llm_span_count

Added boolean field to indicate whether a trace contains at least one span of type 'tool':
- Backend: Added hasToolSpans field to Trace record with ClickHouse aggregation
- Backend: Calculate has_tool_spans using countIf(s.type = 'tool') > 0 in TraceDAO
- Frontend: Updated Trace interface with has_tool_spans boolean field
- Frontend: TraceMessage component now checks has_tool_spans to display tool icon

Implements OPIK-2470: Show tool calls in thread view
Copilot AI review requested due to automatic review settings November 13, 2025 14:28
@JetoPistola JetoPistola requested a review from a team as a code owner November 13, 2025 14:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a has_tool_spans boolean field to traces to enable visual indicators (tool icons) in the thread view UI when a trace contains spans of type 'tool'. The implementation follows the same pattern as the existing llm_span_count field.

Key Changes:

  • Backend aggregation using ClickHouse to compute whether a trace has any tool-type spans
  • Frontend interface and UI updates to display tool icons when the field is true

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
apps/opik-backend/src/main/java/com/comet/opik/api/Trace.java Added hasToolSpans boolean field to Trace record and HAS_TOOL_SPANS to TraceField enum
apps/opik-backend/src/main/java/com/comet/opik/domain/TraceDAO.java Implemented ClickHouse aggregation logic, SQL template exclusion support, and row mapping with default false value
apps/opik-frontend/src/types/traces.ts Added optional has_tool_spans boolean field to Trace interface
apps/opik-frontend/src/components/pages-shared/traces/TraceMessages/TraceMessage.tsx Displays tool icon at -left-6 position for both input/output message bubbles when has_tool_spans is true

Comment on lines +83 to +87
{trace.has_tool_spans && (
<div className="absolute -left-6 top-2">
<BaseTraceDataTypeIcon type={SPAN_TYPE.tool} />
</div>
)}
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tool icon rendering logic is duplicated for both input and output message bubbles (lines 83-87 and 93-97). Consider extracting this into a reusable component or constant to avoid duplication and make future updates easier.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Contributor

Backend Tests Results

  286 files    286 suites   42m 9s ⏱️
5 446 tests 5 171 ✅ 7 💤 267 ❌ 1 🔥
4 377 runs  4 102 ✅ 7 💤 267 ❌ 1 🔥

For more details on these failures and errors, see this check.

Results for commit 6b5e750.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants