-
Notifications
You must be signed in to change notification settings - Fork 710
feat(extension): support tool schema for completions chat api #508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
LearningGp
merged 64 commits into
agentscope-ai:main
from
Alexxigang:feat/tool-schema-support
Mar 4, 2026
Merged
Changes from 61 commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
86c97fd
feat: support tool schema for completions chat api
Alexxigang d369c91
style: format code
Alexxigang 15b9a7b
Merge branch 'main' into feat/tool-schema-support
Alexxigang c037f7f
fix: fix tool accumulate
Alexxigang a6b9a4a
fix(core): enable custom config for mcpclientbuilder (#509)
Alexxigang 2004772
chore(deps): bump org.postgresql:postgresql from 42.7.4 to 42.7.8 (#567)
dependabot[bot] 036c919
chore(deps): bump com.aliyun:bailian20231229 from 2.6.2 to 2.7.0 (#566)
dependabot[bot] 8da5b1e
fix: Fix the observability of the callTool pipeline. (#576)
fangxiu-wf 02cc98f
chore(deps-dev): bump com.google.genai:google-genai from 1.34.0 to 1.…
dependabot[bot] 7222c9d
chore(deps): bump org.postgresql:postgresql from 42.7.8 to 42.7.9 (#580)
dependabot[bot] 908b805
chore(deps): bump org.springframework:spring-webflux from 7.0.2 to 7.…
dependabot[bot] 782cc2e
chore(deps): bump com.aliyun:bailian20231229 from 2.7.0 to 2.7.1 (#582)
dependabot[bot] ae88f1f
fix(example): Inconsistent groupManager in ReActAgent.Builder#build d…
fishl3j cfadc9d
feat(hook): add summary phase hook support for ReActAgent (#577)
AlbumenJ 4665f8c
feat: support websocket transport (#557)
AlbumenJ 766bae5
feat: support metadata recording and filtering for Mem0 (#563)
xuanmiss c3c1038
fix(a2a): prevent a2a SDK SPI loading issues caused by delayed thread…
LearningGp fc754d5
chore(deps): bump com.aliyun:bailian20231229 from 2.7.1 to 2.7.2 (#594)
dependabot[bot] 77c06dc
chore(deps): bump ch.qos.logback:logback-classic from 1.5.24 to 1.5.2…
dependabot[bot] aee6bfe
chore(deps): bump redis.clients:jedis from 7.2.0 to 7.2.1 (#597)
dependabot[bot] 10e9a07
chore(deps): bump io.opentelemetry.instrumentation:opentelemetry-reac…
dependabot[bot] 86dc1be
chore(deps): bump com.fasterxml.jackson:jackson-bom from 2.20.1 to 2.…
dependabot[bot] 928f1ba
chore(dependency): Exclude lombok to compatible with jdk25 (#604)
guanxuc 2de5c66
fix(a2a): jakarta.servlet.http.HttpServletRequest is not compatible w…
jouzi5 1f8fd79
chore(deps): bump com.alibaba:dashscope-sdk-java from 2.22.5 to 2.22.…
dependabot[bot] 0761c65
feat: Elasticsearch RAG Storage (#503)
ShenJunkun 7fff15e
feat(model): Support response_format for dashscope model (#564)
guanxuc ff3abab
feat: Support LLM thinking mode output in AG-UI (#574)
karsonto b278ece
fix(core):Add the correct reason for the stop agent behavior (#606)
feelshana 2f7d122
chore(deps): bump io.milvus:milvus-sdk-java from 2.6.12 to 2.6.13 (#622)
dependabot[bot] e3670f6
chore(deps): bump lodash-es from 4.17.21 to 4.17.23 in /agentscope-ex…
dependabot[bot] a3462fd
fix(werewolf): update vote message metadata structure (#625)
LearningGp d792df5
fix(tool): prevent pipe buffer deadlock in ShellCommandTool (#619)
fang-tech 3b2130d
chore(deps): bump lodash from 4.17.21 to 4.17.23 in /agentscope-examp…
dependabot[bot] da6bd15
refactor(skill): simplify skill lifecycle and improve tool group acti…
fang-tech 4a1c094
feat(skill): Add code execution capabilities to SkillBox (#614)
fang-tech 015d727
fix(agui): Fix duplicate TextMessageEnd emission (#562) (#586)
fishl3j 397c98b
chore(deps): bump mcp-sdk.version from 0.17.0 to 0.17.2 (#634)
dependabot[bot] b1eb9a0
chore(deps): bump com.aliyun:bailian20231229 from 2.7.2 to 2.8.0 (#635)
dependabot[bot] fe7677b
chore(deps): bump org.springframework.boot:spring-boot-dependencies f…
dependabot[bot] c01796a
chore(deps): bump org.springframework.boot:spring-boot-autoconfigure …
dependabot[bot] 7386592
chore(deps-dev): bump com.google.genai:google-genai from 1.35.0 to 1.…
dependabot[bot] dfe2ff4
chore(deps-dev): bump com.openai:openai-java from 4.15.0 to 4.16.0 (#…
dependabot[bot] b9fe56f
feat: add Qwen tts model support. (#541)
flystar32 e84d7dd
feat(skill): refactor code execution API with builder pattern (#646)
fang-tech 21a8812
fix: empty content in ToolCalls (#643)
AlbumenJ 66fa860
fix(ollama): handle no-parameter tool calls with empty arguments (#572)
JGoP-L fb85a6e
fix(ReActAgent): When ReactAgent resumes, it only executes tools that…
wuji1428 5dbf390
Merge branch 'main' into feat/tool-schema-support
Alexxigang 2b581da
fix: fix for cr
Alexxigang 1e28570
Merge branch 'main' into feat/tool-schema-support
Alexxigang e3e9e33
revert(test): remove unnecessary test method from ReasoningContextTest
Alexxigang ea3bbd8
refactor(core): revert ReasoningContext to main version and improve c…
Alexxigang a30d128
Merge branch 'main' into feat/tool-schema-support
Alexxigang acb9132
Merge branch 'main' into feat/tool-schema-support
Alexxigang e799b81
Merge branch 'main' into feat/tool-schema-support
Alexxigang 2c88c95
Merge branch 'main' into feat/tool-schema-support
Alexxigang 6480631
style: fix spotless format violations
Alexxigang d3beaf5
feat(extension): support tool schema for completions chat api
Alexxigang 8655136
Merge branch 'main' into feat/tool-schema-support
Alexxigang b6cff84
Merge branch 'main' into feat/tool-schema-support
Alexxigang cfbe7d0
fix(test): correct version in McpClientBuilderTest to match project v…
Alexxigang 8e64653
fix(streaming): align finish_reason logic with non-streaming path
Alexxigang e78f6d5
Merge branch 'main' into feat/tool-schema-support
LearningGp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
...-web/src/main/java/io/agentscope/core/chat/completions/converter/OpenAIToolConverter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| /* | ||
| * Copyright 2024-2026 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * You may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.agentscope.core.chat.completions.converter; | ||
|
|
||
| import io.agentscope.core.chat.completions.model.OpenAITool; | ||
| import io.agentscope.core.chat.completions.model.OpenAIToolFunction; | ||
| import io.agentscope.core.model.ToolSchema; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * Converter for converting OpenAI tool format to AgentScope ToolSchema. | ||
| * | ||
| * <p>This converter handles the transformation from OpenAI's tool format (used in Chat Completions | ||
| * API requests) to AgentScope's internal ToolSchema format. Tools converted by this converter are | ||
| * intended to be registered as schema-only tools, which will trigger tool suspension when called. | ||
| */ | ||
| public class OpenAIToolConverter { | ||
|
|
||
| private static final Logger log = LoggerFactory.getLogger(OpenAIToolConverter.class); | ||
|
|
||
| /** | ||
| * Converts a list of OpenAI tools to AgentScope ToolSchemas. | ||
| * | ||
| * <p>Only tools with type "function" are converted. Other tool types are skipped with a warning. | ||
| * | ||
| * @param tools The list of OpenAI tools to convert (may be null or empty) | ||
| * @return A list of converted ToolSchema objects; returns an empty list if input is null or | ||
| * empty | ||
| */ | ||
| public List<ToolSchema> convertToToolSchemas(List<OpenAITool> tools) { | ||
| if (tools == null || tools.isEmpty()) { | ||
| return List.of(); | ||
| } | ||
|
|
||
| List<ToolSchema> schemas = new ArrayList<>(); | ||
|
|
||
| for (OpenAITool tool : tools) { | ||
| if (tool == null) { | ||
| log.warn("Skipping null tool in conversion"); | ||
| continue; | ||
| } | ||
|
|
||
| // Only support function type tools for now | ||
| if (!"function".equals(tool.getType())) { | ||
| log.warn( | ||
| "Skipping tool with unsupported type: {}. Only 'function' type is" | ||
| + " supported", | ||
| tool.getType()); | ||
| continue; | ||
| } | ||
|
|
||
| OpenAIToolFunction function = tool.getFunction(); | ||
| if (function == null) { | ||
| log.warn("Skipping tool with null function definition"); | ||
| continue; | ||
| } | ||
|
|
||
| String name = function.getName(); | ||
| String description = function.getDescription(); | ||
| Map<String, Object> parameters = function.getParameters(); | ||
|
|
||
| // Validate required fields | ||
| if (name == null || name.isBlank()) { | ||
| log.warn("Skipping tool with null or empty name"); | ||
| continue; | ||
| } | ||
|
|
||
| if (description == null || description.isBlank()) { | ||
| log.warn("Skipping tool '{}' with null or empty description", name); | ||
| // Use empty string as fallback for description | ||
| description = ""; | ||
| } | ||
|
|
||
| try { | ||
| ToolSchema.Builder schemaBuilder = | ||
| ToolSchema.builder().name(name).description(description); | ||
|
|
||
| if (parameters != null) { | ||
| schemaBuilder.parameters(parameters); | ||
| } | ||
|
|
||
| if (function.getStrict() != null) { | ||
| schemaBuilder.strict(function.getStrict()); | ||
| } | ||
|
|
||
| ToolSchema schema = schemaBuilder.build(); | ||
| schemas.add(schema); | ||
| log.debug("Converted OpenAI tool to ToolSchema: {}", name); | ||
|
|
||
| } catch (Exception e) { | ||
| log.error("Failed to convert tool '{}' to ToolSchema: {}", name, e.getMessage(), e); | ||
| } | ||
| } | ||
|
|
||
| return schemas; | ||
| } | ||
|
|
||
| /** | ||
| * Converts a single OpenAI tool to a ToolSchema. | ||
| * | ||
| * @param tool The OpenAI tool to convert | ||
| * @return The converted ToolSchema, or null if conversion fails | ||
| */ | ||
| public ToolSchema convertToToolSchema(OpenAITool tool) { | ||
| if (tool == null) { | ||
| return null; | ||
| } | ||
|
|
||
| List<ToolSchema> schemas = convertToToolSchemas(List.of(tool)); | ||
| return schemas.isEmpty() ? null : schemas.get(0); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.