Module: AgentHarness::Providers::Adapter
- Included in:
- Base
- Defined in:
- lib/agent_harness/providers/adapter.rb
Overview
Interface that all providers must implement
This module defines the contract that provider implementations must follow. Include this module in provider classes to ensure they implement the required interface.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#auth_type ⇒ Symbol
Authentication type for this provider.
-
#build_mcp_flags(mcp_servers, working_dir: nil) ⇒ Array<String>
Build provider-specific MCP flags/arguments for CLI invocation.
-
#capabilities ⇒ Hash
Provider capabilities.
-
#configuration_schema ⇒ Hash
Provider configuration schema for app-driven setup UIs.
-
#dangerous_mode_flags ⇒ Array<String>
Get dangerous mode flags.
-
#error_patterns ⇒ Hash<Symbol, Array<Regexp>>
Error patterns for classification.
-
#execution_semantics ⇒ Hash
Execution semantics for this provider.
-
#fetch_mcp_servers ⇒ Array<Hash>
Fetch configured MCP servers.
-
#health_status ⇒ Hash
Health check.
-
#parse_rate_limit_reset(output) ⇒ Time?
Parse a rate-limit reset time from provider output.
-
#send_message(prompt:, **options) ⇒ Response
Send a message/prompt to the provider.
-
#session_flags(session_id) ⇒ Array<String>
Get session flags for continuation.
-
#supported_mcp_transports ⇒ Array<String>
Supported MCP transport types for this provider.
-
#supports_dangerous_mode? ⇒ Boolean
Check if provider supports dangerous mode.
-
#supports_mcp? ⇒ Boolean
Check if provider supports MCP.
-
#supports_sessions? ⇒ Boolean
Check if provider supports session continuation.
-
#validate_config ⇒ Hash
Validate provider configuration.
-
#validate_mcp_servers!(mcp_servers) ⇒ Object
Validate that this provider can handle the given MCP servers.
Class Method Details
.included(base) ⇒ Object
19 20 21 |
# File 'lib/agent_harness/providers/adapter.rb', line 19 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#auth_type ⇒ Symbol
Authentication type for this provider
130 131 132 |
# File 'lib/agent_harness/providers/adapter.rb', line 130 def auth_type :api_key end |
#build_mcp_flags(mcp_servers, working_dir: nil) ⇒ Array<String>
Build provider-specific MCP flags/arguments for CLI invocation
160 161 162 |
# File 'lib/agent_harness/providers/adapter.rb', line 160 def build_mcp_flags(mcp_servers, working_dir: nil) [] end |
#capabilities ⇒ Hash
Provider capabilities
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/agent_harness/providers/adapter.rb', line 107 def capabilities { streaming: false, file_upload: false, vision: false, tool_use: false, json_mode: false, mcp: false, dangerous_mode: false } end |
#configuration_schema ⇒ Hash
Provider configuration schema for app-driven setup UIs
Returns metadata describing the configurable fields, supported authentication modes, and backend compatibility for this provider. Applications use this to build generic provider-entry forms without hardcoding provider-specific knowledge.
96 97 98 99 100 101 102 |
# File 'lib/agent_harness/providers/adapter.rb', line 96 def configuration_schema { fields: [], auth_modes: [auth_type], openai_compatible: false } end |
#dangerous_mode_flags ⇒ Array<String>
Get dangerous mode flags
210 211 212 |
# File 'lib/agent_harness/providers/adapter.rb', line 210 def dangerous_mode_flags [] end |
#error_patterns ⇒ Hash<Symbol, Array<Regexp>>
Error patterns for classification
122 123 124 |
# File 'lib/agent_harness/providers/adapter.rb', line 122 def error_patterns {} end |
#execution_semantics ⇒ Hash
Execution semantics for this provider
Returns a hash describing provider-specific execution behavior so downstream apps do not need to hardcode CLI quirks. This metadata can be used to select the right flags and interpret output.
250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/agent_harness/providers/adapter.rb', line 250 def execution_semantics { prompt_delivery: :arg, # :arg, :stdin, or :flag output_format: :text, # :text or :json sandbox_aware: false, # adjusts behavior inside containers uses_subcommand: false, # e.g. "codex exec", "opencode run" non_interactive_flag: nil, # flag to suppress interactive prompts legitimate_exit_codes: [0], # exit codes that are NOT errors stderr_is_diagnostic: true, # stderr may contain non-error output parses_rate_limit_reset: false # can extract Retry-After from output } end |
#fetch_mcp_servers ⇒ Array<Hash>
Fetch configured MCP servers
144 145 146 |
# File 'lib/agent_harness/providers/adapter.rb', line 144 def fetch_mcp_servers [] end |
#health_status ⇒ Hash
Health check
239 240 241 |
# File 'lib/agent_harness/providers/adapter.rb', line 239 def health_status {healthy: true, message: "OK"} end |
#parse_rate_limit_reset(output) ⇒ Time?
Parse a rate-limit reset time from provider output
Providers that include rate-limit reset information in their error output can override this to extract it, so the orchestration layer can schedule retries accurately.
271 272 273 |
# File 'lib/agent_harness/providers/adapter.rb', line 271 def parse_rate_limit_reset(output) nil end |
#send_message(prompt:, **options) ⇒ Response
Send a message/prompt to the provider
84 85 86 |
# File 'lib/agent_harness/providers/adapter.rb', line 84 def (prompt:, **) raise NotImplementedError, "#{self.class} must implement #send_message" end |
#session_flags(session_id) ⇒ Array<String>
Get session flags for continuation
225 226 227 |
# File 'lib/agent_harness/providers/adapter.rb', line 225 def session_flags(session_id) [] end |
#supported_mcp_transports ⇒ Array<String>
Supported MCP transport types for this provider
151 152 153 |
# File 'lib/agent_harness/providers/adapter.rb', line 151 def supported_mcp_transports [] end |
#supports_dangerous_mode? ⇒ Boolean
Check if provider supports dangerous mode
203 204 205 |
# File 'lib/agent_harness/providers/adapter.rb', line 203 def supports_dangerous_mode? capabilities[:dangerous_mode] end |
#supports_mcp? ⇒ Boolean
Check if provider supports MCP
137 138 139 |
# File 'lib/agent_harness/providers/adapter.rb', line 137 def supports_mcp? capabilities[:mcp] end |
#supports_sessions? ⇒ Boolean
Check if provider supports session continuation
217 218 219 |
# File 'lib/agent_harness/providers/adapter.rb', line 217 def supports_sessions? false end |
#validate_config ⇒ Hash
Validate provider configuration
232 233 234 |
# File 'lib/agent_harness/providers/adapter.rb', line 232 def validate_config {valid: true, errors: []} end |
#validate_mcp_servers!(mcp_servers) ⇒ Object
Validate that this provider can handle the given MCP servers
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/agent_harness/providers/adapter.rb', line 169 def validate_mcp_servers!(mcp_servers) return if mcp_servers.nil? || mcp_servers.empty? unless supports_mcp? raise McpUnsupportedError.new( "Provider '#{self.class.provider_name}' does not support MCP servers", provider: self.class.provider_name ) end supported = supported_mcp_transports if supported.empty? raise McpUnsupportedError.new( "Provider '#{self.class.provider_name}' does not support request-time MCP servers", provider: self.class.provider_name ) end mcp_servers.each do |server| next if supported.include?(server.transport) raise McpTransportUnsupportedError.new( "Provider '#{self.class.provider_name}' does not support MCP transport " \ "'#{server.transport}' (server: '#{server.name}'). " \ "Supported transports: #{supported.join(", ")}", provider: self.class.provider_name ) end end |