Class: SwarmSDK::V3::Hooks::Context
- Inherits:
-
Object
- Object
- SwarmSDK::V3::Hooks::Context
- Defined in:
- lib/swarm_sdk/v3/hooks/context.rb
Overview
Read-only context passed to hook blocks
Each hook event type populates a different subset of fields:
| Field | before_ask | after_ask | before_tool | after_tool | on_stop | |—————–|————|———–|————-|————|———| | event | yes | yes | yes | yes | yes | | agent_name | yes | yes | yes | yes | yes | | prompt | yes | yes | - | - | - | | response | - | yes | - | - | yes | | tool_name | - | - | yes | yes | - | | tool_arguments | - | - | yes | yes | - | | tool_result | - | - | - | yes | - |
Hook blocks use convenience methods to return Result objects:
Instance Attribute Summary collapse
-
#agent_name ⇒ Symbol
readonly
Agent name from definition.
-
#event ⇒ Symbol
readonly
Event type (:before_ask, :after_ask, :before_tool, :after_tool, :on_stop).
-
#prompt ⇒ String?
readonly
User prompt (ask events only).
-
#response ⇒ RubyLLM::Message?
readonly
LLM response (after_ask and on_stop only).
-
#tool_arguments ⇒ Hash?
readonly
Tool call arguments (tool events only).
-
#tool_name ⇒ String?
readonly
Tool name (tool events only).
-
#tool_result ⇒ Object?
readonly
Tool execution result (after_tool only).
Instance Method Summary collapse
-
#continue ⇒ Result
Signal to continue normal processing.
-
#halt(message = nil) ⇒ Result
Signal to halt processing.
-
#initialize(event:, agent_name:, prompt: nil, response: nil, tool_name: nil, tool_arguments: nil, tool_result: nil) ⇒ Context
constructor
Create a new hook context.
-
#replace(value) ⇒ Result
Signal to replace a value.
Constructor Details
#initialize(event:, agent_name:, prompt: nil, response: nil, tool_name: nil, tool_arguments: nil, tool_result: nil) ⇒ Context
Create a new hook context
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/swarm_sdk/v3/hooks/context.rb', line 61 def initialize(event:, agent_name:, prompt: nil, response: nil, tool_name: nil, tool_arguments: nil, tool_result: nil) @event = event @agent_name = agent_name @prompt = prompt @response = response @tool_name = tool_name @tool_arguments = tool_arguments @tool_result = tool_result freeze end |
Instance Attribute Details
#agent_name ⇒ Symbol (readonly)
Returns Agent name from definition.
35 36 37 |
# File 'lib/swarm_sdk/v3/hooks/context.rb', line 35 def agent_name @agent_name end |
#event ⇒ Symbol (readonly)
Returns Event type (:before_ask, :after_ask, :before_tool, :after_tool, :on_stop).
32 33 34 |
# File 'lib/swarm_sdk/v3/hooks/context.rb', line 32 def event @event end |
#prompt ⇒ String? (readonly)
Returns User prompt (ask events only).
38 39 40 |
# File 'lib/swarm_sdk/v3/hooks/context.rb', line 38 def prompt @prompt end |
#response ⇒ RubyLLM::Message? (readonly)
Returns LLM response (after_ask and on_stop only).
41 42 43 |
# File 'lib/swarm_sdk/v3/hooks/context.rb', line 41 def response @response end |
#tool_arguments ⇒ Hash? (readonly)
Returns Tool call arguments (tool events only).
47 48 49 |
# File 'lib/swarm_sdk/v3/hooks/context.rb', line 47 def tool_arguments @tool_arguments end |
#tool_name ⇒ String? (readonly)
Returns Tool name (tool events only).
44 45 46 |
# File 'lib/swarm_sdk/v3/hooks/context.rb', line 44 def tool_name @tool_name end |
#tool_result ⇒ Object? (readonly)
Returns Tool execution result (after_tool only).
50 51 52 |
# File 'lib/swarm_sdk/v3/hooks/context.rb', line 50 def tool_result @tool_result end |
Instance Method Details
#continue ⇒ Result
Signal to continue normal processing
78 79 80 |
# File 'lib/swarm_sdk/v3/hooks/context.rb', line 78 def continue Result.continue end |