Module: AgentHarness
- Defined in:
- lib/agent_harness.rb,
lib/agent_harness/errors.rb,
lib/agent_harness/version.rb,
lib/agent_harness/response.rb,
lib/agent_harness/mcp_server.rb,
lib/agent_harness/conversation.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, McpConfigTranslator, Orchestration, Providers, SubAgentTranslator Classes: AuthMismatchError, AuthenticationError, CallbackRegistry, CircuitBreakerConfig, CircuitOpenError, CommandExecutionError, CommandExecutor, Configuration, ConfigurationError, Conversation, DockerCommandExecutor, Error, ExecutionPreparation, HealthCheckConfig, IdleTimeoutError, InvalidDurationError, McpConfigLoader, McpConfigurationError, McpServer, McpTransportUnsupportedError, McpUnsupportedError, NoProvidersAvailableError, OpenAICompatibleTransport, OrchestrationConfig, ProviderConfig, ProviderError, ProviderHealthCheck, ProviderNotFoundError, ProviderRuntime, ProviderUnavailableError, RateLimitConfig, RateLimitError, Response, RetryConfig, SubAgentConfig, SubAgentFileLoader, TextTransport, TimeoutError, TokenTracker, ToolDefinition, ToolRegistry, UnsupportedAuthFlowError
Constant Summary collapse
- VERSION =
"0.11.2"
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.
-
.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.
-
.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.
-
.logger ⇒ Logger?
Returns the global logger.
-
.provider(name) ⇒ Providers::Base
Get a provider instance.
-
.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.
-
.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
208 209 210 |
# File 'lib/agent_harness.rb', line 208 def auth_capabilities(provider_name) Authentication.auth_capabilities(provider_name) end |
.auth_status(provider_name) ⇒ Hash
Get detailed authentication status for a provider
200 201 202 |
# File 'lib/agent_harness.rb', line 200 def auth_status(provider_name) Authentication.auth_status(provider_name) end |
.auth_url(provider_name) ⇒ String
Generate an OAuth URL for a provider
224 225 226 |
# File 'lib/agent_harness.rb', line 224 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
216 217 218 |
# File 'lib/agent_harness.rb', line 216 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
193 194 195 |
# File 'lib/agent_harness.rb', line 193 def auth_valid?(provider_name) Authentication.auth_valid?(provider_name) end |
.check_provider(provider_name, timeout: nil, executor: nil, provider_runtime: nil) ⇒ Hash
Check health of a single provider
268 269 270 271 272 273 274 |
# File 'lib/agent_harness.rb', line 268 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.
255 256 257 258 259 260 261 262 |
# File 'lib/agent_harness.rb', line 255 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
66 67 68 |
# File 'lib/agent_harness.rb', line 66 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 |
.install_contract(name) ⇒ Hash
Get install contract metadata for a provider
108 109 110 |
# File 'lib/agent_harness.rb', line 108 def install_contract(name) Providers::Registry.instance.install_contract(name) end |
.installation_contract(provider_name, **options) ⇒ Hash?
Get installation metadata for a provider CLI.
136 137 138 |
# File 'lib/agent_harness.rb', line 136 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.
142 143 144 |
# File 'lib/agent_harness.rb', line 142 def installation_contracts Providers::Registry.instance.installation_contracts end |
.logger ⇒ Logger?
Returns the global logger
54 55 56 |
# File 'lib/agent_harness.rb', line 54 def logger configuration.logger end |
.provider(name) ⇒ Providers::Base
Get a provider instance
100 101 102 |
# File 'lib/agent_harness.rb', line 100 def provider(name) conductor.provider_manager.get_provider(name) end |
.provider_install_contract(provider_name, version: nil) ⇒ Hash?
Returns install metadata for a provider CLI when the provider exposes it.
117 118 119 |
# File 'lib/agent_harness.rb', line 117 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.
127 128 129 |
# File 'lib/agent_harness.rb', line 127 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.
153 154 155 |
# File 'lib/agent_harness.rb', line 153 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.
162 163 164 |
# File 'lib/agent_harness.rb', line 162 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.
170 171 172 |
# File 'lib/agent_harness.rb', line 170 def provider_smoke_test_contract(provider_name) smoke_test_contract(provider_name) end |
.refresh_auth(provider_name, token: nil) ⇒ Hash
Refresh authentication credentials for a provider
241 242 243 |
# File 'lib/agent_harness.rb', line 241 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
232 233 234 |
# File 'lib/agent_harness.rb', line 232 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 |
# File 'lib/agent_harness.rb', line 46 def reset! @configuration = nil @conductor = nil @token_tracker = nil end |
.send_message(prompt, provider: nil, executor: nil, **options) ⇒ Response
Send a message using the orchestration layer
76 77 78 |
# File 'lib/agent_harness.rb', line 76 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.
178 179 180 181 182 |
# File 'lib/agent_harness.rb', line 178 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.
186 187 188 |
# File 'lib/agent_harness.rb', line 186 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.
84 85 86 |
# File 'lib/agent_harness.rb', line 84 def sub_agent(reference) configuration.resolve_sub_agent(reference) end |
.token_tracker ⇒ TokenTracker
Returns the global token tracker
60 61 62 |
# File 'lib/agent_harness.rb', line 60 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.
93 94 95 |
# File 'lib/agent_harness.rb', line 93 def translate_sub_agent(reference, provider:) SubAgentTranslator.for_provider(provider, sub_agent(reference)) end |