Class: SwarmSDK::Swarm::LazyDelegateChat
- Inherits:
-
Object
- Object
- SwarmSDK::Swarm::LazyDelegateChat
- Defined in:
- lib/swarm_sdk/swarm/lazy_delegate_chat.rb
Overview
Lazy loader for delegation agent chats
Instead of creating delegation instances eagerly at swarm initialization, this class defers creation until the first delegation call. This improves initialization performance for swarms where not all agents are used.
Thread-safe via Mutex - safe for concurrent access.
Instance Attribute Summary collapse
-
#agent_definition ⇒ Object
readonly
Returns the value of attribute agent_definition.
-
#base_name ⇒ Object
readonly
Returns the value of attribute base_name.
-
#instance_name ⇒ Object
readonly
Returns the value of attribute instance_name.
Instance Method Summary collapse
-
#chat ⇒ Agent::Chat
Get or create the agent chat instance.
-
#initialize(instance_name:, base_name:, agent_definition:, swarm:) ⇒ LazyDelegateChat
constructor
Initialize a lazy delegate chat wrapper.
-
#initialized? ⇒ Boolean
Check if the agent has been initialized.
Constructor Details
#initialize(instance_name:, base_name:, agent_definition:, swarm:) ⇒ LazyDelegateChat
Initialize a lazy delegate chat wrapper
33 34 35 36 37 38 39 40 41 |
# File 'lib/swarm_sdk/swarm/lazy_delegate_chat.rb', line 33 def initialize(instance_name:, base_name:, agent_definition:, swarm:) @instance_name = instance_name @base_name = base_name @agent_definition = agent_definition @swarm = swarm @chat = nil @mutex = Mutex.new @initialized = false end |
Instance Attribute Details
#agent_definition ⇒ Object (readonly)
Returns the value of attribute agent_definition.
25 26 27 |
# File 'lib/swarm_sdk/swarm/lazy_delegate_chat.rb', line 25 def agent_definition @agent_definition end |
#base_name ⇒ Object (readonly)
Returns the value of attribute base_name.
25 26 27 |
# File 'lib/swarm_sdk/swarm/lazy_delegate_chat.rb', line 25 def base_name @base_name end |
#instance_name ⇒ Object (readonly)
Returns the value of attribute instance_name.
25 26 27 |
# File 'lib/swarm_sdk/swarm/lazy_delegate_chat.rb', line 25 def instance_name @instance_name end |
Instance Method Details
#chat ⇒ Agent::Chat
Get or create the agent chat instance
On first call, creates the agent chat and runs initialization. Subsequent calls return the cached instance.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/swarm_sdk/swarm/lazy_delegate_chat.rb', line 49 def chat return @chat if @initialized @mutex.synchronize do return @chat if @initialized @chat = initialize_chat @initialized = true @chat end end |
#initialized? ⇒ Boolean
Check if the agent has been initialized
64 65 66 |
# File 'lib/swarm_sdk/swarm/lazy_delegate_chat.rb', line 64 def initialized? @mutex.synchronize { @initialized } end |