Class: AgentSandbox::BrowserTools::Base

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
lib/agent_sandbox/browser_tools.rb

Direct Known Subclasses

Back, Click, Eval, Fill, GetText, Open, ReadImage, Reload, Screenshot, Snapshot, Wait

Instance Method Summary collapse

Constructor Details

#initialize(sandbox) ⇒ Base

Returns a new instance of Base.



42
43
44
45
# File 'lib/agent_sandbox/browser_tools.rb', line 42

def initialize(sandbox)
  @sandbox = sandbox
  super()
end

Instance Method Details

#run_ab(args) ⇒ Object

agent-browser emits ‘data:, error:` JSON on –json. Return data on success, a structured error hash otherwise, so the LLM always sees something it can reason about instead of opaque exit-status noise.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/agent_sandbox/browser_tools.rb', line 50

def run_ab(args)
  cmd = "agent-browser " + args.map { |a| Shellwords.escape(a) }.join(" ")
  result = @sandbox.exec(cmd)
  parsed = parse_json(result.stdout) || parse_json(result.stderr)
  if parsed
    if parsed["success"]
      parsed["data"] || {}
    else
      { error: parsed["error"] || "agent-browser reported failure",
        stdout: truncate(result.stdout), stderr: truncate(result.stderr) }
    end
  else
    { error: "non-JSON output", status: result.status,
      stdout: truncate(result.stdout), stderr: truncate(result.stderr) }
  end
end