Class: SolidAgent::AgentManifest::AgentBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/solid_agent/agent_manifest/agent_builder.rb

Overview

AgentBuilder generates ActiveAgent classes from Manifest definitions.

Creates anonymous or named classes with the appropriate concerns included, tools defined, and system instructions configured.

Examples:

Build an agent class from a manifest

manifest = AgentManifest.parse("research_assistant.agent.md")
klass = AgentBuilder.build(manifest)
agent = klass.new
agent.research(query: "Ruby concurrency")

Build with a custom base class

klass = AgentBuilder.build(manifest, base_class: ApplicationAgent)

Build with explicit naming

klass = AgentBuilder.build(manifest, class_name: "CustomResearchAgent")
CustomResearchAgent.new.call

Class Method Summary collapse

Class Method Details

.build(manifest, base_class: nil, class_name: nil, namespace: nil) ⇒ Class

Build an agent class from a manifest

Parameters:

  • manifest (Manifest)

    The manifest to build from

  • base_class (Class) (defaults to: nil)

    Base class to inherit from

  • class_name (String, nil) (defaults to: nil)

    Optional class name for constant registration

  • namespace (Module, nil) (defaults to: nil)

    Optional namespace for constant registration

Returns:

  • (Class)

    The generated agent class



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/solid_agent/agent_manifest/agent_builder.rb', line 32

def build(manifest, base_class: nil, class_name: nil, namespace: nil)
  # Determine base class
  parent_class = determine_base_class(manifest, base_class)

  # Create the class
  klass = Class.new(parent_class)

  # Configure the agent
  configure_model(klass, manifest)
  configure_concerns(klass, manifest)
  configure_tools(klass, manifest)
  configure_instructions(klass, manifest)
  (klass, manifest)

  # Register as constant if requested
  if class_name || manifest_class_name(manifest)
    register_constant(klass, class_name || manifest_class_name(manifest), namespace)
  end

  klass
end

.build_from_file(path, **options) ⇒ Class

Build from a file path

Parameters:

  • path (String)

    Path to manifest file

  • options (Hash)

    Options passed to build

Returns:

  • (Class)

    The generated agent class



69
70
71
72
# File 'lib/solid_agent/agent_manifest/agent_builder.rb', line 69

def build_from_file(path, **options)
  manifest = ParserRegistry.parse(path)
  build(manifest, **options)
end

.build_instance(manifest, params: {}, **options) ⇒ Object

Build and instantiate an agent from a manifest

Parameters:

  • manifest (Manifest)

    The manifest to build from

  • params (Hash) (defaults to: {})

    Parameters to pass to the agent

Returns:

  • (Object)

    The instantiated agent



59
60
61
62
# File 'lib/solid_agent/agent_manifest/agent_builder.rb', line 59

def build_instance(manifest, params: {}, **options)
  klass = build(manifest, **options)
  klass.new(params)
end