Class: Helicone::AgentResult

Inherits:
Object
  • Object
show all
Defined in:
lib/helicone/agent_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, messages:, iterations:, response: nil, max_iterations_reached: false) ⇒ AgentResult

Initialize an agent result

Parameters:

  • Final text response from the agent

  • Full conversation history

  • Number of tool execution loops

  • (defaults to: nil)

    The final API response

  • (defaults to: false)

    Whether the agent hit the iteration limit



14
15
16
17
18
19
20
# File 'lib/helicone/agent_result.rb', line 14

def initialize(content:, messages:, iterations:, response: nil, max_iterations_reached: false)
  @content = content
  @messages = messages
  @iterations = iterations
  @response = response
  @max_iterations_reached = max_iterations_reached
end

Instance Attribute Details

#content ⇒ Object (readonly)

Returns the value of attribute content.



5
6
7
# File 'lib/helicone/agent_result.rb', line 5

def content
  @content
end

#iterations ⇒ Object (readonly)

Returns the value of attribute iterations.



5
6
7
# File 'lib/helicone/agent_result.rb', line 5

def iterations
  @iterations
end

#messages ⇒ Object (readonly)

Returns the value of attribute messages.



5
6
7
# File 'lib/helicone/agent_result.rb', line 5

def messages
  @messages
end

#response ⇒ Object (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/helicone/agent_result.rb', line 5

def response
  @response
end

Instance Method Details

#max_iterations_reached? ⇒ Boolean

Check if the agent hit the iteration limit

Returns:



25
26
27
# File 'lib/helicone/agent_result.rb', line 25

def max_iterations_reached?
  @max_iterations_reached
end

#success? ⇒ Boolean

Check if the agent completed successfully

Returns:



32
33
34
# File 'lib/helicone/agent_result.rb', line 32

def success?
  !@max_iterations_reached && !@content.nil? && !@content.empty?
end

#tool_calls_made ⇒ Integer

Count of tool calls executed during the run

Returns:



39
40
41
# File 'lib/helicone/agent_result.rb', line 39

def tool_calls_made
  @messages.count { |m| m.respond_to?(:role) && m.role == "tool" }
end

#tool_results ⇒ Array<Helicone::Message>

Get all tool result messages from the conversation

Returns:

  • Messages with role "tool"



46
47
48
# File 'lib/helicone/agent_result.rb', line 46

def tool_results
  @messages.select { |m| m.respond_to?(:role) && m.role == "tool" }
end