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. When the agent waits, for an approval, a question, or a task of its own, the call pauses on an AgentTask instead, and Chat#complete carries the agent on once nothing holds it.