Class: Agentd::MemoryCommands

Inherits:
Thor
  • Object
show all
Includes:
CLIHelpers
Defined in:
lib/agentd/cli.rb

Overview


Instance Method Summary collapse

Methods included from CLIHelpers

#build_agent, #build_client, #format_json, #status_color

Instance Method Details

#delete(key) ⇒ Object



295
296
297
298
# File 'lib/agentd/cli.rb', line 295

def delete(key)
  build_agent(options).memory_delete(key, namespace: options[:namespace])
  say "Deleted: #{key}", :yellow
end

#dreamObject



301
302
303
304
305
# File 'lib/agentd/cli.rb', line 301

def dream
  say "Dreaming… (this may take a moment)", :cyan
  result = build_agent(options).dream
  say format_json(result)
end

#listObject



259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/agentd/cli.rb', line 259

def list
  memories = build_agent(options).memory_list(
    namespace: options[:namespace],
    per: options[:per]
  )
  if memories.empty?
    say "No memories stored.", :yellow
  else
    memories.each { |m| print_memory(m) }
    say "\n#{memories.length} #{"memory".then { |w| memories.length == 1 ? w : "memories" }}.", :white
  end
end

#search(query) ⇒ Object



274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/agentd/cli.rb', line 274

def search(query)
  results = build_agent(options).memory_search(
    query,
    limit:     options[:limit],
    namespace: options[:namespace]
  )
  if results.empty?
    say "No results for: #{query}", :yellow
  else
    results.each { |m| print_memory(m) }
  end
end

#store(key, value) ⇒ Object



288
289
290
291
292
# File 'lib/agentd/cli.rb', line 288

def store(key, value)
  parsed = (JSON.parse(value) rescue value)
  build_agent(options).memory_store(key, parsed, namespace: options[:namespace])
  say "Stored: #{key}", :green
end