Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
86c97fd
feat: support tool schema for completions chat api
Alexxigang Jan 11, 2026
d369c91
style: format code
Alexxigang Jan 11, 2026
15b9a7b
Merge branch 'main' into feat/tool-schema-support
Alexxigang Jan 14, 2026
c037f7f
fix: fix tool accumulate
Alexxigang Jan 25, 2026
a6b9a4a
fix(core): enable custom config for mcpclientbuilder (#509)
Alexxigang Jan 15, 2026
2004772
chore(deps): bump org.postgresql:postgresql from 42.7.4 to 42.7.8 (#567)
dependabot[bot] Jan 15, 2026
036c919
chore(deps): bump com.aliyun:bailian20231229 from 2.6.2 to 2.7.0 (#566)
dependabot[bot] Jan 15, 2026
8da5b1e
fix: Fix the observability of the callTool pipeline. (#576)
fangxiu-wf Jan 15, 2026
02cc98f
chore(deps-dev): bump com.google.genai:google-genai from 1.34.0 to 1.…
dependabot[bot] Jan 16, 2026
7222c9d
chore(deps): bump org.postgresql:postgresql from 42.7.8 to 42.7.9 (#580)
dependabot[bot] Jan 16, 2026
908b805
chore(deps): bump org.springframework:spring-webflux from 7.0.2 to 7.…
dependabot[bot] Jan 16, 2026
782cc2e
chore(deps): bump com.aliyun:bailian20231229 from 2.7.0 to 2.7.1 (#582)
dependabot[bot] Jan 16, 2026
ae88f1f
fix(example): Inconsistent groupManager in ReActAgent.Builder#build d…
fishl3j Jan 16, 2026
cfadc9d
feat(hook): add summary phase hook support for ReActAgent (#577)
AlbumenJ Jan 16, 2026
4665f8c
feat: support websocket transport (#557)
AlbumenJ Jan 16, 2026
766bae5
feat: support metadata recording and filtering for Mem0 (#563)
xuanmiss Jan 16, 2026
c3c1038
fix(a2a): prevent a2a SDK SPI loading issues caused by delayed thread…
LearningGp Jan 19, 2026
fc754d5
chore(deps): bump com.aliyun:bailian20231229 from 2.7.1 to 2.7.2 (#594)
dependabot[bot] Jan 20, 2026
77c06dc
chore(deps): bump ch.qos.logback:logback-classic from 1.5.24 to 1.5.2…
dependabot[bot] Jan 20, 2026
aee6bfe
chore(deps): bump redis.clients:jedis from 7.2.0 to 7.2.1 (#597)
dependabot[bot] Jan 20, 2026
10e9a07
chore(deps): bump io.opentelemetry.instrumentation:opentelemetry-reac…
dependabot[bot] Jan 20, 2026
86dc1be
chore(deps): bump com.fasterxml.jackson:jackson-bom from 2.20.1 to 2.…
dependabot[bot] Jan 20, 2026
928f1ba
chore(dependency): Exclude lombok to compatible with jdk25 (#604)
guanxuc Jan 20, 2026
2de5c66
fix(a2a): jakarta.servlet.http.HttpServletRequest is not compatible w…
B18150228NJUPT Jan 20, 2026
1f8fd79
chore(deps): bump com.alibaba:dashscope-sdk-java from 2.22.5 to 2.22.…
dependabot[bot] Jan 20, 2026
0761c65
feat: Elasticsearch RAG Storage (#503)
ShenJunkun Jan 21, 2026
7fff15e
feat(model): Support response_format for dashscope model (#564)
guanxuc Jan 21, 2026
ff3abab
feat: Support LLM thinking mode output in AG-UI (#574)
karsonto Jan 21, 2026
b278ece
fix(core):Add the correct reason for the stop agent behavior (#606)
feelshana Jan 21, 2026
2f7d122
chore(deps): bump io.milvus:milvus-sdk-java from 2.6.12 to 2.6.13 (#622)
dependabot[bot] Jan 22, 2026
e3670f6
chore(deps): bump lodash-es from 4.17.21 to 4.17.23 in /agentscope-ex…
dependabot[bot] Jan 22, 2026
a3462fd
fix(werewolf): update vote message metadata structure (#625)
LearningGp Jan 22, 2026
d792df5
fix(tool): prevent pipe buffer deadlock in ShellCommandTool (#619)
fang-tech Jan 22, 2026
3b2130d
chore(deps): bump lodash from 4.17.21 to 4.17.23 in /agentscope-examp…
dependabot[bot] Jan 22, 2026
da6bd15
refactor(skill): simplify skill lifecycle and improve tool group acti…
fang-tech Jan 22, 2026
4a1c094
feat(skill): Add code execution capabilities to SkillBox (#614)
fang-tech Jan 22, 2026
015d727
fix(agui): Fix duplicate TextMessageEnd emission (#562) (#586)
fishl3j Jan 22, 2026
397c98b
chore(deps): bump mcp-sdk.version from 0.17.0 to 0.17.2 (#634)
dependabot[bot] Jan 23, 2026
b1eb9a0
chore(deps): bump com.aliyun:bailian20231229 from 2.7.2 to 2.8.0 (#635)
dependabot[bot] Jan 23, 2026
fe7677b
chore(deps): bump org.springframework.boot:spring-boot-dependencies f…
dependabot[bot] Jan 23, 2026
c01796a
chore(deps): bump org.springframework.boot:spring-boot-autoconfigure …
dependabot[bot] Jan 23, 2026
7386592
chore(deps-dev): bump com.google.genai:google-genai from 1.35.0 to 1.…
dependabot[bot] Jan 23, 2026
dfe2ff4
chore(deps-dev): bump com.openai:openai-java from 4.15.0 to 4.16.0 (#…
dependabot[bot] Jan 23, 2026
b9fe56f
feat: add Qwen tts model support. (#541)
flystar32 Jan 23, 2026
e84d7dd
feat(skill): refactor code execution API with builder pattern (#646)
fang-tech Jan 23, 2026
21a8812
fix: empty content in ToolCalls (#643)
AlbumenJ Jan 24, 2026
66fa860
fix(ollama): handle no-parameter tool calls with empty arguments (#572)
JGoP-L Jan 24, 2026
fb85a6e
fix(ReActAgent): When ReactAgent resumes, it only executes tools that…
wuji1428 Jan 24, 2026
5dbf390
Merge branch 'main' into feat/tool-schema-support
Alexxigang Jan 25, 2026
2b581da
fix: fix for cr
Alexxigang Jan 27, 2026
1e28570
Merge branch 'main' into feat/tool-schema-support
Alexxigang Jan 27, 2026
e3e9e33
revert(test): remove unnecessary test method from ReasoningContextTest
Alexxigang Jan 27, 2026
ea3bbd8
refactor(core): revert ReasoningContext to main version and improve c…
Alexxigang Jan 27, 2026
a30d128
Merge branch 'main' into feat/tool-schema-support
Alexxigang Feb 1, 2026
acb9132
Merge branch 'main' into feat/tool-schema-support
Alexxigang Feb 5, 2026
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 @@ -97,6 +97,89 @@ private static void printStartupInfo() {
""");
System.out.println("\nNote: Accept: text/event-stream header is optional when stream=true");
System.out.println("===================================================");
System.out.println("\nChat completion with Tool Schema (Tool Suspend).\n");
System.out.println(
"""
curl -N -X POST http://localhost:8080/v1/chat/completions \\
-H 'Content-Type: application/json' \\
-d '{
"model": "qwen3-max",
"stream": true,
"messages": [
{ "role": "user", "content": "What is the weather in Hangzhou?" }
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "The city name"
}
},
"required": ["city"]
}
}
}
]
}'
""");
System.out.println("\nNote: Tools are registered as schema-only tools, triggering tool");
System.out.println(" suspension. The response will include tool_calls with");
System.out.println(" finish_reason='tool_calls'. Execute tools externally, then");
System.out.println(" send tool results in the next request:");
System.out.println(
"""

curl -N -X POST http://localhost:8080/v1/chat/completions \\
-H 'Content-Type: application/json' \\
-d '{
"model": "qwen3-max",
"stream": true,
"messages": [
{ "role": "user", "content": "What is the weather in Hangzhou?" },
{
"role": "assistant",
"tool_calls": [{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\\"city\\":\\"Hangzhou\\"}"
}
}]
},
{
"role": "tool",
"tool_call_id": "call_abc123",
"name": "get_weather",
"content": "Sunny, 25°C"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": { "type": "string", "description": "The city name" }
},
"required": ["city"]
}
}
}
]
}'
""");
System.out.println("===================================================");
System.out.println(
"\n⚠️ Important: stream=false with Accept: text/event-stream will return error");
System.out.println(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.agentscope.core.chat.completions.model.ChatMessage;
import io.agentscope.core.chat.completions.model.ToolCall;
import io.agentscope.core.message.ContentBlock;
import io.agentscope.core.message.GenerateReason;
import io.agentscope.core.message.Msg;
import io.agentscope.core.message.MsgRole;
import io.agentscope.core.message.TextBlock;
Expand Down Expand Up @@ -99,9 +100,13 @@ public ChatCompletionsResponse buildResponse(
ChatMessage message = convertMsgToChatMessage(reply);
choice.setMessage(message);

// Set finish_reason based on whether there are tool calls
if (message.getToolCalls() != null && !message.getToolCalls().isEmpty()) {
// Set finish_reason based on GenerateReason or tool calls
GenerateReason generateReason = reply != null ? reply.getGenerateReason() : null;
if (generateReason == GenerateReason.TOOL_SUSPENDED
|| (message.getToolCalls() != null && !message.getToolCalls().isEmpty())) {
choice.setFinishReason("tool_calls");
} else if (generateReason == GenerateReason.MAX_ITERATIONS) {
choice.setFinishReason("length");
} else {
choice.setFinishReason("stop");
}
Expand Down Expand Up @@ -207,11 +212,29 @@ public String extractTextContent(Msg msg) {
/**
* Convert a ToolUseBlock to a ToolCall, serializing the input Map to JSON string.
*
* <p>Prioritizes the content field (raw JSON string) over the input Map, as some providers
* like DashScope store arguments in the content field.
*
* @param block The ToolUseBlock to convert
* @return The OpenAI-compatible ToolCall
*/
private ToolCall convertToolUseBlockToToolCall(ToolUseBlock block) {
String argumentsJson = serializeMapToJson(block.getInput());
// Prioritize content field (raw JSON string) over input map
// DashScope and some providers store arguments in content field
String argumentsJson;
String content = block.getContent();
Map<String, Object> input = block.getInput();

if (content != null && !content.isEmpty()) {
argumentsJson = content;
} else if (input != null && !input.isEmpty()) {
// Only serialize input if it's not empty
argumentsJson = serializeMapToJson(input);
} else {
// Both content and input are empty - use empty object for non-streaming
argumentsJson = "{}";
}

return new ToolCall(block.getId(), block.getName(), argumentsJson);
}

Expand Down
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ public static ChatCompletionsChunk toolCallChunk(
* standard OpenAI streaming response (since OpenAI doesn't execute tools), AgentScope's
* ReActAgent executes tools internally, so we expose the results in the stream.
*
* <p><b>Important:</b> In OpenAI's streaming API specification, delta.role can only be
* "assistant" or "user". The role "tool" is not supported in streaming responses. Therefore,
* tool results are formatted as assistant content with a prefix indicating the tool name.
*
* <p><b>Example output:</b>
*
* <pre>
Expand All @@ -159,31 +163,29 @@ public static ChatCompletionsChunk toolCallChunk(
* "choices": [{
* "index": 0,
* "delta": {
* "role": "tool",
* "tool_call_id": "call_abc",
* "name": "get_weather",
* "content": "The weather is sunny..."
* "role": "assistant",
* "content": "[Tool: get_weather] The weather is sunny..."
* }
* }]
* }
* </pre>
*
* @param id Request ID
* @param model Model name
* @param toolCallId The ID of the tool call this result corresponds to
* @param toolCallId The ID of the tool call this result corresponds to (currently unused in streaming)
* @param toolName The name of the tool that was executed
* @param content The tool execution result content
* @return ChatCompletionsChunk with tool result
* @return ChatCompletionsChunk with tool result formatted as assistant content
*/
public static ChatCompletionsChunk toolResultChunk(
String id, String model, String toolCallId, String toolName, String content) {
ChatCompletionsChunk chunk = new ChatCompletionsChunk(id, model);

ChatMessage delta = new ChatMessage();
delta.setRole("tool");
delta.setToolCallId(toolCallId);
delta.setName(toolName);
delta.setContent(content);
delta.setRole("assistant");
// Format tool result as assistant content for streaming compatibility
// OpenAI streaming API does not support role: "tool" in delta
delta.setContent("[Tool: " + toolName + "] " + content);

ChatChoice choice = new ChatChoice();
choice.setIndex(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ public class ChatCompletionsRequest {
/** Whether to stream responses via Server-Sent Events (SSE). Optional, defaults to false. */
private Boolean stream;

/**
* A list of tools the model may call. Currently, only functions are supported as a tool.
*
* <p>When tools are provided, they are registered as schema-only tools. When the agent decides
* to call a tool, execution is suspended and the tool call is returned to the client for
* external execution.
*/
private List<OpenAITool> tools;

public String getModel() {
return model;
}
Expand All @@ -94,4 +103,12 @@ public Boolean getStream() {
public void setStream(Boolean stream) {
this.stream = stream;
}

public List<OpenAITool> getTools() {
return tools;
}

public void setTools(List<OpenAITool> tools) {
this.tools = tools;
}
}
Loading
Loading