Class: LittleGhost::Tool::Binding

Inherits:
Object
  • Object
show all
Defined in:
lib/little_ghost/tool.rb

Overview

Supply run-scoped collaborators when tools are instantiated outside an agent. A binding can be copied with selected collaborators replaced.

Tool instances expose the bound agent, run, runtime, model, workspace, and sandbox through matching accessors. ToolRegistry and Agent normally create bindings on behalf of application code.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent: nil, run: nil, runtime: nil, model: nil, workspace: nil, sandbox: nil) ⇒ Binding

Creates a binding from any available run-scoped collaborators.



55
56
57
58
59
60
61
62
# File 'lib/little_ghost/tool.rb', line 55

def initialize(agent: nil, run: nil, runtime: nil, model: nil, workspace: nil, sandbox: nil)
  @agent = agent
  @run = run
  @runtime = runtime
  @model = model
  @workspace = workspace
  @sandbox = sandbox
end

Instance Attribute Details

#agentObject (readonly)

Agent, run, runtime, model, workspace, and sandbox available to a tool.



52
53
54
# File 'lib/little_ghost/tool.rb', line 52

def agent
  @agent
end

#modelObject (readonly)

Agent, run, runtime, model, workspace, and sandbox available to a tool.



52
53
54
# File 'lib/little_ghost/tool.rb', line 52

def model
  @model
end

#runObject (readonly)

Agent, run, runtime, model, workspace, and sandbox available to a tool.



52
53
54
# File 'lib/little_ghost/tool.rb', line 52

def run
  @run
end

#runtimeObject (readonly)

Agent, run, runtime, model, workspace, and sandbox available to a tool.



52
53
54
# File 'lib/little_ghost/tool.rb', line 52

def runtime
  @runtime
end

#sandboxObject (readonly)

Agent, run, runtime, model, workspace, and sandbox available to a tool.



52
53
54
# File 'lib/little_ghost/tool.rb', line 52

def sandbox
  @sandbox
end

#workspaceObject (readonly)

Agent, run, runtime, model, workspace, and sandbox available to a tool.



52
53
54
# File 'lib/little_ghost/tool.rb', line 52

def workspace
  @workspace
end

Instance Method Details

#build(*tool_classes) ⇒ Object

Instantiates each supplied tool class against this binding.



71
72
73
# File 'lib/little_ghost/tool.rb', line 71

def build(*tool_classes)
  tool_classes.flatten.map { |tool_class| tool_class.new(binding: self) }
end

#with(agent: self.agent, run: self.run, runtime: self.runtime, model: self.model, workspace: self.workspace, sandbox: self.sandbox) ⇒ Object

Copies the binding, replacing only the supplied collaborators.



65
66
67
68
# File 'lib/little_ghost/tool.rb', line 65

def with(agent: self.agent, run: self.run, runtime: self.runtime, model: self.model,
  workspace: self.workspace, sandbox: self.sandbox)
  self.class.new(agent:, run:, runtime:, model:, workspace:, sandbox:)
end