Class: AgentHarness::Providers::Anthropic
- Defined in:
- lib/agent_harness/providers/anthropic.rb
Overview
Anthropic Claude Code CLI provider
Provides integration with the Claude Code CLI tool for AI-powered coding assistance.
Constant Summary collapse
- MODEL_PATTERN =
Model name pattern for Anthropic Claude models
/^claude-[\d.-]+-(?:opus|sonnet|haiku)(?:-\d{8})?$/i
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
- .available? ⇒ Boolean
- .binary_name ⇒ Object
- .discover_models ⇒ Object
- .firewall_requirements ⇒ Object
- .instruction_file_paths ⇒ Object
-
.model_family(provider_model_name) ⇒ Object
Normalize a provider-specific model name to its model family.
-
.provider_model_name(family_name) ⇒ Object
Convert a model family name to the provider’s preferred model name.
- .provider_name ⇒ Object
-
.supports_model_family?(family_name) ⇒ Boolean
Check if this provider supports a given model family.
Instance Method Summary collapse
- #capabilities ⇒ Object
- #dangerous_mode_flags ⇒ Object
- #display_name ⇒ Object
- #error_patterns ⇒ Object
- #fetch_mcp_servers ⇒ Object
- #name ⇒ Object
- #supports_dangerous_mode? ⇒ Boolean
- #supports_mcp? ⇒ Boolean
Methods inherited from Base
#configure, #initialize, #send_message
Methods included from Adapter
#health_status, included, #send_message, #session_flags, #supports_sessions?, #validate_config
Constructor Details
This class inherits a constructor from AgentHarness::Providers::Base
Class Method Details
.available? ⇒ Boolean
28 29 30 31 |
# File 'lib/agent_harness/providers/anthropic.rb', line 28 def available? executor = AgentHarness.configuration.command_executor !!executor.which(binary_name) end |
.binary_name ⇒ Object
24 25 26 |
# File 'lib/agent_harness/providers/anthropic.rb', line 24 def binary_name "claude" end |
.discover_models ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/agent_harness/providers/anthropic.rb', line 54 def discover_models return [] unless available? begin require "open3" output, _, status = Open3.capture3("claude", "models", "list", {timeout: 10}) return [] unless status.success? parse_models_list(output) rescue => e AgentHarness.logger&.debug("[AgentHarness::Anthropic] Model discovery failed: #{e.}") [] end end |
.firewall_requirements ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/agent_harness/providers/anthropic.rb', line 33 def firewall_requirements { domains: [ "api.anthropic.com", "claude.ai", "console.anthropic.com" ], ip_ranges: [] } end |
.instruction_file_paths ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/agent_harness/providers/anthropic.rb', line 44 def instruction_file_paths [ { path: "CLAUDE.md", description: "Claude Code CLI agent instructions", symlink: true } ] end |
.model_family(provider_model_name) ⇒ Object
Normalize a provider-specific model name to its model family
70 71 72 |
# File 'lib/agent_harness/providers/anthropic.rb', line 70 def model_family(provider_model_name) provider_model_name.sub(/-\d{8}$/, "") end |
.provider_model_name(family_name) ⇒ Object
Convert a model family name to the provider’s preferred model name
75 76 77 |
# File 'lib/agent_harness/providers/anthropic.rb', line 75 def provider_model_name(family_name) family_name end |
.provider_name ⇒ Object
20 21 22 |
# File 'lib/agent_harness/providers/anthropic.rb', line 20 def provider_name :claude end |
.supports_model_family?(family_name) ⇒ Boolean
Check if this provider supports a given model family
80 81 82 |
# File 'lib/agent_harness/providers/anthropic.rb', line 80 def supports_model_family?(family_name) MODEL_PATTERN.match?(family_name) end |
Instance Method Details
#capabilities ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/agent_harness/providers/anthropic.rb', line 163 def capabilities { streaming: true, file_upload: true, vision: true, tool_use: true, json_mode: true, mcp: true, dangerous_mode: true } end |
#dangerous_mode_flags ⇒ Object
183 184 185 |
# File 'lib/agent_harness/providers/anthropic.rb', line 183 def dangerous_mode_flags ["--dangerously-skip-permissions"] end |
#display_name ⇒ Object
159 160 161 |
# File 'lib/agent_harness/providers/anthropic.rb', line 159 def display_name "Anthropic Claude CLI" end |
#error_patterns ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/agent_harness/providers/anthropic.rb', line 187 def error_patterns { rate_limited: [ /rate.?limit/i, /too.?many.?requests/i, /429/, /overloaded/i, /session.?limit/i ], auth_expired: [ /oauth.*token.*expired/i, /authentication.*error/i, /invalid.*api.*key/i, /unauthorized/i, /401/ ], quota_exceeded: [ /quota.*exceeded/i, /usage.*limit/i, /credit.*exhausted/i ], transient: [ /timeout/i, /connection.*reset/i, /temporary.*error/i, /service.*unavailable/i, /503/, /502/, /504/ ], permanent: [ /invalid.*model/i, /unsupported.*operation/i, /not.*found/i, /404/, /bad.*request/i, /400/, /model.*deprecated/i, /end-of-life/i ] } end |
#fetch_mcp_servers ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/agent_harness/providers/anthropic.rb', line 230 def fetch_mcp_servers return [] unless self.class.available? begin result = @executor.execute(["claude", "mcp", "list"], timeout: 5) return [] unless result.success? parse_claude_mcp_output(result.stdout) rescue => e log_debug("fetch_mcp_servers_failed", error: e.) [] end end |
#name ⇒ Object
155 156 157 |
# File 'lib/agent_harness/providers/anthropic.rb', line 155 def name "anthropic" end |
#supports_dangerous_mode? ⇒ Boolean
179 180 181 |
# File 'lib/agent_harness/providers/anthropic.rb', line 179 def supports_dangerous_mode? true end |
#supports_mcp? ⇒ Boolean
175 176 177 |
# File 'lib/agent_harness/providers/anthropic.rb', line 175 def supports_mcp? true end |