-
[OPIK-5745] [BE] feat: add LLM tools for full trace context in eval suite assertions (#6511)
发布于
2026-05-08 12:16:08 +00:00 - [OPIK-5745] [BE] feat: add LLM tools for full trace context in eval suite assertions
Eval suite assertions can now inspect sub-span behavior (tool calls, LLM model,
intermediate steps) via two on-demand LLM tools: get_trace_spans and
get_span_details. Tools are only offered when experimentId is present (test suite
assertions); regular online scoring is unchanged.Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
- [OPIK-5745] [BE] refactor: improve system prompt tool usage guidelines for eval suite assertions
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
- fix: preserve ChatRequest parameters when adding tool specs
Removing .parameters(null) from addToolSpecs() — it was stripping
maxCompletionTokens which Anthropic requires, causing
"maxCompletionTokens cannot be null" errors for Claude models.Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
- [OPIK-5745] [BE] fix: address PR review - use InstructionStrategy for assertions, fix ChatRequest builder conflict
- Force InstructionStrategy for test suite assertions so format instructions
survive responseFormat stripping when adding tool specs - Fix "Cannot set both parameters and toolSpecifications" by building fresh
ChatRequest instead of using toBuilder() - Guard handleToolCalls with experimentId != null check
- Use constants for tool names in system prompt
- Reduce tool call logging to debug level
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
- [OPIK-5745][BE] Refactored trace span tools and introduced modular execution framework.
- Removed
TraceSpanToolDefinitionand transitioned to a modular setup for LLM-as-judge tools. - Introduced
ToolRegistry,ToolExecutorinterface, and dedicated tool implementations (GetTraceSpansTool,GetSpanDetailsTool,ReadTool) for improved extensibility and maintainability. - Added infrastructure for tool execution contexts (
TraceToolContext) and entity compression (GenericCompressor,PathAwareTruncator,Tokens, etc.). - Refined logic for trace/span serialization with truncation markers and jq path annotations.
- Updated core application wiring and tests to support the new tool-based architecture.
- [OPIK-5745][BE] Introduced test coverage and input validation for LLM-as-Judge scoring.
- Added
OnlineScoringLlmAsJudgeScorerTestto validate tool-enabled scoring logic and regression guard for structured requests. - Introduced
OnlineScoringEngineCapReplacementsTestto test variable substitution with input capping logic. - Enhanced
OnlineScoringEnginewith a capped variable substitution path for large trace inputs, improving token efficiency and leveraging tool-based retrieval for full data.
- [OPIK-5745][BE] Add JqTool for evaluating jq expressions on cached entities.
- Introduced
JqToolto execute jq expressions on cached JSON entities (e.g., spans, traces, datasets) usingjackson-jq. - Registered
JqToolinToolsModuleand updatedTestSuitePromptConstantsto include usage guidance. - Implemented argument validation, output capping, and error handling for malformed or runtime errors in expressions.
- Added comprehensive unit tests for
JqToolto validate spec adherence, expression handling, and caching behavior. - Updated
pom.xmlto includejackson-jqdependency.
- [OPIK-5745][BE] Add SearchTool for regex-based searches in cached entities.
- Implemented
SearchToolto perform case-insensitive regex searches on cached JSON entities (e.g., spans, traces). - Registered
SearchToolinToolsModuleandTestSuitePromptConstantswith detailed usage guidance. - Added argument parsing, output capping at 50 matches, value truncation, and robust error handling for malformed inputs.
- Developed comprehensive unit tests covering pattern matching, path scoping, and edge cases.
- Introduced functionality to return matched paths and truncated values for follow-up extraction with
JqTool.
- [OPIK-5745][BE] Introduce
shouldUseToolsutility to centralize tool path enablement logic.
- Replaced repetitive
experimentIdchecks withshouldUseToolsfor improved code readability and maintainability. - Added JavaDoc to clarify tool path scope and future extensibility.
- Updated
OnlineScoringLlmAsJudgeScorerto leverage the utility in tool-specific conditions.
- [OPIK-5745][BE] Add builder pattern to
CompressionResultand refactor compressors.
- Annotated
CompressionResultwith@Builderto enable builder pattern and immutability. - Refactored
GenericCompressor,TraceCompressor, andDatasetCompressorto useCompressionResult.builder()for object instantiation.
- [OPIK-5745][BE] Extract and centralize span hierarchy logic into
SpanHierarchy.
- Consolidated span tree-building logic from
SpanTreeSerializerandTraceCompressorinto a sharedSpanHierarchyutility for reusability and consistency. - Added unit tests in
SpanHierarchyTestto validate root promotion, child attachment, and edge cases. - Refactored
SpanTreeSerializerandTraceCompressorto leverageSpanHierarchy.toTreefor span tree generation.
- [OPIK-5745][BE] Add sticky cache truncation warnings and downgrade tier for capped entries.
- Modified
ReadToolto persistcache_warningon subsequent reads of previously truncated entities. - Updated
applyCacheCapto handlerefandctx, marking truncated entries for consistent behavior. - Introduced
effectiveTierto downgrade compression tier toMEDIUMwhencache_warningis present. - Extended
TraceToolContextwith tracking for capped entries (markTruncated,isTruncated). - Added unit tests to validate persistent warnings and tier downgrades for capped entities.
- [OPIK-5745][BE] Enhance truncation logic with configurable suffix styles.
- Introduced
PathAwareTruncator.SuffixStyleto supportWITH_JQ_HINTandBAREoptions for truncation markers. - Updated
GenericCompressorandTraceCompressorto accept custom suffix styles for truncated output. - Modified
ReadToolto dynamically select suffix styles based on cache state, ensuring consistent output for capped entries. - Extended unit tests to validate behavior with both suffix styles and scenarios involving cache capping.
- Refactored and documented truncation logic to clarify suffix behaviors and usage contexts.
- [OPIK-5745][BE] Improve cache capping with fallback thresholds and enhanced truncation logic.
- Added multi-tier fallback thresholds (
CAP_FALLBACK_LIMITS) to gracefully handle oversized cached entities. - Replaced fixed truncation with dynamic fallback logic in
fitWithinCapto prioritize caching highest-fidelity data within memory limits. - Simplified redundant cache pre-checks to ensure consistent behavior when updating cached entries.
- Extended unit tests to validate multi-tier fallback scenarios and ensure capped entities respect
CACHE_CAP_CHARS.
- [OPIK-5745][BE] Remove thread support and improve validation in tools.
- Removed
type=threadsupport inJqTool,SearchTool, andReadTooldue to unsupported caching. - Enhanced error messages for invalid thread-type usage and updated argument validation.
- Fixed logging messages for clarity and consistency.
- Updated
ReadToolTestto reflect thread rejection with improved error text.
- [OPIK-5745][BE] Extract shared argument handling and cache utilities to
ToolArgs.
- Moved common argument parsing and cache utilities from
JqTool,SearchTool, andReadToolto a newToolArgsutility class for reusability and consistency. - Removed redundant methods like
textOrNull,errorJson, andcapWithHintfrom individual tools and replaced them with centralized counterparts inToolArgs. - Updated tools to leverage
ToolArgsfor cleaner and more maintainable code. - Simplified unit tests by aligning with shared utility behaviors.
- [OPIK-5745][BE] Add
withToolssupport to test suite prompts and scoring logic.
- Introduced
withToolsflag to conditionally include tool-teaching addendum in system prompts. - Refactored
TestSuitePromptConstantswith methods to handle dynamic prompt generation. - Updated
EvaluatorMapper,TestSuiteAssertionSampler, and scorers to propagatewithToolsconfiguration. - Added
LlmAsJudgeToolsModeutility to centralize tool path enablement logic. - Ensured consistent application of tool-teaching logic across test suite evaluation flows.
- [OPIK-5745][BE] Centralize truncation logic and enhance tooling support.
- Extracted shared truncation logic into a new utility class
TruncationMarkerfor consistency across the codebase. - Updated
OnlineScoringEngine,PathAwareTruncator, and related tools to useTruncationMarkerfor unified string truncations. - Improved logging and error handling in
ReadToolwith correlation IDs for secure debugging. - Applied builder pattern to
ParsedArgsandCacheOutcomefor cleaner object construction and immutability. - Refactored suffix-handling logic in
PathAwareTruncatorfor modularity.
- [OPIK-5745][BE] Rename
TruncationMarkertoStringTruncatorand refactor truncation logic.
- Renamed
TruncationMarkertoStringTruncatorfor clearer intent and consistency. - Refactored shared truncation methods (
applytotruncate) for improved readability and usage. - Updated
SpanTreeSerializer,DatasetCompressor, and related tools to useStringTruncator.truncatefor centralization. - Removed redundant local truncation implementations in favor of the utility method.
- [OPIK-5745][BE] Improve exception logging in
ReadTooldeserialization.
- Updated
log.warnto include full exception details when deserialization fails for better debugging.
- [OPIK-5745][BE] Replace per-tool truncation with centralized
StringTruncator.
- Updated
JqToolandSearchToolto useStringTruncator.truncatefor string truncation. - Removed
capWithHintfromToolArgsin favor of centralized truncation logic. - Added a new
separatoroption toStringTruncator.truncatefor improved flexibility.
- [OPIK-5745][BE] Add debug logging for tool execution and cache behavior.
- Enhanced debugging in
JqTool,SearchTool,ReadTool, andGetTraceSpansToolwith detailed logs for valid arguments, cache misses, and entity truncation. - Added
@Slf4jannotation toGetTraceSpansToolto support logging.
- [OPIK-5745][BE] Add detailed debug logging for tool execution summaries.
- Enhanced
JqTool,SearchTool, andReadToolwith additional debug logs to capture key execution details. - Logged arguments, output size, truncation status, and other relevant summary metrics for improved traceability.
- [OPIK-5745][BE] Refactor
OnlineScoringLlmAsJudgeScorerto enforce structured LLM outputs.
- Introduced explicit strategy to force JSON-only responses after tool usage.
- Added
UserMessageto clarify response expectations and prevent prose in final output. - Improved handling of tool-driven and structured LLM requests for consistency.
- [OPIK-5745][BE] Enhance workspace name resolution and update prompt path conventions.
- Added
resolveWorkspaceNamemethod toOnlineScoringLlmAsJudgeScorerfor workspace name lookup with fallback behavior. - Updated
TestSuitePromptConstantswith detailed path conventions for tool usage and jq expressions.
-
[OPIK-5745][BE] Prioritize Anthropic for tool-driven LLM judge assertions; update fallback provider and documentation.
-
[OPIK-5745][BE] Update judge provider ordering rationale and enhance debug logging.
- Refined
SupportedJudgeProviderordering explanation with additional empirical details and caveats. - Added detailed debug logs in
GetTraceSpansToolto capture trace ID, span count, and output size for improved logging granularity.
- [OPIK-5745][BE] Force initial tool engagement for OpenAI judges; adjust fallback behavior.
- Updated
addToolSpecsto useToolChoice.REQUIREDon the first call, ensuring at least one tool interaction for OpenAI judges with tool-loop bias. - Refined follow-up behavior with
ToolChoice.AUTOto allow models to decide when to stop investigating. - Enhanced test coverage to verify tool engagement and output propagation under forced and automatic modes.
- Updated rationale in
SupportedJudgeProvidercomments to reflect empirical results and fallback adjustments.
-
[OPIK-5745][BE] Update model usage to GPT-4O-MINI and refine logging for LLM requests and responses.
-
[OPIK-5745][BE] Refine logging for debug and user-facing messages.
- Updated debug logging in
GetTraceSpansToolandReadToolto improve clarity and uniformity. - Guarded
userFacingLoggerinvocations inOnlineScoringLlmAsJudgeScorerwithisInfoEnabledto prevent unnecessary computation for deferred logging.
-
[OPIK-5745][BE] Update log assertions in
AutomationRuleEvaluatorsResourceTestto validate both refactored and legacy log formats. -
[OPIK-5745][BE] Enforce safe jq path expressions in
SearchTooland add corresponding test coverage.
- Introduced regex validation to restrict
pathto simple jq scope expressions. - Updated
ParsedArgsto reject unsafepathinputs. - Added tests to validate safe and unsafe
pathbehaviors.
- [OPIK-5745][BE] Handle tool execution exceptions gracefully; propagate fatal errors.
- Updated
ToolRegistryto return error JSON for exceptions while allowing fatal errors to propagate. - Added tests to verify behavior for runtime exceptions and fatal errors.
- [OPIK-5745][BE] Refine debug logging in
ReadToolfor capped entity size.
- Replaced inline
toString().length()with a variable for improved clarity in log statements.
- [OPIK-5745][BE] Decouple truncation warnings from capping logic in
ReadTool.
- Separated truncation flag handling from size-based capping decisions to ensure independence.
- Updated cache warning behavior to surface only when truncation is flagged.
- [OPIK-5745][BE] Extract common header generation logic into
headerPrefixinSearchTool.
- Refactored
successHeaderanderrorHeaderto share a commonheaderPrefixmethod for consistent header construction.
- [OPIK-5745][BE] Add tests to validate
handleToolCallsbehavior for failure propagation and max round handling.
- Verified error propagation for transient failures without masking issues.
- Ensured max round cap triggers final structured call with proper contract adherence.
- [OPIK-5745][BE] Avoid field loss regression in
addToolSpecsby switching totoBuilder.
- Replaced the manual builder with
toBuilderto ensure all top-level fields inChatRequestare preserved. - Prevents silent field omissions in
addToolSpecsduring tool specification updates.
- [OPIK-5745][BE] Refactor error JSON generation in
ToolRegistry.
- Replaced inline formatted strings with
ToolArgs.errorJsonfor consistency and maintainability in error responses.
Co-authored-by: Claude Opus 4.6 noreply@anthropic.com
Co-authored-by: Iaroslav Omelianenko yaric_mail@yahoo.com下载附件