class

Finfry::AI

Inherits Reference < Object

The seam between finfry and an AI service. Backed by raw HTTPS calls to the Claude Messages API with tool use (no SDK dependency). finfry exposes its commands as tools; the model reads the ledger and proposes changes, and the caller's block executes each tool call. The whole provider conversation lives behind converse, so the backing implementation can later be swapped for a multi-provider library without touching the command layer.

Request building and turn parsing are pure (testable without network).

Constants

ANTHROPIC_VERSION = "2023-06-01"
API_URL = "https://api.anthropic.com/v1/messages"
DEFAULT_MODEL = "claude-opus-4-8"
MAX_TOKENS = 4096
MAX_TURNS = 16

Constructors

from_env
Source
new(api_key : String, model : String = DEFAULT_MODEL)
Source

Class methods

parse_turn(response : JSON::Any) : Turn

Pure: extract text, tool calls, and done-ness from a response document.

Source

Instance methods

build_request(system : String, tools : Array(ToolDef), messages : Array(String)) : String

The JSON request body. Public for testing.

Source
converse(prompt : String, *, system : String, tools : Array(ToolDef), & : ToolCall -> ToolOutcome) : String

Drive a tool-use conversation. The block runs each tool call and returns its outcome (reads execute and return output; writes can be deferred). Returns the model's final text answer.

Source

Nested types