Module: Ragents

Defined in:
lib/ragents.rb,
lib/ragents/tool.rb,
lib/ragents/agent.rb,
lib/ragents/context.rb,
lib/ragents/message.rb,
lib/ragents/railtie.rb,
lib/ragents/version.rb,
lib/ragents/provider.rb,
lib/ragents/orchestrator.rb,
lib/ragents/providers/test.rb,
lib/ragents/providers/ruby_llm.rb

Overview

Ragents - A Ractor-based AI agent framework

Ragents provides concurrent, isolated agent execution using Ruby’s Ractor primitive. It uses RubyLLM as the LLM backend, giving access to 500+ models across all major providers (OpenAI, Anthropic, Gemini, Ollama, etc.)

Examples:

Define and run an agent

class MyAgent < Ragents::Agent
  system_prompt "You are a helpful assistant."

  tool :greet do
    description "Greet someone by name"
    parameter :name, type: :string, required: true
    execute { |name:| "Hello, #{name}!" }
  end
end

# Configure RubyLLM first
RubyLLM.configure do |config|
  config.openai_api_key = ENV["OPENAI_API_KEY"]
end

provider = Ragents::Providers::RubyLLM.new(model: "gpt-4o")
agent = MyAgent.new(provider: provider)
result = agent.run(input: "Greet the user named Alice")

Defined Under Namespace

Modules: Providers Classes: Agent, Configuration, Context, Error, MaxIterationsError, Message, Orchestrator, Provider, Railtie, Response, SupervisorError, Tool, ToolCall, ToolRegistry, Workflow

Constant Summary collapse

VERSION =
"0.2.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



35
36
37
# File 'lib/ragents.rb', line 35

def configuration
  @configuration
end

Class Method Details

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

Yields:



37
38
39
40
41
# File 'lib/ragents.rb', line 37

def configure
  self.configuration ||= Configuration.new
  yield(configuration) if block_given?
  configuration
end

.execute_on_main(&block) ⇒ Object

Execute a block on the main thread from within a Ractor This is used for operations that can’t run in Ractors



45
46
47
48
49
50
51
# File 'lib/ragents.rb', line 45

def execute_on_main(&block)
  if Ractor.current == Ractor.main
    block.call
  else
    raise Error, "Main thread execution from Ractor requires setup of main_executor"
  end
end

.provider(name) ⇒ Object



62
63
64
# File 'lib/ragents.rb', line 62

def provider(name)
  providers[name.to_sym]
end

.providersObject

Default provider registry



54
55
56
# File 'lib/ragents.rb', line 54

def providers
  @providers ||= {}
end

.register_provider(name, provider) ⇒ Object



58
59
60
# File 'lib/ragents.rb', line 58

def register_provider(name, provider)
  providers[name.to_sym] = provider
end