Module: AgentHarness
- Defined in:
- lib/agent_harness.rb,
lib/agent_harness/skill.rb,
lib/agent_harness/errors.rb,
lib/agent_harness/skills.rb,
lib/agent_harness/version.rb,
lib/agent_harness/response.rb,
lib/agent_harness/extensions.rb,
lib/agent_harness/mcp_server.rb,
lib/agent_harness/conversation.rb,
lib/agent_harness/providers/pi.rb,
lib/agent_harness/configuration.rb,
lib/agent_harness/token_tracker.rb,
lib/agent_harness/authentication.rb,
lib/agent_harness/error_taxonomy.rb,
lib/agent_harness/providers/base.rb,
lib/agent_harness/text_transport.rb,
lib/agent_harness/providers/aider.rb,
lib/agent_harness/providers/codex.rb,
lib/agent_harness/command_executor.rb,
lib/agent_harness/provider_runtime.rb,
lib/agent_harness/providers/cursor.rb,
lib/agent_harness/providers/gemini.rb,
lib/agent_harness/release_registry.rb,
lib/agent_harness/sub_agent_config.rb,
lib/agent_harness/mcp_config_loader.rb,
lib/agent_harness/providers/adapter.rb,
lib/agent_harness/dependency_updater.rb,
lib/agent_harness/providers/kilocode.rb,
lib/agent_harness/providers/opencode.rb,
lib/agent_harness/providers/registry.rb,
lib/agent_harness/providers/anthropic.rb,
lib/agent_harness/sub_agent_translator.rb,
lib/agent_harness/execution_preparation.rb,
lib/agent_harness/mcp_config_translator.rb,
lib/agent_harness/orchestration/metrics.rb,
lib/agent_harness/provider_health_check.rb,
lib/agent_harness/sub_agent_file_loader.rb,
lib/agent_harness/providers/mistral_vibe.rb,
lib/agent_harness/docker_command_executor.rb,
lib/agent_harness/orchestration/conductor.rb,
lib/agent_harness/providers/github_copilot.rb,
lib/agent_harness/orchestration/rate_limiter.rb,
lib/agent_harness/openai_compatible_transport.rb,
lib/agent_harness/orchestration/health_monitor.rb,
lib/agent_harness/orchestration/circuit_breaker.rb,
lib/agent_harness/providers/token_usage_parsing.rb,
lib/agent_harness/orchestration/provider_manager.rb,
lib/agent_harness/providers/mcp_config_file_support.rb,
lib/agent_harness/providers/rate_limit_reset_parsing.rb
Overview
AgentHarness provides a unified interface for CLI-based AI coding agents.
It offers:
-
Unified interface for multiple AI coding agents (Claude Code, Cursor, Gemini CLI, etc.)
-
Full orchestration layer with provider switching, circuit breakers, and health monitoring
-
Flexible configuration via YAML, Ruby DSL, or environment variables
-
Dynamic provider registration for custom provider support
-
Token usage tracking for cost and limit calculations
Defined Under Namespace
Modules: Authentication, ErrorTaxonomy, Extensions, McpConfigTranslator, Orchestration, Providers, Skills, SubAgentTranslator Classes: AuthMismatchError, AuthenticationError, CallbackRegistry, CircuitBreakerConfig, CircuitOpenError, CommandExecutionError, CommandExecutor, Configuration, ConfigurationError, Conversation, DependencyUpdater, DockerCommandExecutor, Error, ExecutionPreparation, ExtensionCompatibilityError, HealthCheckConfig, IdleTimeoutError, InvalidDurationError, McpConfigLoader, McpConfigurationError, McpServer, McpTransportUnsupportedError, McpUnsupportedError, NoProvidersAvailableError, OpenAICompatibleTransport, OrchestrationConfig, ProviderConfig, ProviderError, ProviderHealthCheck, ProviderNotFoundError, ProviderRuntime, ProviderUnavailableError, RateLimitConfig, RateLimitError, ReleaseRegistry, Response, RetryConfig, Skill, SubAgentConfig, SubAgentFileLoader, TextTransport, TimeoutError, TokenTracker, ToolDefinition, ToolRegistry, UnsupportedAuthFlowError
Constant Summary collapse
- VERSION =
"0.22.0"
Class Method Summary collapse
-
.auth_capabilities(provider_name) ⇒ Hash
Get authentication flow capabilities for a provider.
-
.auth_status(provider_name) ⇒ Hash
Get detailed authentication status for a provider.
-
.auth_url(provider_name) ⇒ String
Generate an OAuth URL for a provider.
-
.auth_url_supported?(provider_name) ⇒ Boolean
Check whether OAuth URL generation is supported for a provider.
-
.auth_valid?(provider_name) ⇒ Boolean
Check if authentication is valid for a provider.
-
.build_config(name, **options) ⇒ ProviderConfig
Build a new ProviderConfig with defaults for the given provider.
-
.check_provider(provider_name, timeout: nil, executor: nil, provider_runtime: nil) ⇒ Hash
Check health of a single provider.
-
.check_providers(timeout: nil, executor: nil, provider_runtime: nil) ⇒ Array<Hash>
Check health of all configured providers.
-
.conductor ⇒ Orchestration::Conductor
Returns the global conductor for orchestrated requests.
-
.configuration ⇒ Configuration
Returns the global configuration instance.
-
.configure {|Configuration| ... } ⇒ void
Configure AgentHarness with a block.
-
.dependency_updater ⇒ DependencyUpdater
Returns the global dependency updater for managing agent tool versions.
-
.discover_extensions(directory) ⇒ Array<Extensions::Base>
Discover and register all extensions found in a directory.
-
.extension(reference) ⇒ Extensions::Base
Resolve a canonical extension definition by name or inline object.
-
.extension_compatibility(provider:, extensions:) ⇒ Array<Extensions::CompatibilityReport>
Build a compatibility report for extensions against a provider.
-
.install_contract(name) ⇒ Hash
Get install contract metadata for a provider.
-
.installation_contract(provider_name, **options) ⇒ Hash?
Get installation metadata for a provider CLI.
-
.installation_contracts ⇒ Hash<Symbol, Hash>
Get all provider installation contracts exposed by agent-harness.
-
.load_extensions(path, adapter: nil) ⇒ Array<Extensions::Base>
Load one or more extensions from disk through an adapter.
-
.logger ⇒ Logger?
Returns the global logger.
-
.provider(name) ⇒ Providers::Base
Get a provider instance.
-
.provider_class(name) ⇒ Class
Look up the provider class for a given name or alias.
-
.provider_install_contract(provider_name, version: nil) ⇒ Hash?
Returns install metadata for a provider CLI when the provider exposes it.
-
.provider_installation_contract(name, **options) ⇒ Hash?
Get the installation contract for a provider CLI.
-
.provider_metadata(provider_name, refresh: false) ⇒ Hash
Get consolidated metadata for a provider.
-
.provider_metadata_catalog(refresh: false) ⇒ Hash<Symbol, Hash>
Get consolidated metadata for all registered providers.
-
.provider_smoke_test_contract(provider_name) ⇒ Hash?
Get smoke-test metadata for a provider CLI when the provider exposes it.
-
.providers ⇒ Array<Symbol>
List all registered provider names.
-
.refresh_auth(provider_name, token: nil) ⇒ Hash
Refresh authentication credentials for a provider.
-
.refresh_auth_supported?(provider_name) ⇒ Boolean
Check whether credential refresh is supported for a provider.
-
.reset! ⇒ void
Reset configuration to defaults (useful for testing).
-
.resolve_latest_version(provider_name, bypass_cooldown: false) ⇒ Hash?
Resolve the latest eligible version for an installable provider tool, applying the configured cooldown period.
-
.send_message(prompt, provider: nil, executor: nil, **options) ⇒ Response
Send a message using the orchestration layer.
-
.smoke_test_contract(provider_name) ⇒ Hash?
Get smoke-test metadata for a provider CLI.
-
.smoke_test_contracts ⇒ Hash<Symbol, Hash>
Get all provider smoke-test contracts exposed by agent-harness.
-
.sub_agent(reference) ⇒ SubAgentConfig
Resolve a canonical sub-agent definition by name or inline payload.
-
.token_tracker ⇒ TokenTracker
Returns the global token tracker.
-
.translate_sub_agent(reference, provider:) ⇒ Hash
Translate a canonical sub-agent definition into a provider-specific format.
Class Method Details
.auth_capabilities(provider_name) ⇒ Hash
Get authentication flow capabilities for a provider
278 279 280 |
# File 'lib/agent_harness.rb', line 278 def auth_capabilities(provider_name) Authentication.auth_capabilities(provider_name) end |
.auth_status(provider_name) ⇒ Hash
Get detailed authentication status for a provider
270 271 272 |
# File 'lib/agent_harness.rb', line 270 def auth_status(provider_name) Authentication.auth_status(provider_name) end |
.auth_url(provider_name) ⇒ String
Generate an OAuth URL for a provider
294 295 296 |
# File 'lib/agent_harness.rb', line 294 def auth_url(provider_name) Authentication.auth_url(provider_name) end |
.auth_url_supported?(provider_name) ⇒ Boolean
Check whether OAuth URL generation is supported for a provider
286 287 288 |
# File 'lib/agent_harness.rb', line 286 def auth_url_supported?(provider_name) Authentication.auth_url_supported?(provider_name) end |
.auth_valid?(provider_name) ⇒ Boolean
Check if authentication is valid for a provider
263 264 265 |
# File 'lib/agent_harness.rb', line 263 def auth_valid?(provider_name) Authentication.auth_valid?(provider_name) end |
.build_config(name, **options) ⇒ ProviderConfig
Build a new ProviderConfig with defaults for the given provider
168 169 170 171 172 |
# File 'lib/agent_harness.rb', line 168 def build_config(name, **) config = ProviderConfig.new(name) config.merge!() unless .empty? config end |
.check_provider(provider_name, timeout: nil, executor: nil, provider_runtime: nil) ⇒ Hash
Check health of a single provider
338 339 340 341 342 343 344 |
# File 'lib/agent_harness.rb', line 338 def check_provider(provider_name, timeout: nil, executor: nil, provider_runtime: nil) = {} [:timeout] = timeout unless timeout.nil? [:executor] = executor unless executor.nil? [:provider_runtime] = provider_runtime unless provider_runtime.nil? ProviderHealthCheck.check(provider_name, **) end |
.check_providers(timeout: nil, executor: nil, provider_runtime: nil) ⇒ Array<Hash>
Check health of all configured providers.
Validates each enabled provider through registration, CLI availability, authentication, provider health status, and config validation checks.
325 326 327 328 329 330 331 332 |
# File 'lib/agent_harness.rb', line 325 def check_providers(timeout: nil, executor: nil, provider_runtime: nil) raise ArgumentError, "provider_runtime is only supported for single-provider health checks" unless provider_runtime.nil? = {} [:timeout] = timeout unless timeout.nil? [:executor] = executor unless executor.nil? ProviderHealthCheck.check_all(**) end |
.conductor ⇒ Orchestration::Conductor
Returns the global conductor for orchestrated requests
68 69 70 |
# File 'lib/agent_harness.rb', line 68 def conductor @conductor ||= Orchestration::Conductor.new(config: configuration) end |
.configuration ⇒ Configuration
Returns the global configuration instance
33 34 35 |
# File 'lib/agent_harness.rb', line 33 def configuration @configuration ||= Configuration.new end |
.configure {|Configuration| ... } ⇒ void
This method returns an undefined value.
Configure AgentHarness with a block
40 41 42 |
# File 'lib/agent_harness.rb', line 40 def configure yield(configuration) if block_given? end |
.dependency_updater ⇒ DependencyUpdater
Returns the global dependency updater for managing agent tool versions.
The dependency updater applies a configurable cooldown period before adopting new upstream releases, reducing exposure to regressions.
352 353 354 |
# File 'lib/agent_harness.rb', line 352 def dependency_updater @dependency_updater ||= DependencyUpdater.new end |
.discover_extensions(directory) ⇒ Array<Extensions::Base>
Discover and register all extensions found in a directory.
103 104 105 |
# File 'lib/agent_harness.rb', line 103 def discover_extensions(directory) configuration.discover_extensions(directory) end |
.extension(reference) ⇒ Extensions::Base
Resolve a canonical extension definition by name or inline object.
86 87 88 |
# File 'lib/agent_harness.rb', line 86 def extension(reference) configuration.resolve_extension(reference) end |
.extension_compatibility(provider:, extensions:) ⇒ Array<Extensions::CompatibilityReport>
Build a compatibility report for extensions against a provider.
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/agent_harness.rb', line 112 def extension_compatibility(provider:, extensions:) provider_instance = provider.is_a?(Providers::Base) ? provider : self.provider(provider) Array(extensions).map do |extension_ref| Extensions::Compatibility.report( provider: provider_instance, extension: extension(extension_ref) ) end end |
.install_contract(name) ⇒ Hash
Get install contract metadata for a provider
178 179 180 |
# File 'lib/agent_harness.rb', line 178 def install_contract(name) Providers::Registry.instance.install_contract(name) end |
.installation_contract(provider_name, **options) ⇒ Hash?
Get installation metadata for a provider CLI.
206 207 208 |
# File 'lib/agent_harness.rb', line 206 def installation_contract(provider_name, **) Providers::Registry.instance.installation_contract(provider_name, **) end |
.installation_contracts ⇒ Hash<Symbol, Hash>
Get all provider installation contracts exposed by agent-harness.
212 213 214 |
# File 'lib/agent_harness.rb', line 212 def installation_contracts Providers::Registry.instance.installation_contracts end |
.load_extensions(path, adapter: nil) ⇒ Array<Extensions::Base>
Load one or more extensions from disk through an adapter.
95 96 97 |
# File 'lib/agent_harness.rb', line 95 def load_extensions(path, adapter: nil) configuration.load_extensions(path, adapter: adapter) end |
.logger ⇒ Logger?
Returns the global logger
56 57 58 |
# File 'lib/agent_harness.rb', line 56 def logger configuration.logger end |
.provider(name) ⇒ Providers::Base
Get a provider instance
143 144 145 |
# File 'lib/agent_harness.rb', line 143 def provider(name) conductor.provider_manager.get_provider(name) end |
.provider_class(name) ⇒ Class
Look up the provider class for a given name or alias
159 160 161 |
# File 'lib/agent_harness.rb', line 159 def provider_class(name) Providers::Registry.instance.get(name) end |
.provider_install_contract(provider_name, version: nil) ⇒ Hash?
Returns install metadata for a provider CLI when the provider exposes it.
187 188 189 |
# File 'lib/agent_harness.rb', line 187 def provider_install_contract(provider_name, version: nil) provider_installation_contract(provider_name, **(version ? {version: version} : {})) end |
.provider_installation_contract(name, **options) ⇒ Hash?
Get the installation contract for a provider CLI.
197 198 199 |
# File 'lib/agent_harness.rb', line 197 def provider_installation_contract(name, **) Providers::Registry.instance.installation_contract(name, **) end |
.provider_metadata(provider_name, refresh: false) ⇒ Hash
Get consolidated metadata for a provider.
223 224 225 |
# File 'lib/agent_harness.rb', line 223 def (provider_name, refresh: false) Providers::Registry.instance.(provider_name, refresh: refresh) end |
.provider_metadata_catalog(refresh: false) ⇒ Hash<Symbol, Hash>
Get consolidated metadata for all registered providers.
232 233 234 |
# File 'lib/agent_harness.rb', line 232 def (refresh: false) Providers::Registry.instance.(refresh: refresh) end |
.provider_smoke_test_contract(provider_name) ⇒ Hash?
Get smoke-test metadata for a provider CLI when the provider exposes it.
240 241 242 |
# File 'lib/agent_harness.rb', line 240 def provider_smoke_test_contract(provider_name) smoke_test_contract(provider_name) end |
.providers ⇒ Array<Symbol>
List all registered provider names
150 151 152 |
# File 'lib/agent_harness.rb', line 150 def providers Providers::Registry.instance.all end |
.refresh_auth(provider_name, token: nil) ⇒ Hash
Refresh authentication credentials for a provider
311 312 313 |
# File 'lib/agent_harness.rb', line 311 def refresh_auth(provider_name, token: nil) Authentication.refresh_auth(provider_name, token: token) end |
.refresh_auth_supported?(provider_name) ⇒ Boolean
Check whether credential refresh is supported for a provider
302 303 304 |
# File 'lib/agent_harness.rb', line 302 def refresh_auth_supported?(provider_name) Authentication.refresh_auth_supported?(provider_name) end |
.reset! ⇒ void
This method returns an undefined value.
Reset configuration to defaults (useful for testing)
46 47 48 49 50 51 52 |
# File 'lib/agent_harness.rb', line 46 def reset! @configuration = nil @conductor = nil @token_tracker = nil @dependency_updater = nil Skills.reset! if defined?(Skills) end |
.resolve_latest_version(provider_name, bypass_cooldown: false) ⇒ Hash?
Resolve the latest eligible version for an installable provider tool, applying the configured cooldown period.
363 364 365 366 367 368 |
# File 'lib/agent_harness.rb', line 363 def resolve_latest_version(provider_name, bypass_cooldown: false) dependency_updater.resolve_latest_installation_contract( provider_name, bypass_cooldown: bypass_cooldown ) end |
.send_message(prompt, provider: nil, executor: nil, **options) ⇒ Response
Send a message using the orchestration layer
78 79 80 |
# File 'lib/agent_harness.rb', line 78 def (prompt, provider: nil, executor: nil, **) conductor.(prompt, provider: provider, executor: executor, **) end |
.smoke_test_contract(provider_name) ⇒ Hash?
Get smoke-test metadata for a provider CLI.
248 249 250 251 252 |
# File 'lib/agent_harness.rb', line 248 def smoke_test_contract(provider_name) # Explicitly raise if provider is not registered to match documentation raise ConfigurationError, "Unknown provider: #{provider_name}" unless Providers::Registry.instance.registered?(provider_name) Providers::Registry.instance.smoke_test_contract(provider_name) end |
.smoke_test_contracts ⇒ Hash<Symbol, Hash>
Get all provider smoke-test contracts exposed by agent-harness.
256 257 258 |
# File 'lib/agent_harness.rb', line 256 def smoke_test_contracts Providers::Registry.instance.smoke_test_contracts end |
.sub_agent(reference) ⇒ SubAgentConfig
Resolve a canonical sub-agent definition by name or inline payload.
127 128 129 |
# File 'lib/agent_harness.rb', line 127 def sub_agent(reference) configuration.resolve_sub_agent(reference) end |
.token_tracker ⇒ TokenTracker
Returns the global token tracker
62 63 64 |
# File 'lib/agent_harness.rb', line 62 def token_tracker @token_tracker ||= TokenTracker.new end |
.translate_sub_agent(reference, provider:) ⇒ Hash
Translate a canonical sub-agent definition into a provider-specific format.
136 137 138 |
# File 'lib/agent_harness.rb', line 136 def translate_sub_agent(reference, provider:) SubAgentTranslator.for_provider(provider, sub_agent(reference)) end |