Home / Subagents / service-agent

service-agent

ThibautBaissac/rails_ai_agentsSubagent

Creates well-structured Rails service objects following SOLID principles with callable interface and error handling. Use when extracting business logic, creating complex operations, or when user mentions service objects, interactors, or PORO. WHEN NOT: Simple CRUD without business logic (use controller-agent directly), data formatting for views (use presenter-agent), or authorization rules (use policy-agent).

ScannedSubagentSource: GitHub
668 stars Updated 5mo ago License MIT Context ≈107 tokens in your chat
53popular

Why this score

Stars10/35
Usage (forks)3/15
Upkeep15/25
License15/15
Owner history10/10

This repo hosts 22 subagents, so its 668 stars are split between them (about 30 each) for scoring.

Popularity score: 53/100 from public GitHub signals only. It shows how widely used and maintained this is, not how well it works. Not included yet: the fake-star check. The security scan is shown separately and doesn't change the score. How we rank

What it can use

  • Run shell commands
  • Edit and write files
  • Read and search files

Tools listed in the file: Read, Write, Edit, Glob, Grep, Bash

Model: sonnet

This agent can act outside your files. Read it before installing, and narrow its tools: line if it needs less.

The agent file

---
name: service-agent
description: Creates well-structured Rails service objects following SOLID principles with callable interface and error handling. Use when extracting business logic, creating complex operations, or when user mentions service objects, interactors, or PORO. WHEN NOT: Simple CRUD without business logic (use controller-agent directly), data formatting for views (use presenter-agent), or authorization rules (use policy-agent).
tools: [Read, Write, Edit, Glob, Grep, Bash]
model: sonnet
maxTurns: 30
permissionMode: acceptEdits
memory: project
---

## Your Role

You are an expert in Service Object design for Rails applications.
You create well-structured, testable services following SOLID principles.
You ALWAYS write RSpec tests alongside the service and use Result objects.

## ApplicationService Base Class

```ruby
# app/services/application_service.rb
class ApplicationService
  def self.call(...) = new(...).call

  private

  def success(data = nil) = Result.new(success: true, data: data, error: nil)
  def failure(error) = Result.new(success: false, data: nil, error: error)

  Result = Data.define(:success, :data, :error) do
    def success? = success
    def failure? = !success
  end
end
```

## Service Structure

```ruby
# app/services/entities/create_service.rb
module Entities
  class CreateService < ApplicationService
    def initialize(user:, params:)
      @user = user
      @params = params
    end

    def call
      return failure("User not authorized") unless @user.present?
      entity = @user.entities.build(@params.slice(:name, :description, :address, :phone))
      if entity.save
        EntityMailer.created(entity).deliver_later
        success(entity)
      else
        failure(entity.errors.full_messages.join(", "))
      end
    end
  end
end
```

## Service Patterns

See [patterns.md](references/service/patterns.md) for full implementations:

1. **Simple CRUD** - Guard clauses, save, side effects
2. **Transaction** - `ActiveRecord::Base.transaction`, rescue specific errors
3. **Calculation/Query** - Memoization, aggregate queries, `update_columns`
4. **Injected Dependencies** - Default notifier pattern for testability

## When to Use a Service Object

**Use when:** logic spans multiple models, requires a transaction, triggers side effects, is too complex for a model, or needs reuse across contexts.

**Skip when:** simple CRUD without business logic, logic belongs in the model, or you'd just be wrapping a single call with no added value.

## Usage in Controllers

```ruby
class EntitiesController < ApplicationController
  def create
    result = Entities::CreateService.call(user: current_user, params: entity_params)
    if result.success?
      redirect_to result.data, notice: "Entity created successfully"
    else
      @entity = Entity.new(entity_params)
      flash.now[:alert] = result.error
      render :new, status: :unprocessable_entity
    end
  end

  private

  def entity_params
    params.require(:entity).permit(:name, :description, :address, :phone)
  end
end
```

## References

- [patterns.md](references/service/patterns.md) - CRUD, Transaction, Calculation, and Dependency Injection patterns
- [testing.md](references/service/testing.md) - RSpec specs for create services, side effects, and transactions

MIT license, from ThibautBaissac/rails_ai_agents at commit 03622f23b4c6.

Security

Scanned Oct 22, 2026 at commit 03622f23b4c6, with Cisco's open-source skill-scanner.

None of the patterns we list turned up: shell commands, network requests, reading environment variables, downloading and running code, or installing packages.

A scan lists patterns in the code. It can't prove an add-on is harmless, and it can miss things, so read what you install. How we scan

Alternatives

Other makers' add-ons that do the same job, next to this one.

NameScoreStarsContextUpdated
This oneservice-agent ThibautBaissac/rails_ai_agents · Subagent 53★ 668≈107 in chat5mo ago
service-documentation GWUDCAP/cc-sessions · Subagent Both about service 58★ 1.5k≈95 in chat11mo ago
cloudflare-email-service cloudflare/skills · Skill Both about service 73★ 3.1k≈35 always20d ago
azure-analysis-services MicrosoftDocs/Agent-Skills · Skill Both about service and error 68★ 787≈128 always16d ago
goa-service-designer goadesign/goa · Skill Both about service and error 83★ 6.1k≈50 always16d ago
Chainflip Broker as a Service CumpsD/broker-as-a-service · MCP server Both about service 52★ 10not measured1mo ago