Module: SolidAgent

Defined in:
lib/solid_agent/has_tools.rb,
lib/solid_agent.rb,
lib/solid_agent/engine.rb,
lib/solid_agent/records.rb,
lib/solid_agent/version.rb,
lib/solid_agent/has_memory.rb,
lib/solid_agent/reasonable.rb,
lib/solid_agent/tool_cache.rb,
lib/solid_agent/has_context.rb,
lib/solid_agent/has_reasons.rb,
lib/solid_agent/model_naming.rb,
lib/solid_agent/model_pricing.rb,
lib/solid_agent/records/agent.rb,
lib/solid_agent/agent_manifest.rb,
lib/solid_agent/records/ownable.rb,
lib/solid_agent/run_fingerprint.rb,
lib/solid_agent/reasonable/reason.rb,
lib/solid_agent/records/agent_run.rb,
lib/solid_agent/agent_manifest/tool.rb,
lib/solid_agent/streams_tool_updates.rb,
lib/solid_agent/agent_manifest/errors.rb,
lib/solid_agent/records/agent_version.rb,
lib/solid_agent/records/agent_template.rb,
lib/solid_agent/agent_manifest/manifest.rb,
lib/solid_agent/agent_manifest/resource.rb,
lib/solid_agent/agent_manifest/validator.rb,
lib/solid_agent/agent_manifest/picoschema.rb,
lib/solid_agent/agent_manifest/input_schema.rb,
lib/solid_agent/agent_manifest/agent_builder.rb,
lib/solid_agent/agent_manifest/registry/auth.rb,
lib/generators/solid_agent/tool/tool_generator.rb,
lib/solid_agent/agent_manifest/parser_registry.rb,
lib/solid_agent/agent_manifest/registry/client.rb,
lib/generators/solid_agent/agent/agent_generator.rb,
lib/solid_agent/agent_manifest/exporter_registry.rb,
lib/solid_agent/agent_manifest/parsers/base_parser.rb,
lib/generators/solid_agent/context/context_generator.rb,
lib/generators/solid_agent/install/install_generator.rb,
lib/generators/solid_agent/reasons/reasons_generator.rb,
lib/solid_agent/agent_manifest/parsers/crewai_parser.rb,
lib/generators/solid_agent/manifest/manifest_generator.rb,
lib/solid_agent/agent_manifest/exporters/base_exporter.rb,
lib/solid_agent/agent_manifest/parsers/agent_md_parser.rb,
lib/solid_agent/agent_manifest/parsers/dotprompt_parser.rb,
lib/solid_agent/agent_manifest/exporters/crewai_exporter.rb,
lib/solid_agent/agent_manifest/exporters/agent_md_exporter.rb,
lib/solid_agent/agent_manifest/exporters/dotprompt_exporter.rb,
lib/solid_agent/agent_manifest/parsers/github_prompt_parser.rb,
sig/solid_agent.rbs

Overview

StreamsToolUpdates provides real-time UI feedback during tool execution.

When an agent is processing and calls tools (which may take time), this concern broadcasts status updates to the client so users see what's happening rather than a frozen UI. This is especially important for long-running tools like web browsing.

Examples:

Basic usage

class MyAgent < ApplicationAgent
  include SolidAgent::HasTools
  include SolidAgent::StreamsToolUpdates

  has_tools :search, :navigate

  def research
    prompt(tools: tools)
  end
end

With custom descriptions

class MyAgent < ApplicationAgent
  include SolidAgent::HasTools
  include SolidAgent::StreamsToolUpdates

  tool_description :navigate, ->(args) { "Visiting #{args[:url]}..." }
  tool_description :search, ->(args) { "Searching for '#{args[:query]}'..." }
  tool_description :extract_text, "Reading page content..."
end

Defined Under Namespace

Modules: AgentManifest, Generators, HasContext, HasMemory, HasReasons, HasTools, ModelNaming, Reasonable, Records, RunFingerprint, StreamsToolUpdates, ToolCache Classes: Engine, Error, LoadError, ModelPricing

Constant Summary collapse

VERSION =

Returns:

  • (String)
"0.2.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.context_classObject

Returns the value of attribute context_class.



33
34
35
# File 'lib/solid_agent.rb', line 33

def context_class
  @context_class
end

.execution_job_classString

Job class enqueued by asynchronous execution, resolved at call time.

Returns:

  • (String)


116
117
118
# File 'lib/solid_agent/records.rb', line 116

def execution_job_class
  @execution_job_class || "AgentExecutionJob"
