Module: OllamaAgent::ToolContentParser

Defined in:
lib/ollama_agent/tool_content_parser.rb

Overview

Parses JSON tool lines from assistant prose when OLLAMA_AGENT_PARSE_TOOL_JSON=1 (fallback for weak models).

Defined Under Namespace

Classes: SyntheticToolCall

Constant Summary collapse

KNOWN_TOOLS =
%w[list_files read_file search_code edit_file write_file].freeze

Class Method Summary collapse

Class Method Details

.enabled?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/ollama_agent/tool_content_parser.rb', line 12

def self.enabled?
  ENV["OLLAMA_AGENT_PARSE_TOOL_JSON"] == "1"
end

.synthetic_calls(content) ⇒ Array<SyntheticToolCall>

Returns empty if disabled or no parseable lines.

Returns:



17
18
19
20
21
22
23
24
25
# File 'lib/ollama_agent/tool_content_parser.rb', line 17

def self.synthetic_calls(content)
  return [] unless enabled?
  return [] if content.nil? || content.to_s.strip.empty?

  content.each_line.with_object([]) do |line, calls|
    parsed = parse_json_tool_line(line, calls.size)
    calls << parsed if parsed
  end
end