Class: RubyLLM::Agents::ToolContext
- Inherits:
-
Object
- Object
- RubyLLM::Agents::ToolContext
- Defined in:
- lib/ruby_llm/agents/tool_context.rb
Overview
Read-only wrapper around Pipeline::Context for tool authors.
Exposes agent params and execution metadata to tools without leaking pipeline internals. Supports both method-style and hash-style access to agent params.
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Hash-style access to agent params.
-
#agent_type ⇒ String?
Agent class name.
-
#id ⇒ Integer?
Execution record ID — links tool calls to the agent execution.
-
#initialize(pipeline_context) ⇒ ToolContext
constructor
A new instance of ToolContext.
-
#tenant_id ⇒ String?
Tenant ID from the pipeline context.
Constructor Details
#initialize(pipeline_context) ⇒ ToolContext
Returns a new instance of ToolContext.
48 49 50 51 |
# File 'lib/ruby_llm/agents/tool_context.rb', line 48 def initialize(pipeline_context) @ctx = pipeline_context @agent_options = @ctx.agent_instance&.send(:options) || {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object (private)
Method-style access to agent params
56 57 58 59 60 61 62 63 |
# File 'lib/ruby_llm/agents/tool_context.rb', line 56 def method_missing(method_name, *args) key = method_name.to_sym if @agent_options.key?(key) || @agent_options.key?(key.to_s) self[key] else super end end |
Instance Method Details
#[](key) ⇒ Object?
Hash-style access to agent params
44 45 46 |
# File 'lib/ruby_llm/agents/tool_context.rb', line 44 def [](key) @agent_options[key.to_sym] || @agent_options[key.to_s] end |
#agent_type ⇒ String?
Agent class name
36 37 38 |
# File 'lib/ruby_llm/agents/tool_context.rb', line 36 def agent_type @ctx.agent_class&.name end |
#id ⇒ Integer?
Execution record ID — links tool calls to the agent execution
22 23 24 |
# File 'lib/ruby_llm/agents/tool_context.rb', line 22 def id @ctx.execution_id end |
#tenant_id ⇒ String?
Tenant ID from the pipeline context
29 30 31 |
# File 'lib/ruby_llm/agents/tool_context.rb', line 29 def tenant_id @ctx.tenant_id end |