end

.generation_classObject

Returns the value of attribute generation_class.



33
34
35
# File 'lib/solid_agent.rb', line 33

def generation_class
  @generation_class
end

.message_classObject

Returns the value of attribute message_class.



33
34
35
# File 'lib/solid_agent.rb', line 33

def message_class
  @message_class
end

.run_executor#call

Executes an agent record and returns its result.

Running an agent from a persisted configuration means building a class from stored provider/model/instructions and driving it — execution concerns, which belong to activeagent and to the host, not to a persistence gem. So the gem defines the seam and the host fills it.

The callable receives (agent_record, run) and must return a Hash with :output and optionally :metadata and :usage.

Examples:

SolidAgent.run_executor = ->(agent_record, run) { AgentExecutionService.call(agent_record, run) }

Returns:

  • (#call)


103
104
105
106
107
108
109
# File 'lib/solid_agent/records.rb', line 103

def run_executor
  @run_executor ||= lambda do |agent_record, _run|
    raise Error, "No SolidAgent.run_executor is configured, so #{agent_record.class} cannot be executed. " \
                 "Set SolidAgent.run_executor to a callable taking (agent_record, run) and returning " \
                 "{ output:, metadata:, usage: }."
  end
end

Class Method Details

.agent(source, format: nil, base_class: nil, as: nil) ⇒ Class

Unified agent loading from any source

Examples:

Load from file

ResearchAgent = SolidAgent.agent("agents/research.agent.md")

Load from URL

WeatherAgent = SolidAgent.agent("https://registry.example.com/weather.agent.md")

Load from hash

QuickAgent = SolidAgent.agent({ name: "quick", model: "gpt-4o", instructions: "Be helpful" })

Parameters:

  • source (String, Hash, URI)

    File path, URL, JSON, YAML, or Hash

  • format (Symbol) (defaults to: nil)

    Force format (:agent_md, :json, :yaml, :dotprompt, :crewai)

  • base_class (Class) (defaults to: nil)

    Parent class for generated agent

  • as (String) (defaults to: nil)

    Register as constant with this name

Returns:

  • (Class)

    Generated agent class



56
57
58
59
# File 'lib/solid_agent.rb', line 56

def agent(source, format: nil, base_class: nil, as: nil)
  manifest = AgentManifest.load(source, format: format)
  AgentManifest.build(manifest, base_class: base_class, class_name: as)
end

.agents_from(directory, pattern: "**/*.agent.md", **options) ⇒ Array<Class>

Load multiple agents from a directory

Examples:

Load all agents from config/agents

SolidAgent.agents_from("config/agents")

Parameters:

  • directory (String)

    Path to directory containing agent manifests

  • pattern (String) (defaults to: "**/*.agent.md")

    Glob pattern for manifest files

  • options (Hash)

    Options passed to agent()

Returns:

  • (Array<Class>)

    Array of generated agent classes



71
72
73
74
75
# File 'lib/solid_agent.rb', line 71

def agents_from(directory, pattern: "**/*.agent.md", **options)
  Dir.glob(File.join(directory, pattern)).map do |path|
    agent(path, **options)
  end
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (SolidAgent)

    the object that the method was called on



35
36
37
# File 'lib/solid_agent.rb', line 35

def configure
  yield self if block_given?
end

.execution_jobClass?

Returns:

  • (Class, nil)


123
# File 'lib/solid_agent/records.rb', line 123

def execution_job = execution_job_class.to_s.safe_constantize

.records_installed?Boolean

Whether the agent-records models are present and backed by tables.

Consumers that must degrade gracefully — ActiveAgent's dashboard being the motivating one — check this before touching the models. It answers false both when the constant is missing and when the migration has not run, because a defined model over a missing table fails later and less legibly.

Returns:

  • (Boolean)


78
79
80
81
82
83
84
85
86
87
# File 'lib/solid_agent/records.rb', line 78

def records_installed?
  model = agent_model
  return false unless model

  model.respond_to?(:table_exists?) && model.table_exists?
rescue ::StandardError
  # A connection that is not established yet is not an error worth raising
  # from a predicate whose whole job is to be safe to call.
  false
end

.reset_records_configuration!void

This method returns an undefined value.

Resets every records-layer configuration knob. Test support.



128
129
130
131
132
# File 'lib/solid_agent/records.rb', line 128

def reset_records_configuration!
  Records::MODELS.each_key { |name| instance_variable_set(:"@#{name}", nil) }
  @run_executor = nil
  @execution_job_class = nil
end