-
Notifications
You must be signed in to change notification settings - Fork 269
refactor(tool): add Toolkit deep copy to isolate agent state #438
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
Changes from all commits
c0c9bf2
8772184
bd82f9c
9f878e9
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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -110,4 +110,18 @@ void removeTool(String toolName) { | |||||||
| void removeTools(Set<String> toolNames) { | ||||||||
| toolNames.forEach(this::removeTool); | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * Copy all tools from this registry to another registry. | ||||||||
| * | ||||||||
| * @param target The target registry to copy tools to | ||||||||
| */ | ||||||||
| void copyTo(ToolRegistry target) { | ||||||||
| for (Map.Entry<String, AgentTool> entry : tools.entrySet()) { | ||||||||
| String toolName = entry.getKey(); | ||||||||
| AgentTool tool = entry.getValue(); | ||||||||
| RegisteredToolFunction registered = registeredTools.get(toolName); | ||||||||
| target.registerTool(toolName, tool, registered); | ||||||||
|
||||||||
| target.registerTool(toolName, tool, registered); | |
| RegisteredToolFunction registeredCopy = registered == null ? null : registered.copy(); | |
| target.registerTool(toolName, tool, registeredCopy); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -642,6 +642,25 @@ public void updateToolPresetParameters( | |
| logger.debug("Updated preset parameters for tool '{}'", toolName); | ||
| } | ||
|
|
||
| // ==================== Deep Copy ==================== | ||
|
|
||
| /** | ||
| * Create a deep copy of this toolkit. | ||
| * | ||
| * @return A new Toolkit instance with copied state | ||
| */ | ||
| public Toolkit copy() { | ||
| Toolkit copy = new Toolkit(this.config); | ||
|
|
||
| // Copy all registered tools | ||
| this.toolRegistry.copyTo(copy.toolRegistry); | ||
|
|
||
| // Copy all tool groups and their states | ||
| this.groupManager.copyTo(copy.groupManager); | ||
|
|
||
| return copy; | ||
| } | ||
|
Comment on lines
+652
to
+662
|
||
|
|
||
| /** | ||
| * Fluent builder for registering tools with optional configuration. | ||
| * | ||
|
|
||
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.
The chunk callback uses .subscribe() which creates a fire-and-forget subscription. This means:
Consider returning the Mono without subscribing and let the caller manage the subscription, or use .subscribeOn() with proper error handling. Alternatively, if fire-and-forget is intentional, add explicit error handling with .doOnError().