Class: Parse::Agent::MCPClient::Result

Inherits:
Struct
  • Object
show all
Defined in:
lib/parse/agent/mcp_client.rb

Overview

Result of an ‘ask` / `reply` call.

  • ‘text` is the LLM’s final-turn answer.

  • ‘tool_calls` is the ordered list of tools invoked, each with its arguments and the dispatcher’s response.

  • ‘transcript` is the full message log (useful for debugging).

  • ‘usage` is a Usage struct for this single call (sum across all LLM turns the round-trip required).

  • ‘reply(question)` continues the conversation that produced this result. Chain freely: `mcp.ask(“a”).reply(“b”).reply(“c”)`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clientObject

Returns the value of attribute client

Returns:

  • (Object)

    the current value of client



57
58
59
# File 'lib/parse/agent/mcp_client.rb', line 57

def client
  @client
end

#textObject

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



57
58
59
# File 'lib/parse/agent/mcp_client.rb', line 57

def text
  @text
end

#tool_callsObject

Returns the value of attribute tool_calls

Returns:

  • (Object)

    the current value of tool_calls



57
58
59
# File 'lib/parse/agent/mcp_client.rb', line 57

def tool_calls
  @tool_calls
end

#transcriptObject

Returns the value of attribute transcript

Returns:

  • (Object)

    the current value of transcript



57
58
59
# File 'lib/parse/agent/mcp_client.rb', line 57

def transcript
  @transcript
end

#usageObject

Returns the value of attribute usage

Returns:

  • (Object)

    the current value of usage



57
58
59
# File 'lib/parse/agent/mcp_client.rb', line 57

def usage
  @usage
end

Instance Method Details

#reply(question) ⇒ Result

Continue this conversation. Equivalent to calling ‘client.ask(question, reset: false)`.

Parameters:

Returns:



62
63
64
65
# File 'lib/parse/agent/mcp_client.rb', line 62

def reply(question)
  raise "Result has no associated client (constructed outside MCPClient)" unless client
  client.ask(question, reset: false)
end

#to_sObject Also known as: inspect

Pretty-print for IRB: tool trace, answer, then per-call usage line.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/parse/agent/mcp_client.rb', line 68

def to_s
  parts = []
  if tool_calls.any?
    parts << "─── tool calls (#{tool_calls.size}) ───"
    tool_calls.each_with_index do |tc, i|
      args_str = tc[:arguments].is_a?(Hash) ? tc[:arguments].inspect : tc[:arguments].to_s
      parts << "  #{i + 1}. #{tc[:name]}(#{args_str})"
    end
  end
  parts << "─── answer ───"
  parts << text.to_s
  parts << "─── usage ───" << "  #{usage}" if usage && usage.total_tokens.positive?
  parts.join("\n")
end