class RubyLLM::AgentTool

The Tool an Agent class becomes when it goes wherever tools go, so a model can hand work to it: a subagent. Agent::to_tool returns one, and Chat#with_tools and Agent::tools convert an Agent class themselves.

class ResearchAgent < RubyLLM::Agent
  description "Researches a question across the web and reports back"
  tools WebSearch, ReadPage
end

chat.with_tools(ResearchAgent).ask "What changed in Ruby 4.0?"

The tool is named after the agent (research_agent, or billing_research_agent for Billing::ResearchAgent) and takes a task, everything the agent needs written to stand alone, plus the agent’s ::inputs that ::to_tool was not given. Each call runs a fresh instance of the agent on the task, under the owner of the chat that called it, and returns the content of its last answer.

The agent lives only as long as its call, so it has to finish within it. When it stops to wait instead, for an approval, a question, or a task, the call raises ConfigurationError. To let a subagent wait for a person, give it a chat of its own, as the Agents guide shows.