Class: SwarmSDK::Workflow::AgentConfig
- Inherits:
-
Object
- Object
- SwarmSDK::Workflow::AgentConfig
- Defined in:
- lib/swarm_sdk/workflow/agent_config.rb
Overview
AgentConfig provides fluent API for configuring agents within a node
This class enables the chainable syntax:
agent(:backend).delegates_to(:tester, :database)
agent(:backend, reset_context: false) # Preserve context across nodes
agent(:backend).tools(:Read, :Edit) # Override tools for this node
Instance Attribute Summary collapse
-
#agent_name ⇒ Object
readonly
Returns the value of attribute agent_name.
Instance Method Summary collapse
-
#delegates_to(*agent_names_and_options) ⇒ self
Set delegation targets for this agent.
-
#finalize ⇒ void
Finalize agent configuration (backward compatibility).
-
#initialize(agent_name, node_builder, reset_context: true) ⇒ AgentConfig
constructor
A new instance of AgentConfig.
-
#tools(*tool_names) ⇒ self
Override tools for this agent in this node.
-
#update_registration ⇒ void
Update agent registration (called after each fluent method).
Constructor Details
#initialize(agent_name, node_builder, reset_context: true) ⇒ AgentConfig
Returns a new instance of AgentConfig.
29 30 31 32 33 34 35 36 |
# File 'lib/swarm_sdk/workflow/agent_config.rb', line 29 def initialize(agent_name, node_builder, reset_context: true) @agent_name = agent_name @node_builder = node_builder @delegates_to = [] @reset_context = reset_context @tools = nil # nil means use global agent definition tools @finalized = false end |
Instance Attribute Details
#agent_name ⇒ Object (readonly)
Returns the value of attribute agent_name.
27 28 29 |
# File 'lib/swarm_sdk/workflow/agent_config.rb', line 27 def agent_name @agent_name end |
Instance Method Details
#delegates_to(*agent_names_and_options) ⇒ self
Set delegation targets for this agent
Supports multiple formats for flexibility:
- Array: delegates_to(:frontend, :backend)
- Hash: delegates_to(frontend: "AskFrontend", backend: "GetBackend")
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/swarm_sdk/workflow/agent_config.rb', line 46 def delegates_to(*) # Parse delegation configs (same logic as Agent::Builder) @delegates_to = [] .each do |item| case item when Symbol, String @delegates_to << { agent: item.to_sym, tool_name: nil } when Hash item.each do |agent, tool_name| @delegates_to << { agent: agent.to_sym, tool_name: tool_name } end end end update_registration self end |
#finalize ⇒ void
This method returns an undefined value.
Finalize agent configuration (backward compatibility)
90 91 92 |
# File 'lib/swarm_sdk/workflow/agent_config.rb', line 90 def finalize update_registration end |
#tools(*tool_names) ⇒ self
Override tools for this agent in this node
71 72 73 74 75 |
# File 'lib/swarm_sdk/workflow/agent_config.rb', line 71 def tools(*tool_names) @tools = tool_names.map(&:to_sym) update_registration self end |
#update_registration ⇒ void
This method returns an undefined value.
Update agent registration (called after each fluent method)
Always updates the registration with current state. This allows chaining: .delegates_to(...).tools(...)
83 84 85 |
# File 'lib/swarm_sdk/workflow/agent_config.rb', line 83 def update_registration @node_builder.register_agent(@agent_name, @delegates_to, @reset_context, @tools) end |