-
Notifications
You must be signed in to change notification settings - Fork 889
feat: add workspace interface #1942
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
Open
yuluo-yx
wants to merge
2
commits into
agentscope-ai:main
Choose a base branch
from
yuluo-yx:0626-yuluo/add-worksapce-interface
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+312
−4
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
agentscope-core/src/main/java/io/agentscope/core/workspace/AbstractWorkspace.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,46 @@ | ||
| /* | ||
| * Copyright 2026-2027 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.workspace; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| /** | ||
| * @author yuluo | ||
| * @author <a href="mailto:yuluo08290126@gmail.com">yuluo</a> | ||
| */ | ||
|
|
||
| public abstract class AbstractWorkspace implements Workspace { | ||
|
|
||
| private static final String DEFAULT_HOME_DIR = "/workspace"; | ||
|
|
||
| @Override | ||
| public String workspaceRoot() { | ||
|
|
||
| return DEFAULT_HOME_DIR; | ||
| } | ||
|
|
||
| @Override | ||
| public String sandboxId() { | ||
|
|
||
| return uuid(); | ||
| } | ||
|
|
||
| private static String uuid() { | ||
|
|
||
| return UUID.randomUUID().toString().replace("-", ""); | ||
| } | ||
| } |
150 changes: 150 additions & 0 deletions
150
agentscope-core/src/main/java/io/agentscope/core/workspace/Workspace.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,150 @@ | ||
| /* | ||
| * Copyright 2026-2027 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.workspace; | ||
|
|
||
| import io.agentscope.core.message.DataBlock; | ||
| import io.agentscope.core.skill.AgentSkill; | ||
| import io.agentscope.core.tool.mcp.McpClientWrapper; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
| /** | ||
| * @author yuluo | ||
| * @author <a href="mailto:yuluo08290126@gmail.com">yuluo</a> | ||
| */ | ||
| public interface Workspace extends Sandbox, OffLoader, Mcp, SkillCatalog { | ||
|
|
||
| default String workspaceId() { | ||
| return sandboxId(); | ||
| } | ||
|
|
||
| String workspaceRoot(); | ||
|
|
||
| String getInstructions(); | ||
| } | ||
|
|
||
| /** Contract for the workspace sandbox lifecycle. */ | ||
| interface Sandbox extends AutoCloseable { | ||
|
|
||
| /** | ||
| * Gets the sandbox id. | ||
| * | ||
| * @return the current sandbox id. | ||
| */ | ||
| String sandboxId(); | ||
|
|
||
| /** | ||
| * Checks whether the workspace is still alive. | ||
| * | ||
| * @return true when the workspace is alive, false otherwise. | ||
| */ | ||
| boolean isAlive(); | ||
|
|
||
| /** Initializes the workspace sandbox. */ | ||
| void init(); | ||
|
|
||
| /** Resets the workspace sandbox. */ | ||
| boolean reset(); | ||
|
|
||
| /** | ||
| * Closes the sandbox and releases any associated resources. | ||
| */ | ||
| @Override | ||
| void close(); | ||
| } | ||
|
|
||
| /** Persists data that should be moved out of the active model context. */ | ||
| interface OffLoader { | ||
|
|
||
| String offloadContext(); | ||
|
|
||
| String offloadToolResult(); | ||
|
|
||
| DataBlock offloadMessage(); | ||
| } | ||
|
|
||
| /** Contract for managing MCP clients available in a workspace. */ | ||
| interface Mcp { | ||
|
|
||
| /** | ||
| * Lists the names of MCP clients registered in the current workspace. | ||
| * | ||
| * @return the MCP client names. | ||
| */ | ||
| Set<String> listMcpClients(); | ||
|
|
||
| /** | ||
| * Looks up an MCP client by name. | ||
| * | ||
| * @param mcpClientName the MCP client name. | ||
| * @return the matching MCP client, or empty when it does not exist. | ||
| */ | ||
| Optional<McpClientWrapper> getMcpClient(String mcpClientName); | ||
|
|
||
| /** | ||
| * Registers an MCP client and returns it after the asynchronous initialization chain | ||
| * completes. | ||
| * | ||
| * @param mcpClient the MCP client wrapper. | ||
| * @return the registered MCP client. | ||
| */ | ||
| Mono<McpClientWrapper> addMcpClient(McpClientWrapper mcpClient); | ||
|
|
||
| /** | ||
| * Removes the specified MCP client and returns the removed client. | ||
| * | ||
| * @param mcpClientName the MCP client name. | ||
| * @return the removed MCP client, or an empty Mono when the client does not exist. | ||
| */ | ||
| Mono<McpClientWrapper> removeMcpClient(String mcpClientName); | ||
| } | ||
|
|
||
| /** Contract for managing skills available in a workspace. */ | ||
| interface SkillCatalog { | ||
|
|
||
| /** | ||
| * Lists the skill ids registered in the current workspace. | ||
| * | ||
| * @return the registered skill ids. | ||
| */ | ||
| Set<String> listSkills(); | ||
|
|
||
| /** | ||
| * Looks up a skill by id. | ||
| * | ||
| * @param skillId the skill id. | ||
| * @return the matching skill, or empty when it does not exist. | ||
| */ | ||
| Optional<AgentSkill> getSkill(String skillId); | ||
|
|
||
| /** | ||
| * Registers a skill and returns the actual registered skill. | ||
| * | ||
| * @param skill the skill instance. | ||
| * @return the registered skill. | ||
| */ | ||
| AgentSkill addSkill(AgentSkill skill); | ||
|
|
||
| /** | ||
| * Removes the specified skill and returns the removed skill. | ||
| * | ||
| * @param skillId the skill id. | ||
| * @return the removed skill, or empty when the skill does not exist. | ||
| */ | ||
| Optional<AgentSkill> removeSkill(String skillId); | ||
| } | ||
113 changes: 113 additions & 0 deletions
113
agentscope-core/src/main/java/io/agentscope/core/workspace/impl/local/LocalWorkSpace.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,113 @@ | ||
| /* | ||
| * Copyright 2026-2027 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.workspace.impl.local; | ||
|
|
||
| import io.agentscope.core.message.DataBlock; | ||
| import io.agentscope.core.skill.AgentSkill; | ||
| import io.agentscope.core.tool.mcp.McpClientWrapper; | ||
| import io.agentscope.core.workspace.AbstractWorkspace; | ||
|
|
||
| import java.util.Optional; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * @author yuluo | ||
| * @author <a href="mailto:yuluo08290126@gmail.com">yuluo</a> | ||
| */ | ||
|
|
||
| public class LocalWorkSpace extends AbstractWorkspace { | ||
|
|
||
| @Override | ||
| public String getInstructions() { | ||
| return ""; | ||
| } | ||
|
|
||
| @Override | ||
| public Set<String> listMcpClients() { | ||
| return Set.of(); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<McpClientWrapper> getMcpClient(String mcpClientName) { | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| @Override | ||
| public Mono<McpClientWrapper> addMcpClient(McpClientWrapper mcpClient) { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public Mono<McpClientWrapper> removeMcpClient(String mcpClientName) { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public String offloadContext() { | ||
| return ""; | ||
| } | ||
|
|
||
| @Override | ||
| public String offloadToolResult() { | ||
| return ""; | ||
| } | ||
|
|
||
| @Override | ||
| public DataBlock offloadMessage() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isAlive() { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public void init() { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public boolean reset() { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public Set<String> listSkills() { | ||
| return Set.of(); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<AgentSkill> getSkill(String skillId) { | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| @Override | ||
| public AgentSkill addSkill(AgentSkill skill) { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<AgentSkill> removeSkill(String skillId) { | ||
| return Optional.empty(); | ||
| } | ||
| } |
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.