Class: LittleGhost::Subagents::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/little_ghost/subagents/definition.rb

Overview

A Definition describes one kind of agent available for delegation. Most applications create definitions through Agent::Delegation#subagent.

The factory receives the complete agent path and may also accept runtime:. When accepts_conversation_id is true it receives the durable conversation UUID as a second positional argument. Factories returning a LittleGhost::Agent must construct it with the supplied path as agent_path; the conversation UUID is a separate persistence identifier.

# ResearchAgent is defined by the application.
definition = LittleGhost::Subagents::Definition.new(
kind: "research",
description: "Investigates a bounded question",
factory: ->(agent_path) { ResearchAgent.new(agent_path:) }
)
definition.kind # => "research"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind:, description:, factory:, persist: true, accepts_conversation_id: false) ⇒ Definition

Validates a definition. persist is effective only when the manager has a parent session.

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
38
39
# File 'lib/little_ghost/subagents/definition.rb', line 30

def initialize(kind:, description:, factory:, persist: true, accepts_conversation_id: false)
  @kind = String(kind)
  @description = String(description)
  @factory = factory
  @persist = !!persist
  @accepts_conversation_id = !!accepts_conversation_id

  raise ArgumentError, "kind cannot be empty" if @kind.empty?
  raise ArgumentError, "factory must respond to call" unless @factory.respond_to?(:call)
end

Instance Attribute Details

#accepts_conversation_idObject (readonly)

The model-visible kind and description, callable factory, persistence policy, and factory-arity declaration.



26
27
28
# File 'lib/little_ghost/subagents/definition.rb', line 26

def accepts_conversation_id
  @accepts_conversation_id
end

#descriptionObject (readonly)

The model-visible kind and description, callable factory, persistence policy, and factory-arity declaration.



26
27
28
# File 'lib/little_ghost/subagents/definition.rb', line 26

def description
  @description
end

#factoryObject (readonly)

The model-visible kind and description, callable factory, persistence policy, and factory-arity declaration.



26
27
28
# File 'lib/little_ghost/subagents/definition.rb', line 26

def factory
  @factory
end

#kindObject (readonly)

The model-visible kind and description, callable factory, persistence policy, and factory-arity declaration.



26
27
28
# File 'lib/little_ghost/subagents/definition.rb', line 26

def kind
  @kind
end

#persistObject (readonly)

The model-visible kind and description, callable factory, persistence policy, and factory-arity declaration.



26
27
28
# File 'lib/little_ghost/subagents/definition.rb', line 26

def persist
  @persist
end