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/sub_agent_config.rb,
lib/agent_harness/mcp_config_loader.rb,
lib/agent_harness/providers/adapter.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, DockerCommandExecutor, Error, ExecutionPreparation, ExtensionCompatibilityError, HealthCheckConfig, IdleTimeoutError, InvalidDurationError, McpConfigLoader, McpConfigurationError, McpServer, McpTransportUnsupportedError, McpUnsupportedError, NoProvidersAvailableError, OpenAICompatibleTransport, OrchestrationConfig, ProviderConfig, ProviderError, ProviderHealthCheck, ProviderNotFoundError, ProviderRuntime, ProviderUnavailableError, RateLimitConfig, RateLimitError, Response, RetryConfig, Skill, SubAgentConfig, SubAgentFileLoader, TextTransport, TimeoutError, TokenTracker, ToolDefinition, ToolRegistry, UnsupportedAuthFlowError
Constant Summary collapse
- VERSION =
"0.18.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.
-
.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).
-
.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
277 278 279 |
# File 'lib/agent_harness.rb', line 277 def auth_capabilities(provider_name) Authentication.auth_capabilities(provider_name) end |
.auth_status(provider_name) ⇒ Hash
Get detailed authentication status for a provider
269 270 271 |
# File 'lib/agent_harness.rb', line 269 def auth_status(provider_name) Authentication.auth_status(provider_name) end |
.auth_url(provider_name) ⇒ String
Generate an OAuth URL for a provider
293 294 295 |
# File 'lib/agent_harness.rb', line 293 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
285 286 287 |
# File 'lib/agent_harness.rb', line 285 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
262 263 264 |
# File 'lib/agent_harness.rb', line 262 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
167 168 169 170 171 |
# File 'lib/agent_harness.rb', line 167 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
337 338 339 340 341 342 343 |
# File 'lib/agent_harness.rb', line 337 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.
324 325 326 327 328 329 330 331 |
# File 'lib/agent_harness.rb', line 324 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
67 68 69 |
# File 'lib/agent_harness.rb', line 67 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 |
.discover_extensions(directory) ⇒ Array<Extensions::Base>
Discover and register all extensions found in a directory.
102 103 104 |
# File 'lib/agent_harness.rb', line 102 def discover_extensions(directory) configuration.discover_extensions(directory) end |
.extension(reference) ⇒ Extensions::Base
Resolve a canonical extension definition by name or inline object.
85 86 87 |
# File 'lib/agent_harness.rb', line 85 def extension(reference) configuration.resolve_extension(reference) end |
.extension_compatibility(provider:, extensions:) ⇒ Array<Extensions::CompatibilityReport>
Build a compatibility report for extensions against a provider.
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/agent_harness.rb', line 111 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
177 178 179 |
# File 'lib/agent_harness.rb', line 177 def install_contract(name) Providers::Registry.instance.install_contract(name) end |
.installation_contract(provider_name, **options) ⇒ Hash?
Get installation metadata for a provider CLI.
205 206 207 |
# File 'lib/agent_harness.rb', line 205 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.
211 212 213 |
# File 'lib/agent_harness.rb', line 211 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.
94 95 96 |
# File 'lib/agent_harness.rb', line 94 def load_extensions(path, adapter: nil) configuration.load_extensions(path, adapter: adapter) end |
.logger ⇒ Logger?
Returns the global logger
55 56 57 |
# File 'lib/agent_harness.rb', line 55 def logger configuration.logger end |
.provider(name) ⇒ Providers::Base
Get a provider instance
142 143 144 |
# File 'lib/agent_harness.rb', line 142 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
158 159 160 |
# File 'lib/agent_harness.rb', line 158 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.
186 187 188 |
# File 'lib/agent_harness.rb', line 186 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.
196 197 198 |
# File 'lib/agent_harness.rb', line 196 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.
222 223 224 |
# File 'lib/agent_harness.rb', line 222 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.
231 232 233 |
# File 'lib/agent_harness.rb', line 231 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.
239 240 241 |
# File 'lib/agent_harness.rb', line 239 def provider_smoke_test_contract(provider_name) smoke_test_contract(provider_name) end |
.providers ⇒ Array<Symbol>
List all registered provider names
149 150 151 |
# File 'lib/agent_harness.rb', line 149 def providers Providers::Registry.instance.all end |
.refresh_auth(provider_name, token: nil) ⇒ Hash
Refresh authentication credentials for a provider
310 311 312 |
# File 'lib/agent_harness.rb', line 310 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
301 302 303 |
# File 'lib/agent_harness.rb', line 301 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 |
# File 'lib/agent_harness.rb', line 46 def reset! @configuration = nil @conductor = nil @token_tracker = nil Skills.reset! if defined?(Skills) end |
.send_message(prompt, provider: nil, executor: nil, **options) ⇒ Response
Send a message using the orchestration layer
77 78 79 |
# File 'lib/agent_harness.rb', line 77 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.
247 248 249 250 251 |
# File 'lib/agent_harness.rb', line 247 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.
255 256 257 |
# File 'lib/agent_harness.rb', line 255 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.
126 127 128 |
# File 'lib/agent_harness.rb', line 126 def sub_agent(reference) configuration.resolve_sub_agent(reference) end |
.token_tracker ⇒ TokenTracker
Returns the global token tracker
61 62 63 |
# File 'lib/agent_harness.rb', line 61 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.
135 136 137 |
# File 'lib/agent_harness.rb', line 135 def translate_sub_agent(reference, provider:) SubAgentTranslator.for_provider(provider, sub_agent(reference)) end |