Skip to content
Kward Search API index

Class: Kward::Tools::RetrieveToolOutput

Inherits:
Base
  • Object
show all
Defined in:
lib/kward/tools/retrieve_tool_output.rb

Overview

Retrieves original tool outputs that were compacted out of model context.

Constant Summary collapse

DEFAULT_LIMIT =
120

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#schema

Constructor Details

#initializeRetrieveToolOutput

Builds the retrieval tool schema.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/kward/tools/retrieve_tool_output.rb', line 12

def initialize
  super(
    "retrieve_tool_output",
    "Retrieve original output from a compacted previous tool result.",
    properties: {
      id: { type: "string", description: "Tool output id, for example toolout_abc123." },
      query: { type: "string", description: "Optional case-insensitive text search within the original output." },
      offset: { type: "integer", description: "1-indexed line offset for returned output." },
      limit: { type: "integer", description: "Maximum lines to return; default 120." }
    },
    required: ["id"]
  )
end

Instance Method Details

#call(args, conversation, cancellation: nil) ⇒ Object

Executes retrieval from the active conversation artifact store.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/kward/tools/retrieve_tool_output.rb', line 27

def call(args, conversation, cancellation: nil)
  cancellation&.raise_if_cancelled!
  id = argument(args, :id, "").to_s
  return "Error: id is required" if id.empty?

  artifact = conversation.tool_output_artifacts[id]
  return "Error: unknown tool output id: #{id}" unless artifact

  content = artifact[:content].to_s
  query = argument(args, :query, "").to_s
  lines = query.empty? ? content.split("\n", -1) : matching_lines(content, query)
  return "No matching lines for #{query.inspect} in #{id}." if lines.empty?

  slice_lines(id, lines, offset: argument(args, :offset), limit: argument(args, :limit), query: query)
end