swarm_sdk 2.7.2 → 2.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9d0b44f3edf346a30b0442027c9ca2e8cf06e3e2c074c89f483c0eab0964a592
|
|
4
|
+
data.tar.gz: b7c690fd69303078c70c252a09a9e4f46b63f0f4a438a3fc9188cacc30e44109
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e0881dd9ae7fefc423bdbad4d56d535be627b622f2301eae1c12858d8198f7f55472198f6413535bccd768b17368233ac24ca5d2ab58417cbee9a7a68e8cdc79
|
|
7
|
+
data.tar.gz: a2af0ea8bf741a017196ce6db4d17a7b1bdc9fed2e517c35ae17c2336b950d25300186970f15b746fbc7dfd5c2679a53b9596d9f675c5a44089dc10672d542a0
|
|
@@ -275,6 +275,10 @@ module SwarmSDK
|
|
|
275
275
|
# backend: "GetBackendHelp",
|
|
276
276
|
# :qa
|
|
277
277
|
#
|
|
278
|
+
# @example With delegation options (preserve_context controls context persistence)
|
|
279
|
+
# delegates_to :frontend,
|
|
280
|
+
# { agent: :backend, tool_name: "AskBackend", preserve_context: false }
|
|
281
|
+
#
|
|
278
282
|
# @param agent_names_and_options [Array<Symbol, Hash>] Agent names and/or hash with custom tool names
|
|
279
283
|
# @return [void]
|
|
280
284
|
def delegates_to(*agent_names_and_options)
|
|
@@ -282,11 +286,20 @@ module SwarmSDK
|
|
|
282
286
|
case item
|
|
283
287
|
when Symbol, String
|
|
284
288
|
# Simple format: :frontend
|
|
285
|
-
@delegates_to << { agent: item.to_sym, tool_name: nil }
|
|
289
|
+
@delegates_to << { agent: item.to_sym, tool_name: nil, preserve_context: true }
|
|
286
290
|
when Hash
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
@delegates_to << {
|
|
291
|
+
if item.key?(:agent)
|
|
292
|
+
# Full config format: { agent: :backend, tool_name: "Custom", preserve_context: false }
|
|
293
|
+
@delegates_to << {
|
|
294
|
+
agent: item[:agent].to_sym,
|
|
295
|
+
tool_name: item[:tool_name],
|
|
296
|
+
preserve_context: item.fetch(:preserve_context, true),
|
|
297
|
+
}
|
|
298
|
+
else
|
|
299
|
+
# Hash format: { frontend: "AskFrontend", backend: nil }
|
|
300
|
+
item.each do |agent, tool_name|
|
|
301
|
+
@delegates_to << { agent: agent.to_sym, tool_name: tool_name, preserve_context: true }
|
|
302
|
+
end
|
|
290
303
|
end
|
|
291
304
|
else
|
|
292
305
|
raise ConfigurationError, "delegates_to accepts Symbols or Hashes, got #{item.class}"
|
|
@@ -325,16 +325,20 @@ module SwarmSDK
|
|
|
325
325
|
delegation_config.flat_map do |item|
|
|
326
326
|
case item
|
|
327
327
|
when Symbol, String
|
|
328
|
-
# Simple format: :frontend → {agent: :frontend, tool_name: nil}
|
|
329
|
-
[{ agent: item.to_sym, tool_name: nil }]
|
|
328
|
+
# Simple format: :frontend → {agent: :frontend, tool_name: nil, preserve_context: true}
|
|
329
|
+
[{ agent: item.to_sym, tool_name: nil, preserve_context: true }]
|
|
330
330
|
when Hash
|
|
331
331
|
# Could be already normalized or hash format
|
|
332
332
|
if item.key?(:agent)
|
|
333
|
-
# Already normalized: {agent: :frontend, tool_name: "Custom"}
|
|
334
|
-
[
|
|
333
|
+
# Already normalized: {agent: :frontend, tool_name: "Custom", preserve_context: false}
|
|
334
|
+
[{
|
|
335
|
+
agent: item[:agent].to_sym,
|
|
336
|
+
tool_name: item[:tool_name],
|
|
337
|
+
preserve_context: item.fetch(:preserve_context, true),
|
|
338
|
+
}]
|
|
335
339
|
else
|
|
336
340
|
# Hash format in array: {frontend: "AskFrontend"}
|
|
337
|
-
item.map { |agent, tool_name| { agent: agent.to_sym, tool_name: tool_name } }
|
|
341
|
+
item.map { |agent, tool_name| { agent: agent.to_sym, tool_name: tool_name, preserve_context: true } }
|
|
338
342
|
end
|
|
339
343
|
else
|
|
340
344
|
raise ConfigurationError, "Invalid delegation config format: #{item.inspect}"
|
|
@@ -343,7 +347,7 @@ module SwarmSDK
|
|
|
343
347
|
elsif delegation_config.is_a?(Hash)
|
|
344
348
|
# Hash format: {frontend: "AskFrontend", backend: nil}
|
|
345
349
|
delegation_config.map do |agent, tool_name|
|
|
346
|
-
{ agent: agent.to_sym, tool_name: tool_name }
|
|
350
|
+
{ agent: agent.to_sym, tool_name: tool_name, preserve_context: true }
|
|
347
351
|
end
|
|
348
352
|
else
|
|
349
353
|
raise ConfigurationError, "delegates_to must be an Array or Hash, got #{delegation_config.class}"
|
|
@@ -91,8 +91,9 @@ module SwarmSDK
|
|
|
91
91
|
# @param agent_name [Symbol] Name of the delegating agent
|
|
92
92
|
# @param delegating_chat [Agent::Chat, nil] The chat instance of the agent doing the delegating
|
|
93
93
|
# @param custom_tool_name [String, nil] Optional custom tool name (overrides auto-generated name)
|
|
94
|
+
# @param preserve_context [Boolean] Whether to preserve conversation context between delegations (default: true)
|
|
94
95
|
# @return [Tools::Delegate] Delegation tool
|
|
95
|
-
def create_delegation_tool(name:, description:, delegate_chat:, agent_name:, delegating_chat: nil, custom_tool_name: nil)
|
|
96
|
+
def create_delegation_tool(name:, description:, delegate_chat:, agent_name:, delegating_chat: nil, custom_tool_name: nil, preserve_context: true)
|
|
96
97
|
Tools::Delegate.new(
|
|
97
98
|
delegate_name: name,
|
|
98
99
|
delegate_description: description,
|
|
@@ -101,6 +102,7 @@ module SwarmSDK
|
|
|
101
102
|
swarm: @swarm,
|
|
102
103
|
delegating_chat: delegating_chat,
|
|
103
104
|
custom_tool_name: custom_tool_name,
|
|
105
|
+
preserve_context: preserve_context,
|
|
104
106
|
)
|
|
105
107
|
end
|
|
106
108
|
|
|
@@ -219,7 +221,7 @@ module SwarmSDK
|
|
|
219
221
|
#
|
|
220
222
|
# @param delegator_name [Symbol, String] Name of the agent doing the delegating
|
|
221
223
|
# @param delegator_chat [Agent::Chat] Chat instance of the delegator
|
|
222
|
-
# @param delegation_config [Hash] Delegation configuration with :agent and :
|
|
224
|
+
# @param delegation_config [Hash] Delegation configuration with :agent, :tool_name, and :preserve_context keys
|
|
223
225
|
# @param tool_configurator [ToolConfigurator] Tool configuration helper
|
|
224
226
|
# @param create_nested_instances [Boolean] Whether to create new instances for nested delegation
|
|
225
227
|
# @return [void]
|
|
@@ -227,10 +229,11 @@ module SwarmSDK
|
|
|
227
229
|
delegate_name_sym = delegation_config[:agent]
|
|
228
230
|
delegate_name_str = delegate_name_sym.to_s
|
|
229
231
|
custom_tool_name = delegation_config[:tool_name]
|
|
232
|
+
preserve_context = delegation_config.fetch(:preserve_context, true)
|
|
230
233
|
|
|
231
234
|
# Check if target is a registered swarm
|
|
232
235
|
if @swarm.swarm_registry&.registered?(delegate_name_str)
|
|
233
|
-
wire_swarm_delegation(delegator_name, delegator_chat, delegate_name_str, custom_tool_name)
|
|
236
|
+
wire_swarm_delegation(delegator_name, delegator_chat, delegate_name_str, custom_tool_name, preserve_context)
|
|
234
237
|
elsif @swarm.agent_definitions.key?(delegate_name_sym)
|
|
235
238
|
wire_agent_delegation(
|
|
236
239
|
delegator_name: delegator_name,
|
|
@@ -239,6 +242,7 @@ module SwarmSDK
|
|
|
239
242
|
custom_tool_name: custom_tool_name,
|
|
240
243
|
tool_configurator: tool_configurator,
|
|
241
244
|
create_nested_instances: create_nested_instances,
|
|
245
|
+
preserve_context: preserve_context,
|
|
242
246
|
)
|
|
243
247
|
else
|
|
244
248
|
raise ConfigurationError,
|
|
@@ -252,8 +256,9 @@ module SwarmSDK
|
|
|
252
256
|
# @param delegator_chat [Agent::Chat] Chat instance of the delegator
|
|
253
257
|
# @param swarm_name [String] Name of the registered swarm
|
|
254
258
|
# @param custom_tool_name [String, nil] Optional custom tool name
|
|
259
|
+
# @param preserve_context [Boolean] Whether to preserve context between delegations
|
|
255
260
|
# @return [void]
|
|
256
|
-
def wire_swarm_delegation(delegator_name, delegator_chat, swarm_name, custom_tool_name)
|
|
261
|
+
def wire_swarm_delegation(delegator_name, delegator_chat, swarm_name, custom_tool_name, preserve_context)
|
|
257
262
|
tool = create_delegation_tool(
|
|
258
263
|
name: swarm_name,
|
|
259
264
|
description: "External swarm: #{swarm_name}",
|
|
@@ -261,13 +266,14 @@ module SwarmSDK
|
|
|
261
266
|
agent_name: delegator_name,
|
|
262
267
|
delegating_chat: delegator_chat,
|
|
263
268
|
custom_tool_name: custom_tool_name,
|
|
269
|
+
preserve_context: preserve_context,
|
|
264
270
|
)
|
|
265
271
|
|
|
266
272
|
# Register in tool registry (Plan 025)
|
|
267
273
|
delegator_chat.tool_registry.register(
|
|
268
274
|
tool,
|
|
269
275
|
source: :delegation,
|
|
270
|
-
metadata: { delegate_name: swarm_name, delegation_type: :swarm },
|
|
276
|
+
metadata: { delegate_name: swarm_name, delegation_type: :swarm, preserve_context: preserve_context },
|
|
271
277
|
)
|
|
272
278
|
end
|
|
273
279
|
|
|
@@ -282,8 +288,9 @@ module SwarmSDK
|
|
|
282
288
|
# @param custom_tool_name [String, nil] Optional custom tool name
|
|
283
289
|
# @param tool_configurator [ToolConfigurator] Tool configuration helper
|
|
284
290
|
# @param create_nested_instances [Boolean] Whether to create new instances if not found
|
|
291
|
+
# @param preserve_context [Boolean] Whether to preserve context between delegations
|
|
285
292
|
# @return [void]
|
|
286
|
-
def wire_agent_delegation(delegator_name:, delegator_chat:, delegate_name_sym:, custom_tool_name:, tool_configurator:, create_nested_instances:)
|
|
293
|
+
def wire_agent_delegation(delegator_name:, delegator_chat:, delegate_name_sym:, custom_tool_name:, tool_configurator:, create_nested_instances:, preserve_context:)
|
|
287
294
|
delegate_definition = @swarm.agent_definitions[delegate_name_sym]
|
|
288
295
|
|
|
289
296
|
# Determine which chat instance to use
|
|
@@ -316,6 +323,7 @@ module SwarmSDK
|
|
|
316
323
|
agent_name: delegator_name,
|
|
317
324
|
delegating_chat: delegator_chat,
|
|
318
325
|
custom_tool_name: custom_tool_name,
|
|
326
|
+
preserve_context: preserve_context,
|
|
319
327
|
)
|
|
320
328
|
|
|
321
329
|
# Register in tool registry (Plan 025)
|
|
@@ -325,6 +333,7 @@ module SwarmSDK
|
|
|
325
333
|
metadata: {
|
|
326
334
|
delegate_name: delegate_name_sym,
|
|
327
335
|
delegation_mode: delegate_definition.shared_across_delegations ? :shared : :isolated,
|
|
336
|
+
preserve_context: preserve_context,
|
|
328
337
|
},
|
|
329
338
|
)
|
|
330
339
|
end
|
|
@@ -37,7 +37,7 @@ module SwarmSDK
|
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
attr_reader :delegate_name, :delegate_target, :tool_name
|
|
40
|
+
attr_reader :delegate_name, :delegate_target, :tool_name, :preserve_context
|
|
41
41
|
|
|
42
42
|
# Initialize a delegation tool
|
|
43
43
|
#
|
|
@@ -48,6 +48,7 @@ module SwarmSDK
|
|
|
48
48
|
# @param swarm [Swarm] The swarm instance (provides hook_registry, delegation_call_stack, swarm_registry)
|
|
49
49
|
# @param delegating_chat [Agent::Chat, nil] The chat instance of the agent doing the delegating (for accessing hooks)
|
|
50
50
|
# @param custom_tool_name [String, nil] Optional custom tool name (overrides auto-generated name)
|
|
51
|
+
# @param preserve_context [Boolean] Whether to preserve conversation context between delegations (default: true)
|
|
51
52
|
def initialize(
|
|
52
53
|
delegate_name:,
|
|
53
54
|
delegate_description:,
|
|
@@ -55,7 +56,8 @@ module SwarmSDK
|
|
|
55
56
|
agent_name:,
|
|
56
57
|
swarm:,
|
|
57
58
|
delegating_chat: nil,
|
|
58
|
-
custom_tool_name: nil
|
|
59
|
+
custom_tool_name: nil,
|
|
60
|
+
preserve_context: true
|
|
59
61
|
)
|
|
60
62
|
super()
|
|
61
63
|
|
|
@@ -65,6 +67,7 @@ module SwarmSDK
|
|
|
65
67
|
@agent_name = agent_name
|
|
66
68
|
@swarm = swarm
|
|
67
69
|
@delegating_chat = delegating_chat
|
|
70
|
+
@preserve_context = preserve_context
|
|
68
71
|
|
|
69
72
|
# Use custom tool name if provided, otherwise generate using canonical method
|
|
70
73
|
@tool_name = custom_tool_name || self.class.tool_name_for(delegate_name)
|
|
@@ -224,6 +227,9 @@ module SwarmSDK
|
|
|
224
227
|
# Push delegate target onto call stack to track delegation chain
|
|
225
228
|
call_stack.push(@delegate_target)
|
|
226
229
|
begin
|
|
230
|
+
# Clear conversation if preserve_context is false
|
|
231
|
+
@delegate_chat.clear_conversation unless @preserve_context
|
|
232
|
+
|
|
227
233
|
response = @delegate_chat.ask(message, source: "delegation")
|
|
228
234
|
response.content
|
|
229
235
|
ensure
|
data/lib/swarm_sdk/version.rb
CHANGED