Expand description
§rust_llm_loco
RubyLLM’s Rails integration (acts_as_chat, acts_as_message, acts_as_tool_call, the
rust_llm_models/rust_llm_usages ledgers) for Loco’s default ORM, SeaORM.
class Chat < ApplicationRecord
acts_as_chat
end
chat = Chat.create!(model: "claude-haiku-4-5")
chat.with_tools(Weather).ask("What's the weather in Berlin?")
chat.messages.count # => user, assistant tool call, tool result, assistantuse rust_llm_loco::ChatRecord;
let record = ChatRecord::create(db, "claude-haiku-4-5", None).await?;
let mut chat = record.to_llm(db).await?.with_tool(Weather);
record.ask(db, &mut chat, "What's the weather in Berlin?").await?;
let rows = record.messages(db).await?; // user, assistant tool call, tool result, assistantLike RubyLLM, every message, tool call, and billed attempt is written as it happens, so a
chat can be reloaded mid-round (parked on a tool approval or an MCP input request) and
continued later, and another process can cancel it through the chats.cancelled column. Add
migrations() to your Loco migrator for the tables.
Message attachments live in rust_llm_attachments (bytes plus the filename, content type, and
resolution RubyLLM keeps on the Active Storage blob), since Loco has no Active Storage. See the
persistence guide.
Re-exports§
pub use batch::BatchStore;pub use model_store::ModelStore;
Modules§
- batch
- Port of
lib/ruby_llm/active_record/batch.rb: RustLLM’s persistence for provider-side batches, inrust_llm_batches. With aBatchStoreset asconfig.batch_store(the Railtie setsRubyLLM::ActiveRecord::Batchthere),rust_llm::batch(chats)records the batch and its chats when it is submitted,Batch::find(id)rebuilds it from the row in any process, with the records’ chats attached, andrefresh/cancelwrite the new state back. - entities
- SeaORM entities for the tables
migrationscreates:RubyLLM::ActiveRecord::Model,ToolCall,Usage, and the app’sChat/Message(acts_as_chat/acts_as_message), plusrust_llm_attachments, which stands in for Active Storage, andrust_llm_batches. - migrations
- Port of
rails generate rust_llm:install’s migrations: the same tables and columns, as SeaORM migrations. Addrust_llm_loco::migrations()to your app’sMigrator. - model_
store - Port of
lib/ruby_llm/active_record/model.rb: therust_llm_modelstable as the model registry store. Chats point at a row throughchats.rust_llm_model_id;listedreturns the rows the provider still serves,unlistedthe ones kept only because a chat references them.
Structs§
- Chat
Record - A persisted chat: the
Chatmodel thatacts_as_chat. - McpCredential
Store RubyLLM::ActiveRecord::MCPCredentialas aCredentialStore.- Provider
File RubyLLM::ActiveRecord::ProviderFile.- Usage
Ledger rust_llm_usagesasAccounting::Usage.ledger(Ruby’s railtie setsRubyLLM::ActiveRecord::Usagethere). Rows belong to no chat and keep their owner when it is a record (rust_llm::accounting::UsageOwner::Record).
Enums§
- Error
- Stream
Event - What
ChatRecord::complete_streamreports while it runs: RubyLLM’son_new_message, each streamed chunk, andon_end_message, each with themessagesrow it belongs to.
Constants§
- CANCELLATION_
POLL_ INTERVAL ChatMethods::CANCELLATION_POLL_INTERVAL: how often a runningcompletereads thechats.cancelledcolumn another process may have set.- CHAT_
TYPE - The polymorphic type names written into
message_type/chat_type, like Rails’ class names. - MESSAGE_
TYPE
Functions§
- find_
or_ create_ model ChatMethods#find_or_create_model:Model.find_or_create_by!(provider:, model_id:)with the registry’s metadata, reusing the row another process inserted between the lookup and the insert.- insert_
model - The insert half of
find_or_create_model, after its lookup missed: inserts the row, or returns the one another process inserted in between (the unique index rejects ours). - message_
to_ llm message.to_llmfor amessagesrow read from the database: its tool calls, the tool call it answers, attachments, and usage entries are loaded with it, somodel,model_info, and the finish predicates answer as they do on the in-memory message.- migrations
- The Rust migrations to append to an app’s
Migrator::migrations(). - purge_
attachments message.attachments.purge: deletes the attachment rows of these messages and, like theafter_destroyhook RubyLLM puts on Active Storage blobs, the provider uploads recorded against them (ProviderFile.forget_blob).- tool_
error_ message tool_error_message(PayloadHelpers#payload_error_message): theerrorof a JSON object payload, such as a failed tool result’s content or a tool call’s arguments, orNone.