Skip to content
Merged
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
2 changes: 2 additions & 0 deletions docs/advanced/spi.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Every service delegates HTTP communication to an abstract `RestClient`. The conc
| `FoundationModelService` | `FoundationModelRestClient` |
| `ToolService` | `ToolRestClient` |
| `DeploymentService` | `DeploymentRestClient` |
| `FileService` | `FileRestClient` |
| `BatchService` | `BatchRestClient` |

Each `RestClient` performs the lookup this way:

Expand Down
4 changes: 2 additions & 2 deletions docs/services/chat-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ ChatService chatService = ChatService.builder()

### Advanced Configuration

You can configure **default parameters** and **tools** that will automatically apply to every chat request created by this `ChatService` instance. These defaults simplify reuse and ensure consistent behavior across multiple calls.
You can configure **default parameters** and **tools** that will automatically apply to every chat request created by a `ChatService` instance. These defaults simplify reuse and ensure consistent behavior across multiple calls.

```java
ChatParameters defaultParameters = ChatParameters.builder()
Expand Down Expand Up @@ -698,7 +698,7 @@ ChatService chatService = ChatService.builder()

// Use only specific tools
ChatService limitedService = ChatService.builder()
.tools(registry.tools("get_weather", "search"))
.tools(registry.tools(WeatherTool.class, SearchTool.class))
.build();
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public Object execute(String toolName, ToolArguments args) {
}

/**
* Returns the schemas of all registered tools.
* Returns all registered tools.
*
* @return a list of tool schemas for all registered tools
*/
Expand All @@ -100,7 +100,7 @@ public List<Tool> tools() {
}

/**
* Returns the schemas of tools matching the specified names.
* Returns the tools that match the specified names.
*
* @param names the tool names to include
* @return a list of tool schemas for the matching tools
Expand All @@ -110,7 +110,7 @@ public List<Tool> tools(String... names) {
}

/**
* Returns the schemas of tools matching the specified names.
* Returns the tools that match the specified names.
* <p>
* If the provided set is {@code null} or empty, all registered tool schemas are returned. Unmatched names are silently ignored.
*
Expand All @@ -126,6 +126,24 @@ public List<Tool> tools(Set<String> names) {
return stream.map(ExecutableTool::schema).toList();
}

/**
* Returns the tools that match the specified tool classes.
*
* @param toolClasses the tool classes to filter by
* @return a list of tool schemas for the matching tools
*/
@SafeVarargs
public final List<Tool> tools(Class<? extends ExecutableTool>... toolClasses) {
Set<Class<? extends ExecutableTool>> classes = Set.of(toolClasses);

var toolNames = tools.values().stream()
.filter(tool -> classes.stream().anyMatch(clazz -> clazz.isAssignableFrom(tool.getClass())))
.map(ExecutableTool::name)
.collect(Collectors.toSet());

return tools(toolNames);
}

/**
* Creates a new builder for constructing a {@link ToolRegistry}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void should_return_the_schema_registered() {

assertEquals(7, toolRegistry.tools().size());
assertEquals(1, toolRegistry.tools(webCrawlerTool.name()).size());
assertEquals(1, toolRegistry.tools(WebCrawlerTool.class).size());
assertEquals(7, toolRegistry.tools(Set.of()).size());
}

Expand Down