Class: Agents::ToolContext
- Inherits:
-
Object
- Object
- Agents::ToolContext
- Defined in:
- lib/agents/tool_context.rb
Instance Attribute Summary collapse
-
#retry_count ⇒ Object
readonly
Returns the value of attribute retry_count.
-
#run_context ⇒ Object
readonly
Returns the value of attribute run_context.
Instance Method Summary collapse
-
#context ⇒ Hash
Convenient access to the shared context hash from the RunContext.
-
#initialize(run_context:, retry_count: 0) ⇒ ToolContext
constructor
Initialize a new ToolContext wrapping a RunContext.
-
#state ⇒ Hash
Convenient access to the shared state hash within the context.
-
#usage ⇒ Agents::RunContext::Usage
Convenient access to the usage tracking object from the RunContext.
Constructor Details
#initialize(run_context:, retry_count: 0) ⇒ ToolContext
Initialize a new ToolContext wrapping a RunContext
61 62 63 64 |
# File 'lib/agents/tool_context.rb', line 61 def initialize(run_context:, retry_count: 0) @run_context = run_context @retry_count = retry_count end |
Instance Attribute Details
#retry_count ⇒ Object (readonly)
Returns the value of attribute retry_count.
55 56 57 |
# File 'lib/agents/tool_context.rb', line 55 def retry_count @retry_count end |
#run_context ⇒ Object (readonly)
Returns the value of attribute run_context.
55 56 57 |
# File 'lib/agents/tool_context.rb', line 55 def run_context @run_context end |
Instance Method Details
#context ⇒ Hash
Convenient access to the shared context hash from the RunContext. This delegation makes it easier for tools to access context data without having to navigate through run_context.context.
77 78 79 |
# File 'lib/agents/tool_context.rb', line 77 def context @run_context.context end |
#state ⇒ Hash
Convenient access to the shared state hash within the context. This provides tools with a dedicated space to store and retrieve state that persists across agent interactions within a conversation.
State is automatically initialized as an empty hash if it doesn’t exist. All state modifications are automatically included in context serialization, making it persist across process boundaries (e.g., Rails with ActiveRecord).
130 131 132 |
# File 'lib/agents/tool_context.rb', line 130 def state context[:state] ||= {} end |
#usage ⇒ Agents::RunContext::Usage
Convenient access to the usage tracking object from the RunContext. Tools can use this to add their own usage metrics if they make additional LLM calls.
94 95 96 |
# File 'lib/agents/tool_context.rb', line 94 def usage @run_context.usage end |