Class: LittleGhost::AgentBuilder

Inherits:
AssemblyBuilder show all
Defined in:
lib/little_ghost/assembly_builder.rb

Overview

Builds an Agent definition from declarations made at runtime.

agent = LittleGhost::AgentBuilder.new(id: "customer_support")
agent.model "openrouter:openai/gpt-5.6-luna"
agent.system_prompt "Answer customer questions clearly."
agent.ask("Where is my order?")

Supported Agent class-DSL calls are recorded and replayed into each immutable snapshot.

Constant Summary collapse

DECLARATIONS =
%i[
  model limits result_schema capture_diagnostics system_template system_prompt
  tools prompt_local after_initialize before_invocation after_invocation
  before_model after_model after_model_error before_tool after_tool
  manage_context detect_tool_loops skills subagent subagents
  subagent_long_poll_duration agent_as_tool agents_as_tools
  assembly_as_tool assemblies_as_tools
].freeze

Instance Attribute Summary

Attributes inherited from AssemblyBuilder

#runtime

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AssemblyBuilder

#as_tool, #ask, #assembly_id, #assembly_kind, #build, #call, #definition, #description, #start_execution, #stream, #stream_ask, #validate!

Constructor Details

#initialize(**options) ⇒ AgentBuilder

Creates a mutable dynamic Agent definition.



279
280
281
282
# File 'lib/little_ghost/assembly_builder.rb', line 279

def initialize(**options)
  super
  @operations = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *arguments, **keywords, &block) ⇒ Object

Records supported Agent class-DSL declarations for the next snapshot.



290
291
292
293
294
295
# File 'lib/little_ghost/assembly_builder.rb', line 290

def method_missing(name, *arguments, **keywords, &block)
  return super unless DECLARATIONS.include?(name)

  @mutex.synchronize { @operations << [name, arguments, keywords, block] }
  self
end

Class Method Details

.assembly_kindObject

:nodoc:



275
# File 'lib/little_ghost/assembly_builder.rb', line 275

def assembly_kind = :agent

Instance Method Details

#agent_id(value = nil) ⇒ Object

Reads or assigns the Agent identifier.



285
286
287
# File 'lib/little_ghost/assembly_builder.rb', line 285

def agent_id(value = nil)
  value.nil? ? assembly_id : assembly_id(value)
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Reports the declarative methods supported by Agent.

Returns:

  • (Boolean)


298
299
300
# File 'lib/little_ghost/assembly_builder.rb', line 298

def respond_to_missing?(name, include_private = false)
  DECLARATIONS.include?(name) || super
end