Module: Agents

Defined in:
lib/agents/tool.rb,
lib/agents.rb,
lib/agents/agent.rb,
lib/agents/result.rb,
lib/agents/runner.rb,
lib/agents/handoff.rb,
lib/agents/helpers.rb,
lib/agents/version.rb,
lib/agents/agent_tool.rb,
lib/agents/run_context.rb,
lib/agents/agent_runner.rb,
lib/agents/tool_context.rb,
lib/agents/tool_wrapper.rb,
lib/agents/helpers/headers.rb,
lib/agents/callback_manager.rb,
lib/agents/helpers/message_extractor.rb

Overview

Service object responsible for extracting and formatting conversation messages from RubyLLM chat objects into a format suitable for persistence and context restoration.

Handles different message types:

  • User messages: Basic content preservation

  • Assistant messages: Includes agent attribution and tool calls

  • Tool result messages: Links back to original tool calls

Examples:

Extract messages from a chat

messages = Agents::Helpers::MessageExtractor.extract_messages(chat, current_agent)
#=> [
  { role: :user, content: "Hello" },
  { role: :assistant, content: "Hi!", agent_name: "Support", tool_calls: [...] },
  { role: :tool, content: "Result", tool_call_id: "call_123" }
]

Defined Under Namespace

Modules: Helpers Classes: Agent, AgentRunner, AgentTool, CallbackManager, Configuration, Error, HandoffTool, RunContext, RunResult, Runner, Tool, ToolContext, ToolWrapper

Constant Summary collapse

"# System context\n" \
"You are part of a multi-agent system called the Ruby Agents SDK, designed to make agent " \
"coordination and execution easy. Agents uses two primary abstraction: **Agents** and " \
"**Handoffs**. An agent encompasses instructions and tools and can hand off a " \
"conversation to another agent when appropriate. " \
"Handoffs are achieved by calling a handoff function, generally named " \
"`handoff_to_<agent_name>`. Transfers between agents are handled seamlessly in the background; " \
"do not mention or draw attention to these transfers in your conversation with the user.\n"
VERSION =
"0.7.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject

Logger for debugging (can be set by users)



28
29
30
# File 'lib/agents.rb', line 28

def logger
  @logger
end

Class Method Details

.configurationObject



37
38
39
# File 'lib/agents.rb', line 37

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Configure both Agents and RubyLLM in one block

Yields:



31
32
33
34
35
# File 'lib/agents.rb', line 31

def configure
  yield(configuration) if block_given?
  configure_ruby_llm!
  configuration
end