class RubyLLM::Task

A tool call that finishes later. Return one from Tool#execute and a chat pauses the call instead of waiting for it, the way it pauses for an approval. Chat#pending_tasks returns the tasks it waits on, and each Chat#complete hands every one back to its tool’s Tool#resume, which returns the call’s result once it has one:

class RequestSignature < RubyLLM::Tool
  description "Sends a contract for signature and reports when it is signed"

  def execute(contract_id:)
    envelope = Signatures.send_for_signature(Contract.find(contract_id))
    RubyLLM::Task.new(status: :input_required, data: { "envelope_id" => envelope.id })
  end

  def resume(task, **)
    envelope = Signatures.find(task.data["envelope_id"])
    envelope.signed? ? "Signed on #{envelope.signed_on}" : task
  end
end

A task is saved with its tool call as to_h, so a Rails chat can pause in one process and resume in another. MCP::Task is the task of an MCP tool call that a server runs in the background.