Class: Truffle::Providers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/truffle/providers/base.rb

Overview

The contract every provider implements. This single seam is what makes Truffle provider-agnostic: the agent loop only ever calls #chat and reads a Truffle::Response back. Swapping OpenAI for Anthropic or a local model is a one-line change at construction time. Every provider is written from scratch against this seam; there are no runtime gem dependencies.

Subclasses must implement #chat. They are free to translate Truffle::Message objects and tool schemas into their native wire format however they like.

Direct Known Subclasses

OpenAI

Instance Method Summary collapse

Instance Method Details

#chat(messages:, tools: [], model: nil, **options) ⇒ Truffle::Response

Parameters:

  • messages (Array<Truffle::Message>)

    the conversation so far

  • tools (Array<Hash>) (defaults to: [])

    provider-neutral tool schemas (Toolbox#to_schema)

  • model (String, nil) (defaults to: nil)

    override the default model for this call

Returns:

Raises:

  • (NotImplementedError)


18
19
20
# File 'lib/truffle/providers/base.rb', line 18

def chat(messages:, tools: [], model: nil, **options)
  raise NotImplementedError, "#{self.class} must implement #chat"
end

#nameObject

Human-readable provider id, used in events and errors.



23
24
25
# File 'lib/truffle/providers/base.rb', line 23

def name
  self.class.name.split("::").last.downcase
end