Getting Started

Install the engine, configure it, and run your first crew.

Installation

Three steps to get the engine running in your app.

1. Add to your Gemfile

gem 'rcrewai-rails'
$ bundle install

2. Run the install generator

$ rails generate rcrewai:rails:install
$ rails db:migrate

Creates the migrations, adds a configuration initializer, and mounts the engine routes.

3. Manual route setup

Rails.application.routes.draw do
  mount RcrewAI::Rails::Engine => '/rcrewai'
end

The web UI is then at /rcrewai and the API at /rcrewai/api/v1/.

Configuration

Configure the engine and the base RcrewAI gem in an initializer.

RcrewAI::Rails.configure do |config|
  config.job_queue_name = "default"
  config.enable_web_ui = true
  config.async_execution = true
  config.default_llm_provider = "openai"
  config.default_llm_model = "gpt-4"

  # Objects for agent memory (optional)
  config.default_memory_embedder = RCrewAI::Knowledge::Embedder.new
  config.default_memory_store = RCrewAI::Memory::SqliteStore.new(path: "db/rcrewai_memory.sqlite3")
end

# Configure the base rcrewai gem (note the capital C).
# Keys in the environment are read automatically.
RCrewAI.configure(validate: false) do |config|
  config.openai_api_key = ENV["OPENAI_API_KEY"]
end

Your first crew

Generate a crew, define it in Ruby, and run it.

Generate a crew

$ rails generate rcrewai:rails:crew research_team sequential \
    --agents researcher analyst writer \
    --description "Research team for market analysis"

Creates a crew class in app/crews/research_team_crew.rb.

Define a crew programmatically

class ResearchCrew
  include RcrewAI::Rails::CrewBuilder

  crew_name "research_team"
  crew_description "AI-powered research team"
  process_type :sequential # :sequential, :hierarchical, or :consensual

  def setup_agents
    @researcher = create_agent("researcher",
      role: "Senior Research Analyst",
      goal: "Uncover insights and trends",
      backstory: "Expert researcher with years of experience"
    )
    @writer = create_agent("writer",
      role: "Content Writer",
      goal: "Create compelling reports",
      backstory: "Skilled writer specializing in technical content"
    )
  end

  def setup_tasks
    @research_task = create_task("Research latest AI trends",
      expected_output: "Comprehensive research report",
      position: 1
    )
    assign_agent_to_task(@researcher, @research_task)

    @writing_task = create_task("Write executive summary",
      expected_output: "2-page executive summary",
      position: 2
    )
    assign_agent_to_task(@writer, @writing_task)
    add_task_dependency(@writing_task, @research_task)
  end
end

Run it

crew = ResearchCrew.new
execution = crew.execute(topic: "AI in Healthcare")   # async via ActiveJob by default
crew.execute_sync(topic: "AI in Healthcare")           # or run synchronously