Class: ClaudeAgentSDK::AssistantMessage
- Inherits:
-
Object
- Object
- ClaudeAgentSDK::AssistantMessage
- Defined in:
- lib/claude_agent_sdk/types.rb
Overview
Assistant message with content blocks
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#error ⇒ Object
Returns the value of attribute error.
-
#message_id ⇒ Object
Returns the value of attribute message_id.
-
#model ⇒ Object
Returns the value of attribute model.
-
#parent_tool_use_id ⇒ Object
Returns the value of attribute parent_tool_use_id.
-
#session_id ⇒ Object
Returns the value of attribute session_id.
-
#stop_reason ⇒ Object
Returns the value of attribute stop_reason.
-
#usage ⇒ Object
Returns the value of attribute usage.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Instance Method Summary collapse
-
#initialize(content:, model:, parent_tool_use_id: nil, error: nil, usage: nil, message_id: nil, stop_reason: nil, session_id: nil, uuid: nil) ⇒ AssistantMessage
constructor
A new instance of AssistantMessage.
-
#text ⇒ Object
(also: #to_s)
Concatenated text across every TextBlock in this message’s content.
Constructor Details
#initialize(content:, model:, parent_tool_use_id: nil, error: nil, usage: nil, message_id: nil, stop_reason: nil, session_id: nil, uuid: nil) ⇒ AssistantMessage
Returns a new instance of AssistantMessage.
146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/claude_agent_sdk/types.rb', line 146 def initialize(content:, model:, parent_tool_use_id: nil, error: nil, usage: nil, message_id: nil, stop_reason: nil, session_id: nil, uuid: nil) @content = content @model = model @parent_tool_use_id = parent_tool_use_id @error = error # One of: authentication_failed, billing_error, rate_limit, invalid_request, server_error, unknown @usage = usage # Token usage info from the API response @message_id = # Unique message identifier from the API (message.id) @stop_reason = stop_reason # Why the assistant stopped (e.g., "end_turn", "max_tokens") @session_id = session_id # Session the message belongs to @uuid = uuid # Unique message UUID in the session transcript end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
143 144 145 |
# File 'lib/claude_agent_sdk/types.rb', line 143 def content @content end |
#error ⇒ Object
Returns the value of attribute error.
143 144 145 |
# File 'lib/claude_agent_sdk/types.rb', line 143 def error @error end |
#message_id ⇒ Object
Returns the value of attribute message_id.
143 144 145 |
# File 'lib/claude_agent_sdk/types.rb', line 143 def @message_id end |
#model ⇒ Object
Returns the value of attribute model.
143 144 145 |
# File 'lib/claude_agent_sdk/types.rb', line 143 def model @model end |
#parent_tool_use_id ⇒ Object
Returns the value of attribute parent_tool_use_id.
143 144 145 |
# File 'lib/claude_agent_sdk/types.rb', line 143 def parent_tool_use_id @parent_tool_use_id end |
#session_id ⇒ Object
Returns the value of attribute session_id.
143 144 145 |
# File 'lib/claude_agent_sdk/types.rb', line 143 def session_id @session_id end |
#stop_reason ⇒ Object
Returns the value of attribute stop_reason.
143 144 145 |
# File 'lib/claude_agent_sdk/types.rb', line 143 def stop_reason @stop_reason end |
#usage ⇒ Object
Returns the value of attribute usage.
143 144 145 |
# File 'lib/claude_agent_sdk/types.rb', line 143 def usage @usage end |
#uuid ⇒ Object
Returns the value of attribute uuid.
143 144 145 |
# File 'lib/claude_agent_sdk/types.rb', line 143 def uuid @uuid end |
Instance Method Details
#text ⇒ Object Also known as: to_s
Concatenated text across every TextBlock in this message’s content. Returns “” when the message has no text (e.g., a pure tool_use turn).
161 162 163 |
# File 'lib/claude_agent_sdk/types.rb', line 161 def text Array(@content).grep(TextBlock).map(&:text).join("\n\n") end |