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. A Binding does not carry model Tool arguments or application state; the current RunContext carries that state. 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.



97
98
99
100
101
102
103
104
# File 'lib/little_ghost/tool.rb', line 97

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.



94
95
96
# File 'lib/little_ghost/tool.rb', line 94

def agent
  @agent
end

#modelObject (readonly)

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



94
95
96
# File 'lib/little_ghost/tool.rb', line 94

def model
  @model
end

#runObject (readonly)

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



94
95
96
# File 'lib/little_ghost/tool.rb', line 94

def run
  @run
end

#runtimeObject (readonly)

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



94
95
96
# File 'lib/little_ghost/tool.rb', line 94

def runtime
  @runtime
end

#sandboxObject (readonly)

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



94
95
96
# File 'lib/little_ghost/tool.rb', line 94

def sandbox
  @sandbox
end

#workspaceObject (readonly)

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



94
95
96
# File 'lib/little_ghost/tool.rb', line 94

def workspace
  @workspace
end

Instance Method Details

#build(*tool_classes) ⇒ Object

Instantiates each supplied tool class against this binding.



113
114
115
# File 'lib/little_ghost/tool.rb', line 113

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.



107
108
109
110
# File 'lib/little_ghost/tool.rb', line 107

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