Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ public final class ToolCallingObservationContext extends Observation.Context {
private String toolCallResult;

private ToolCallingObservationContext(ToolDefinition toolDefinition, ToolMetadata toolMetadata,
String toolCallArguments, @Nullable String toolCallResult) {
@Nullable String toolCallArguments, @Nullable String toolCallResult) {
Assert.notNull(toolDefinition, "toolDefinition cannot be null");
Assert.notNull(toolMetadata, "toolMetadata cannot be null");
Assert.hasText(toolCallArguments, "toolCallArguments cannot be null or empty");

this.toolDefinition = toolDefinition;
this.toolMetadata = toolMetadata;
this.toolCallArguments = toolCallArguments;
this.toolCallArguments = toolCallArguments != null ? toolCallArguments : "{}";
this.toolCallResult = toolCallResult;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,30 @@ class ToolCallingObservationContextTests {

@Test
void whenMandatoryRequestOptionsThenReturn() {
var observationContext = ToolCallingObservationContext.builder()
.toolDefinition(ToolDefinition.builder().name("toolA").description("description").inputSchema("{}").build())
.build();
assertThat(observationContext).isNotNull();
}

@Test
void whenToolArgumentsIsNullThenReturn() {
var observationContext = ToolCallingObservationContext.builder()
.toolDefinition(ToolDefinition.builder().name("toolA").description("description").inputSchema("{}").build())
.toolCallArguments(null)
.build();
assertThat(observationContext).isNotNull();
assertThat(observationContext.getToolCallArguments()).isEqualTo("{}");
}

@Test
void whenToolArgumentsIsNotNullThenReturn() {
var observationContext = ToolCallingObservationContext.builder()
.toolDefinition(ToolDefinition.builder().name("toolA").description("description").inputSchema("{}").build())
.toolCallArguments("lizard")
.build();
assertThat(observationContext).isNotNull();
assertThat(observationContext.getToolCallArguments()).isEqualTo("lizard");
}

@Test
Expand All @@ -55,22 +74,4 @@ void whenToolMetadataIsNullThenThrow() {
.build()).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("toolMetadata cannot be null");
}

@Test
void whenToolCallInputIsNullThenThrow() {
assertThatThrownBy(() -> ToolCallingObservationContext.builder()
.toolDefinition(ToolDefinition.builder().name("toolA").description("description").inputSchema("{}").build())
.toolCallArguments(null)
.build()).isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("toolCallArguments cannot be null or empty");
}

@Test
void whenToolCallInputIsEmptyThenThrow() {
assertThatThrownBy(() -> ToolCallingObservationContext.builder()
.toolDefinition(ToolDefinition.builder().name("toolA").description("description").inputSchema("{}").build())
.toolCallArguments("")
.build()).isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("toolCallArguments cannot be null or empty");
}

}