π LlamaBotRails
Turn any Rails app into an AI Agent in 2 minutes
Chat with a powerful agent that has access to your models, your application context, and can run console commands. All powered by LangGraph + OpenAI.
π₯ See it in action (30-Second Demo)

The agent can:
- π Explore your Rails app (models, routes, controllers)
- πΎ Query and create data via Rails console
- π οΈ Take action on your behalf
- π§ Understand your domain through natural conversation
π Quickstart β
# 1. Add the gem
bundle add llama_bot_rails
# 2. Install the routes & chat interface
rails generate llama_bot_rails:install
# 3.Run the LlamaBot backend easily with Docker
docker run \
-e OPENAI_API_KEY=(your-key) \
-p 8000:8000 \
kody06/llamabot-backend
# 7. Start your Rails server.
rails server
# 8. Visit the chat interface and start chatting.
open http://localhost:3000/llama_bot/agent/chat
That's it. β You can now chat with your Rails app like a new assistant.
Try asking:
- "What models do I have in this app?"
- "Show me the User model structure"
- "Create a test user"
- "What are my routes?"
Prerequisites
- Rails 7.0+
- Ruby 2.7+
- Redis (for ActionCable)
- OpenAI API key
βοΈ Rails Integration Note (for LlamaBot Rails Gem)
If you're using the llama_bot_rails Gem with Docker, your Rails app must allow the Docker agent to connect back to it.
Add this to your config/environments/development.rb (if it wasnβt added automatically by the Gem installer):
Rails.application.configure do
config.hosts << /host\.docker\.internal/ # Allow Docker agent to connect to Rails
end
This allows the Docker container to reach http://host.docker.internal:3000, which maps to your Rails app on the host machine.
𧨠Power & Responsibility
β οΈ This gem gives the agent access to your Rails console.
This is incredibly powerful -- and also potentially dangerous in production. Treat it like giving shell access to a developer.
π« Do not deploy this tool to production without understanding the risks to your production data & application.
π‘οΈ Production safety features coming soon
ποΈ Architecture
ββββββββββββββββββββββ WebSocket ββββββββββββββββββββββ
β Rails App β ββββββββββββββββββββββββ β LangGraph β
β (Your App) β β FastAPI (Python) β
ββββββββββββββββββββββ€ ββββββββββββββββββββββ€
β LlamaBotRails β β Agents & Tools β
β Gem β β (LangGraph) β
ββββββββββββββββββββββ ββββββββββββββββββββββ
What happens:
- Rails frontend provides a chat interface
- ActionCable WebSocket handles real-time communication to LangGraph
- LangGraph backend runs the AI agent with access to tools
- Agent executes A sequence of Rails console commands, reasoning throughout the process.
- Results stream back to the chat interface in real-time
π οΈ Customization
Custom State Builder
Control what data your agent sees:
# config/initializers/llama_bot_rails.rb
class CustomAgentStateBuilder < LlamaBotRails::AgentStateBuilder
def build
super.merge({
current_user: @context[:user]&.to_json,
app_version: Rails.application.version,
custom_context: gather_app_context
})
end
private
def gather_app_context
{
model_count: ActiveRecord::Base.subclasses.count,
route_count: Rails.application.routes.routes.count,
environment: Rails.env,
database_name: ActiveRecord::Base.connection_db_config.database
}
end
end
# Configure the gem to use your builder
Rails.application.configure do
config.llama_bot_rails.state_builder_class = "CustomAgentStateBuilder"
end
Environment Configuration
# config/environments/development.rb
Rails.application.configure do
config.llama_bot_rails.enable_console_tool = true
end
# config/environments/production.rb
Rails.application.configure do
config.llama_bot_rails.enable_console_tool = false # Disable in production
end
Principle of Least Priviledge: Whitelisting Controller Actions
Rather than giving the agent full access to your Rails app via the Rails console, You can whitelist controller actions instead.
class PagesController < ApplicationController
include LlamaBotRails::ControllerExtensions
include LlamaBotRails::AgentAuth
# βββ Allow the agent to hit these actions ββββββββββββββββββββββββββββββββ
llama_bot_allow :update #uses llama_bot_rails "authenticate_user_or_agent!" on top of your existing devise authentication.
skip_before_action :authenticate_user_or_agent!, only: [:show] #NOTE: You must change any skip_before_action callbacks that skip devise Authentication, to use :authenticate_user_or_agent!
When you include LlamaBotRails::AgentAuth, the gem aliases any authenticate_
π§ͺ What You Can Build
Developer Assistant
- Code exploration: "Show me how authentication works"
- Data analysis: "How many users signed up this month?"
- Quick prototyping: "Create a basic blog post model"
π§ Under the Hood
Real-Time Communication
- ActionCable WebSocket Real-time Rails <-> Agent communication.
- LangGraph Backend FastAPI + OpenAI tool orchestration
Security
- Secure channel seperation -> Per-session isolation.
- Token expiration and automatic refresh mechanisms
Command Streaming
run_rails_console_command: Execute Ruby code in Rails context
π Requirements
Rails Application
- Rails 7.0+ - Modern Rails version with ActionCable support
- Ruby 2.7+ - Compatible Ruby version
- ActionCable configured - For real-time WebSocket communication
- Redis - Recommended for production ActionCable backend
LangGraph Backend
- Python 3.11+ - Python runtime environment
- FastAPI application - Web framework for the agent backend
- OpenAI API access - For LLM capabilities
- WebSocket support - For real-time bidirectional communication
𧨠Troubleshooting
- Agent not responding? Check that backend is running and OpenAI key is set.
- WebSocket issues? Confirm LLAMABOT_WEBSOCKET_URL matches backend address.
π€ Contributing
We'd love your help making LlamaBotRails better!
How to Contribute
- Fork the repo
- Create a feature branch:
git checkout -b my-new-feature - Make your changes and add tests
- Run the test suite:
bundle exec rspec - Submit a pull request
Development Setup
# Clone the repo
git clone https://github.com/kodykendall/llama_bot_rails
cd llama_bot_rails
# Install dependencies
bundle install
# Run tests
bundle exec rspec
# Test in a real Rails app
cd example_app
bundle exec rails server
π What's Next?
We're just getting started. Coming soon:
- π‘οΈ Enhanced security controls for production deployments
- π§ More built-in tools (scaffolding, API calls, database queries)
- π¨ Customizable chat themes and branding
- π Analytics and monitoring for agent interactions
- π Plugin system for custom tool development
- π€ Multi-agent support for complex workflows
- π Background job integration for long-running tasks
π License
MIT. β free for commercial and personal use.
βοΈ Support the Project!
If LlamaBotRails helped you, give us a star βοΈ and share it with other Rails developers.
This is just the beginning. Let's build the Rails agentic future -- together.
βοΈ Star on GitHub β’ π΄ Fork the repo β’ π¬ Join discussions
Built with β€οΈ by Kody Kendall