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. 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.
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
#agent ⇒ Object (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 |
#model ⇒ Object (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 |
#run ⇒ Object (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 |
#runtime ⇒ Object (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 |
#sandbox ⇒ Object (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 |
#workspace ⇒ Object (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 |