Class: SwarmSDK::V3::Tools::Think

Inherits:
Base
  • Object
show all
Defined in:
lib/swarm_sdk/v3/tools/think.rb

Overview

Think tool for explicit reasoning and planning

Allows the agent to write down thoughts, plans, and intermediate calculations. These thoughts become part of the conversation context, enabling better reasoning through complex problems.

When the agent has memory enabled, Think retrieves relevant memories for the thought content and returns them alongside “Thought noted.” This gives the agent access to its long-term knowledge while reasoning. Without memory, Think behaves as a simple acknowledgment.

Think does NOT write to memory — the existing turn-level async ingestion pipeline already captures tool call arguments (including Think’s thoughts), so Think content is automatically persisted.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#name

Constructor Details

#initialize(memory_store: nil) ⇒ Think

Returns a new instance of Think.

Parameters:

  • memory_store (Memory::Store, nil) (defaults to: nil)

    Memory store for retrieval



29
30
31
32
# File 'lib/swarm_sdk/v3/tools/think.rb', line 29

def initialize(memory_store: nil)
  super()
  @memory_store = memory_store
end

Class Method Details

.creation_requirementsArray<Symbol>

Returns Constructor requirements.

Returns:

  • (Array<Symbol>)

    Constructor requirements



23
24
25
# File 'lib/swarm_sdk/v3/tools/think.rb', line 23

def creation_requirements
  [:memory_store]
end

Instance Method Details

#execute(thoughts:, **_kwargs) ⇒ String

Execute the Think tool

When memory is available, searches for cards relevant to the thought content and returns them as context for the agent’s reasoning.

Parameters:

  • thoughts (String)

    The agent’s thoughts

Returns:

  • (String)

    Acknowledgment with optional related memories



63
64
65
66
67
68
# File 'lib/swarm_sdk/v3/tools/think.rb', line 63

def execute(thoughts:, **_kwargs)
  return "Thought noted." unless @memory_store

  cards = @memory_store.search(thoughts, top_k: 5)
  format_response(cards)
end