-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat(openai-official): add OpenAI Responses API module #3078
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /* | ||
| * 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.e2e.providers; | ||
|
|
||
| import io.agentscope.core.ReActAgent; | ||
| import io.agentscope.core.tool.Toolkit; | ||
| import io.agentscope.extensions.model.openaiofficial.OpenAIResponsesChatModel; | ||
| import io.agentscope.extensions.model.openaiofficial.ResponsesMultiAgentFormatter; | ||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * Provider for OpenAI models via the official OpenAI Java SDK (Responses API). | ||
| */ | ||
| @ModelCapabilities({ModelCapability.BASIC, ModelCapability.TOOL_CALLING}) | ||
| public class OpenAIOfficialResponsesProvider extends BaseModelProvider { | ||
|
|
||
| private static final String API_KEY_ENV = "OPENAI_API_KEY"; | ||
| private static final String BASE_URL_ENV = "OPENAI_BASE_URL"; | ||
|
|
||
| public OpenAIOfficialResponsesProvider(String modelName, boolean multiAgentFormatter) { | ||
| super(API_KEY_ENV, modelName, multiAgentFormatter); | ||
| } | ||
|
|
||
| @Override | ||
| protected ReActAgent.Builder doCreateAgentBuilder(String name, Toolkit toolkit, String apiKey) { | ||
| String baseUrl = System.getenv(BASE_URL_ENV); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个只支持通过系统环境变量获取吗? |
||
|
|
||
| OpenAIResponsesChatModel.Builder builder = | ||
| OpenAIResponsesChatModel.builder().apiKey(apiKey).modelName(getModelName()); | ||
|
|
||
| if (baseUrl != null && !baseUrl.isEmpty()) { | ||
| builder.baseUrl(baseUrl); | ||
| } | ||
|
|
||
| if (isMultiAgentFormatter()) { | ||
| builder.formatter(new ResponsesMultiAgentFormatter()); | ||
| } | ||
|
|
||
| return ReActAgent.builder().name(name).model(builder.build()).toolkit(toolkit); | ||
| } | ||
|
|
||
| @Override | ||
| public String getProviderName() { | ||
| return "OpenAI-Official"; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为什么这个不是静态常量? |
||
| } | ||
|
|
||
| @Override | ||
| public Set<ModelCapability> getCapabilities() { | ||
| Set<ModelCapability> caps = new HashSet<>(super.getCapabilities()); | ||
| if (isMultiAgentFormatter()) { | ||
| caps.add(ModelCapability.MULTI_AGENT_FORMATTER); | ||
| } | ||
| return caps; | ||
| } | ||
|
|
||
| // ========================================================================== | ||
| // Provider Instances | ||
| // ========================================================================== | ||
|
|
||
| /** GPT-5.4 via OpenAI Official SDK (Responses API). */ | ||
| @ModelCapabilities({ | ||
| ModelCapability.BASIC, | ||
| ModelCapability.TOOL_CALLING, | ||
| ModelCapability.THINKING | ||
| }) | ||
| public static class Gpt54 extends OpenAIOfficialResponsesProvider { | ||
| public Gpt54() { | ||
| super("gpt-5.4", false); | ||
| } | ||
|
|
||
| @Override | ||
| public String getProviderName() { | ||
| return "OpenAI-Official"; | ||
| } | ||
| } | ||
|
|
||
| /** GPT-5.4 with Multi-Agent Formatter. */ | ||
| @ModelCapabilities({ | ||
| ModelCapability.BASIC, | ||
| ModelCapability.TOOL_CALLING, | ||
| ModelCapability.THINKING, | ||
| ModelCapability.MULTI_AGENT_FORMATTER | ||
| }) | ||
| public static class Gpt54MultiAgent extends OpenAIOfficialResponsesProvider { | ||
| public Gpt54MultiAgent() { | ||
| super("gpt-5.4", true); | ||
| } | ||
|
|
||
| @Override | ||
| public String getProviderName() { | ||
| return "OpenAI-Official (Multi-Agent)"; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为啥这不是静态常量呢? |
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| ~ 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. | ||
| --> | ||
|
|
||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>io.agentscope</groupId> | ||
| <artifactId>agentscope-extensions-model</artifactId> | ||
| <version>${revision}</version> | ||
| <relativePath>../pom.xml</relativePath> | ||
| </parent> | ||
|
|
||
| <artifactId>agentscope-extensions-model-openai-official</artifactId> | ||
| <name>AgentScope Java - Extensions - Model - OpenAI Official</name> | ||
| <description>OpenAI official SDK model provider extension for AgentScope Java</description> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>io.agentscope</groupId> | ||
| <artifactId>agentscope-core</artifactId> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>com.openai</groupId> | ||
| <artifactId>openai-java</artifactId> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>io.projectreactor</groupId> | ||
| <artifactId>reactor-core</artifactId> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>com.fasterxml.jackson.core</groupId> | ||
| <artifactId>jackson-databind</artifactId> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>io.agentscope</groupId> | ||
| <artifactId>agentscope-core</artifactId> | ||
| <version>${project.version}</version> | ||
| <type>test-jar</type> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.mockito</groupId> | ||
| <artifactId>mockito-core</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[HIGH] Adding this module to
agentscope-allcurrently packages the classes but does not make the provider discoverable. The shade build warns that multiple model modules defineMETA-INF/services/io.agentscope.core.model.spi.ModelProvider, and the generatedagentscope-2.0.3-SNAPSHOT.jarkeeps only the existing OpenAI entries:unzip -p agentscope-distribution/agentscope-all/target/agentscope-2.0.3-SNAPSHOT.jar META-INF/services/io.agentscope.core.model.spi.ModelProviderdoes not includeio.agentscope.extensions.model.openaiofficial.OpenAIOfficialModelProvider, even though the class is present. Users depending on the advertised all-in-oneagentscopeartifact will therefore fail to resolveopenai-official:<model>throughModelRegistry. Please configure the shade plugin to merge service descriptors, for example withorg.apache.maven.plugins.shade.resource.ServicesResourceTransformer, and add a packaging assertion or smoke test that the shaded jar service file contains this provider.