This document describes the integration of Active Agents AI framework into Dill, providing AI-powered writing assistance features directly in the editor.
The WritingAssistantAgent provides the following AI-powered features:
- Improve Writing: Enhances text quality, clarity, and engagement
- Grammar Check: Corrects grammar, punctuation, and spelling errors
- Style Adjustment: Adjusts writing style and tone based on guidelines
- Summarize: Creates concise summaries of longer texts
- Expand: Elaborates and expands on existing content
- Brainstorm: Generates creative ideas and suggestions
The FileAnalyzerAgent provides document analysis capabilities:
- PDF Analysis: Extracts and analyzes content from PDF files
- Image Analysis: Describes and analyzes images using vision models
- Text Extraction: Extracts text from various file formats
- Document Summarization: Creates summaries of uploaded documents
Added to Gemfile:
# AI Integration
gem "activeagent"
gem "ruby-openai" # For OpenAI support
gem "ruby-anthropic" # For Anthropic/Claude support
gem "pdf-reader" # For PDF analysisCreated config/active_agent.yml with support for multiple AI providers:
development:
openai:
service: "OpenAI"
api_key: <%= ENV['OPENAI_API_KEY'] %>
model: "gpt-4o-mini"
anthropic:
service: "Anthropic"
api_key: <%= ENV['ANTHROPIC_API_KEY'] %>
model: "claude-3-5-sonnet-latest"Add to .env:
OPENAI_API_KEY=your_openai_api_key_here
ANTHROPIC_API_KEY=your_anthropic_api_key_here-
Agents (
app/agents/)ApplicationAgent: Base agent configurationWritingAssistantAgent: Writing enhancement featuresFileAnalyzerAgent: File analysis capabilities
-
Controller (
app/controllers/ai_assistants_controller.rb)- RESTful endpoints for each AI action
- JSON responses for frontend integration
- Error handling and authentication
-
Routes (
config/routes.rb)namespace :ai_assistants do post "writing/improve" post "writing/grammar" post "writing/style" post "writing/summarize" post "writing/expand" post "writing/brainstorm" post "analyze_file" end
-
Toolbar Integration (
app/views/pages/_house_toolbar.html.erb)- Added AI action buttons to the House editor toolbar
- Icons and tooltips for each AI feature
- Visual separator for AI tools section
-
Stimulus Controller (
app/javascript/controllers/ai_assistant_controller.js)- Handles button clicks and API calls
- Text selection and replacement
- Loading states and error handling
- Integration with House markdown editor
-
Styling (
app/assets/stylesheets/ai_assistant.css)- Button styling and hover effects
- Loading animations
- Tooltips for AI actions
- Open a page for editing in Dill
- Select text in the editor (or leave unselected to process entire content)
- Click an AI button in the toolbar:
- 🔧 Improve: Enhance writing quality
- ✓ Grammar: Fix grammar and spelling
↔️ Expand: Add more detail- 📝 Summarize: Create a summary
- Add the action to the agent:
# app/agents/writing_assistant_agent.rb
def new_action(content:, options: {})
@content = content
@options = options
prompt
end- Create a prompt template:
# app/views/writing_assistant_agent/new_action.text.erb
Please perform new action on this content:
<%= @content %>- Add controller endpoint:
# app/controllers/ai_assistants_controller.rb
def writing_new_action
agent = WritingAssistantAgent.new
result = agent.new_action(content: params[:content])
render json: { result: result.generate_now }
end- Add route and frontend integration
- Start the Rails server:
bin/dev - Navigate to http://localhost:3011
- Open a book and enter edit mode
- Test each AI feature:
- Select text and click "Improve"
- Click "Grammar" to check entire page
- Use "Expand" on a paragraph
- Generate a summary of the content
- ✅ Active Agent gem installation
- ✅ Agent classes created and configured
- ✅ Controller endpoints functional
- ✅ Toolbar buttons visible in edit mode
- ✅ Stimulus controller binds to buttons
- ✅ API routes configured
┌─────────────┐ ┌──────────────┐ ┌─────────────┐
│ Browser │────▶│ Stimulus │────▶│ Rails │
│ Editor │◀────│ Controller │◀────│ Controller │
└─────────────┘ └──────────────┘ └─────────────┘
│
▼
┌─────────────┐
│ Active │
│ Agents │
└─────────────┘
│
┌────────────┴────────────┐
▼ ▼
┌─────────────┐ ┌─────────────┐
│ OpenAI │ │ Anthropic │
│ API │ │ API │
└─────────────┘ └─────────────┘
-
API Keys Not Working
- Ensure environment variables are set
- Restart Rails server after adding
.env - Check credentials in Rails console
-
Buttons Not Appearing
- Verify you're in edit mode
- Check browser console for JS errors
- Ensure Stimulus controller is loaded
-
AI Requests Failing
- Check Rails logs for errors
- Verify network connectivity
- Ensure API quotas aren't exceeded
- Add streaming responses for real-time feedback
- Implement custom writing style profiles
- Add support for more AI providers (Ollama, etc.)
- Create collaborative AI features
- Add AI-powered search and navigation
- Implement context-aware suggestions
- Add translation capabilities
- Create AI writing analytics
- API keys stored in environment variables
- Authentication required for all AI endpoints
- Rate limiting should be implemented
- Input sanitization for AI prompts
- CSRF protection enabled
- AI requests are asynchronous
- Loading states prevent multiple simultaneous requests
- Responses cached where appropriate
- Text selection preserved during operations
This integration follows the MIT License of the Active Agent gem.