From 31a003580e154aa1750d829a72bc05b0ee0921e2 Mon Sep 17 00:00:00 2001 From: Sebastian Arrieta <25210925+sarrietav-dev@users.noreply.github.com> Date: Fri, 20 Mar 2026 15:51:13 -0500 Subject: [PATCH] Document usage of existing Chat record with Agent Added instructions for using an existing Chat record with Agent. --- docs/_core_features/agents.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/_core_features/agents.md b/docs/_core_features/agents.md index b5ffbcb97..e1ccea5fa 100644 --- a/docs/_core_features/agents.md +++ b/docs/_core_features/agents.md @@ -281,6 +281,15 @@ Instruction persistence contract in Rails mode: * `find` applies instructions at runtime only (no persistence side effects) * `sync_instructions!` explicitly persists the current agent instructions +### Using an Existing Chat Record +If you already have a `Chat` record, pass it to `Agent.new(chat:)` instead of calling `Agent.find`. This applies all agent configuration (instructions, tools, etc.) without an extra database query: + +```ruby +chat_record = Chat.find(params[:id]) +chat = WorkAssistant.new(chat: chat_record) +chat.ask("Hello") +``` + ## When to Use Agents vs `RubyLLM.chat` Use `RubyLLM.chat` for one-off, inline conversations: