SolidAgent extends the ActiveAgent framework with enterprise-grade features for building robust AI agents in Rails applications. It provides three core concerns that add database-backed persistence, declarative tool schemas, and real-time streaming capabilities to your agents.
- HasContext - Database-backed prompt context management for maintaining conversation history and agent state
- HasTools - Declarative, schema-based tool definitions compatible with LLM function-calling APIs
- StreamsToolUpdates - Real-time UI feedback during tool execution via ActionCable
Add this line to your application's Gemfile:
gem "solid_agent"And then execute:
$ bundle installOr install it yourself as:
$ gem install solid_agentGenerate a new agent with context support:
$ rails generate solid_agent:agent WritingAssistant --context --context_name conversation --contextable userAdd database-backed context management to your agents:
class WritingAssistantAgent < ApplicationAgent
include SolidAgent::HasContext
has_context :conversation, contextable: :user
def improve
load_conversation(contextable: current_user)
add_conversation_user_message(params[:message])
prompt messages: conversation_messages
end
endThis generates helper methods like:
load_conversation(contextable:)- Load or create a contextconversation_messages- Get formatted message historyadd_conversation_user_message(content)- Add a user messageadd_conversation_assistant_message(content)- Add an AI responseconversation_result- Get the last assistant message
Define tools inline with a clean DSL:
class ResearchAgent < ApplicationAgent
include SolidAgent::HasTools
tool :search do
description "Search for information"
parameter :query, type: :string, required: true
parameter :limit, type: :integer, default: 10
end
def research
prompt tools: tools
end
def search(query:, limit: 10)
# Tool implementation
end
endOr use JSON templates in app/views/research_agent/tools/search.json.erb.
Broadcast tool execution status to your UI:
class BrowserAgent < ApplicationAgent
include SolidAgent::HasTools
include SolidAgent::StreamsToolUpdates
has_tools :navigate, :click
tool_description :navigate, ->(args) { "Visiting #{args[:url]}..." }
end# Generate a new agent
$ rails generate solid_agent:agent MyAgent
# Generate with context support
$ rails generate solid_agent:agent MyAgent --context --context_name session
# Generate a tool template
$ rails generate solid_agent:tool search MyAgent --parameters query:string:required
# Generate context models
$ rails generate solid_agent:context conversationSee SolidAgent in action:
- Fizzy - AI-enhanced Kanban tracking tool with writing, research, and file analysis agents
- Writebook - Collaborative writing platform with integrated AI writing assistance, research, and document analysis
After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/activeagents/solid_agent.
