class LittleGhost::Agent

Define reusable agents that can answer, stream, call tools, and delegate work. Each subclass describes one application role with an inheritable Ruby DSL.

A customer support agent can look up an account itself and give longer investigations to a research specialist:

class ResearchAgent < LittleGhost::Agent
  description "Researches transfer failures"
  model "customer_support.research"
  tools LedgerSearchTool
end

class CustomerSupportAgent < LittleGhost::Agent
  description "Handles support requests"
  model :customer_support
  limits max_turns: 40
  tools AccountLookupTool
  subagent ResearchAgent, kind: "research"
end

run = CustomerSupportAgent.ask("Why is transfer 481 pending?")
run.completed? # => true
run.response   # => "Transfer 481 is waiting for the receiving bank."

Class declarations are inherited. Prompts resolve by the agent’s logical path unless system_prompt or system_template supplies one explicitly; tools and prompt locals may also be selected dynamically for each run. Capabilities such as skills, context management, loop detection, and delegation remain inactive until their DSL methods are called.

The class-level ask helper creates a standalone entrypoint and returns a completed Run. Create a standalone instance explicitly to reuse one Runtime or call stream_ask for StreamEvent objects. Runtimes build bound instances internally; their call method returns a RunResult and their stream method follows the owning run’s single-execution lifecycle. Closing an agent closes owned tools and any standalone workspace and sandbox. LittleGhost::Agent.ask uses You are a helpful agent. as its system prompt. Subclasses continue to use their inline or conventional prompts.

Models can return ordinary text or a locally validated structured result. Tool failures are sanitized before returning to the model, diagnostic capture can be disabled for sensitive agents, and cancellation, deadlines, and cleanup failures remain framework control flow.