Class: RCrewAI::Memory::ToolMemory

Inherits:
BaseMemory show all
Defined in:
lib/rcrewai/memory/tool_memory.rb

Overview

Tool-call history and outcomes. Replaces the old @tool_usage array; persistable and searchable like the other memory types.

Instance Method Summary collapse

Methods inherited from BaseMemory

#clear!, #count, #initialize, #recall, #record

Constructor Details

This class inherits a constructor from RCrewAI::Memory::BaseMemory

Instance Method Details

#record_call(tool_name, params, result) ⇒ Object



10
11
12
13
14
# File 'lib/rcrewai/memory/tool_memory.rb', line 10

def record_call(tool_name, params, result)
  success = !result.to_s.downcase.include?('error')
  text = "#{tool_name}(#{format_params(params)}) -> #{result}"
  add(text, { 'tool' => tool_name, 'success' => success, 'result' => result.to_s })
end

#usage_for(tool_name, limit: 5) ⇒ Object

Most-recent-first usage records for a given tool.



17
18
19
20
21
22
23
# File 'lib/rcrewai/memory/tool_memory.rb', line 17

def usage_for(tool_name, limit: 5)
  @store.all(scope: @scope)
        .select { |r| r[:metadata]['tool'] == tool_name }
        .sort_by { |r| -r[:metadata]['seq'].to_i }
        .first(limit)
        .map { |r| r[:text] }
end