Class: LittleGhost::Tool::Binding
- Inherits:
-
Object
- Object
- LittleGhost::Tool::Binding
- 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
-
#agent ⇒ Object
readonly
Agent, run, runtime, model, workspace, and sandbox available to a tool.
-
#model ⇒ Object
readonly
Agent, run, runtime, model, workspace, and sandbox available to a tool.
-
#run ⇒ Object
readonly
Agent, run, runtime, model, workspace, and sandbox available to a tool.
-
#runtime ⇒ Object
readonly
Agent, run, runtime, model, workspace, and sandbox available to a tool.
-
#sandbox ⇒ Object
readonly
Agent, run, runtime, model, workspace, and sandbox available to a tool.
-
#workspace ⇒ Object
readonly
Agent, run, runtime, model, workspace, and sandbox available to a tool.
Instance Method Summary collapse
-
#build(*tool_classes) ⇒ Object
Instantiates each supplied tool class against this binding.
-
#initialize(agent: nil, run: nil, runtime: nil, model: nil, workspace: nil, sandbox: nil) ⇒ Binding
constructor
Creates a binding from any available run-scoped collaborators.
-
#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.
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
#agent ⇒ Object (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 |
#model ⇒ Object (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 |
#run ⇒ Object (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 |
#runtime ⇒ Object (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 |
#sandbox ⇒ Object (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 |
#workspace ⇒ Object (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 |