Class: SwarmSDK::V3::SubTaskAgent
- Defined in:
- lib/swarm_sdk/v3/sub_task_agent.rb
Overview
Ephemeral agent for focused subtask execution
SubTaskAgent is a lightweight copy of an Agent that shares the parent’s memory store in read-only mode. It inherits all of the parent’s capabilities (MCP connections, skills, tools) but skips memory writes, STM capture, ingestion, and eviction.
## Design
Rather than adding flags to Agent, SubTaskAgent overrides the specific lifecycle methods that differ. This keeps Agent unchanged (zero regression risk) and encapsulates all subtask behavior in one class.
## What’s inherited unchanged from Agent
-
Agent#connect_mcp_servers — full MCP connections
-
Agent#load_skills — same skill directories
-
#create_chat / #configure_chat — fresh chat, same model/params
-
Agent#build_base_system_prompt — same system prompt + skills metadata
-
Agent#ask / Agent#execute_turn — same turn flow (memory writes are no-ops)
-
Agent#interrupt! — interruption safety preserved
-
Agent#clear — proper MCP cleanup
## What’s overridden
-
#initialize_memory — uses parent’s memory store instead of creating one
-
#capture_turn — no-op (subtask is ephemeral)
-
#ingest_into_memory — no-op (read-only memory)
-
#evict_stm — no-op (no STM to evict)
-
#memory_read_only? — returns true (skips access counter updates)
-
#attach_tools — passes subtask_depth to Registry
Instance Attribute Summary collapse
-
#subtask_depth ⇒ Integer
readonly
Current subtask nesting depth.
Attributes inherited from Agent
#definition, #id, #loaded_skills
Instance Method Summary collapse
-
#initialize(definition, parent_memory_store:, subtask_depth:) ⇒ SubTaskAgent
constructor
Create a new subtask agent.
-
#memory_read_only? ⇒ Boolean
Whether memory operations are read-only.
-
#resolved_subtask_config ⇒ Hash
Resolve subtask model configuration with fallback chain.
-
#subtask_mode? ⇒ Boolean
Whether this agent is running as a subtask.
Methods inherited from Agent
#ask, #clear, #clear_steering_queue, #defrag!, #initialized?, #interrupt!, #loop, #memory, #messages, #name, #running?, #steer, #tokens
Constructor Details
#initialize(definition, parent_memory_store:, subtask_depth:) ⇒ SubTaskAgent
Create a new subtask agent
54 55 56 57 58 |
# File 'lib/swarm_sdk/v3/sub_task_agent.rb', line 54 def initialize(definition, parent_memory_store:, subtask_depth:) super(definition) @parent_memory_store = parent_memory_store @subtask_depth = subtask_depth end |
Instance Attribute Details
#subtask_depth ⇒ Integer (readonly)
Returns Current subtask nesting depth.
47 48 49 |
# File 'lib/swarm_sdk/v3/sub_task_agent.rb', line 47 def subtask_depth @subtask_depth end |
Instance Method Details
#memory_read_only? ⇒ Boolean
Whether memory operations are read-only
70 71 72 |
# File 'lib/swarm_sdk/v3/sub_task_agent.rb', line 70 def memory_read_only? true end |
#resolved_subtask_config ⇒ Hash
Resolve subtask model configuration with fallback chain
Resolution order:
-
Agent-level subtask config (definition.subtask_*)
-
Global config subtask config (Configuration.subtask_*)
-
Parent’s model config (fallback)
86 87 88 |
# File 'lib/swarm_sdk/v3/sub_task_agent.rb', line 86 def resolved_subtask_config @resolved_subtask_config ||= build_resolved_subtask_config end |
#subtask_mode? ⇒ Boolean
Whether this agent is running as a subtask
63 64 65 |
# File 'lib/swarm_sdk/v3/sub_task_agent.rb', line 63 def subtask_mode? true end |