diff --git a/CHANGELOG.md b/CHANGELOG.md index 21305af..0e60aba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixture-backed `evals/skills/write-yard-docs/basic`: undocumented `PriceCalculator`, passing starting tests, and a condensed `skills/write-yard-docs/SKILL.md`. - Fixture-backed `evals/skills/triage-bug/basic`: buggy `Discount.apply` (integer division), passing happy-path tests, and a condensed `skills/triage-bug/SKILL.md`. - Fixture-backed `evals/skills/refactor-process/basic`: duplicated `OrderProcessor` methods, passing characterization tests, and a condensed `skills/refactor-process/SKILL.md`. +- xAI (Grok) provider: OpenAI-compatible client at `https://api.x.ai/v1/chat/completions`, default model `grok-4`, `skill-bench init --xai`, env `SKILL_BENCH_XAI_API_KEY` or `XAI_API_KEY`. ### Documentation - Align user docs with shipped 1.3.1: OpenRouter and mock in the provider list, Azure env var `SKILL_BENCH_AZURE_OPENAI_API_KEY`, Mistral key via `skill-bench.json` (no env mapping). diff --git a/README.md b/README.md index 2ebedaf..fc4b698 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ See the [Ecosystem Overview](https://github.com/igmarin/agent-mcp-runtime/blob/m - **Isolated Git Sandboxes**: Every run operates in a temporary repo. Clean diffs, zero side-effects, 100% reproducibility. - **Blind Judging with Dimensions**: LLM judge scores baseline and context independently across 5 canonical dimensions (Correctness, Skill Adherence, Code Quality, Test Coverage, Documentation). Eval authors configure weights and thresholds via `criteria.json`. - **Sophisticated ReAct Loop**: Employs a robust `Thought → Tool → Observation` loop to handle complex, multi-step engineering tasks. -- **Multi-Provider Ecosystem**: Native support for **OpenAI**, **Anthropic**, **Google Gemini**, **Azure OpenAI**, **Ollama**, **Groq**, **DeepSeek**, **Mistral**, **OpenCode**, and **OpenRouter**. +- **Multi-Provider Ecosystem**: Native support for **OpenAI**, **Anthropic**, **Google Gemini**, **Azure OpenAI**, **Ollama**, **Groq**, **DeepSeek**, **Mistral**, **OpenCode**, **OpenRouter**, and **xAI**. - **Standardized Intelligence**: Consistent reporting format regardless of the underlying LLM provider. --- @@ -68,6 +68,7 @@ CLI / API → RunnerService → Sandbox + ReAct Agent → LLM Client Layer → P | **Mistral** | set `api_key` in `skill-bench.json` (no env mapping) | `:mistral` | | **OpenCode** | `SKILL_BENCH_OPENCODE_API_KEY`, `SKILL_BENCH_OPENCODE_BASE_URL` | `:opencode` | | **OpenRouter** | `SKILL_BENCH_OPENROUTER_API_KEY` | `:openrouter` | +| **xAI** | `SKILL_BENCH_XAI_API_KEY` or `XAI_API_KEY` | `:xai` | | **Mock** | — (offline, `skill-bench init --mock`) | `:mock` | > **Note:** Environment variables are loaded automatically. You can also configure provider settings in `skill-bench.json` (created by `skill-bench init`). @@ -77,6 +78,8 @@ CLI / API → RunnerService → Sandbox + ReAct Agent → LLM Client Layer → P > **Mistral** uses Mistral's OpenAI-compatible chat completions API (default model `mistral-large-latest`). Scaffold with `skill-bench init --mistral` and set `config.api_key` in `skill-bench.json`. There is no `SKILL_BENCH_MISTRAL_API_KEY` env mapping. > > **OpenRouter** uses OpenRouter's OpenAI-compatible API (default model `anthropic/claude-3.5-sonnet`). Set `SKILL_BENCH_OPENROUTER_API_KEY` and scaffold with `skill-bench init --openrouter`. +> +> **xAI** uses xAI's OpenAI-compatible chat completions API (default model `grok-4`). Set `SKILL_BENCH_XAI_API_KEY` or `XAI_API_KEY` and scaffold with `skill-bench init --xai`. ### Command Allowlist @@ -148,7 +151,7 @@ skill-bench init --openai } ``` -**Available providers:** `--openai`, `--anthropic`, `--gemini`, `--ollama`, `--azure`, `--groq`, `--deepseek`, `--mistral`, `--opencode`, `--openrouter`, plus `--mock` for an offline config with no API key. +**Available providers:** `--openai`, `--anthropic`, `--gemini`, `--ollama`, `--azure`, `--groq`, `--deepseek`, `--mistral`, `--opencode`, `--openrouter`, `--xai`, plus `--mock` for an offline config with no API key. **Zero-config offline path:** `skill-bench init --mock` scaffolds a minimal offline config that needs no API key and no network — `{"provider":"mock","max_execution_time":30}`. Use it to try the full flow (and run the bundled examples) before wiring up a real provider. diff --git a/docs/architecture.md b/docs/architecture.md index 3ffc539..2526758 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -111,7 +111,7 @@ Owns per-dimension arithmetic and the boolean verdict. Does not call the network ### `Clients::BaseClient` and `ProviderRegistry` -Own HTTP to LLM providers (Faraday, retries, response normalization). Registered providers: openai, anthropic, gemini, ollama, azure, groq, deepseek, mistral, opencode, openrouter, plus mock and null. Do not own eval files. +Own HTTP to LLM providers (Faraday, retries, response normalization). Registered providers: openai, anthropic, gemini, ollama, azure, groq, deepseek, mistral, opencode, openrouter, xai, plus mock and null. Do not own eval files. ### `Config` diff --git a/docs/first-eval-guide.md b/docs/first-eval-guide.md index 8f4bf96..2711de1 100644 --- a/docs/first-eval-guide.md +++ b/docs/first-eval-guide.md @@ -42,7 +42,7 @@ skill-bench init --openai This creates `skill-bench.json` with the OpenAI provider config. Use `--force` to overwrite. -**Available providers:** `--openai`, `--anthropic`, `--gemini`, `--ollama`, `--azure`, `--groq`, `--deepseek`, `--mistral`, `--opencode`, `--openrouter`, plus `--mock` for an offline config with no API key. +**Available providers:** `--openai`, `--anthropic`, `--gemini`, `--ollama`, `--azure`, `--groq`, `--deepseek`, `--mistral`, `--opencode`, `--openrouter`, `--xai`, plus `--mock` for an offline config with no API key. > **What is `skill-bench.json`?** This is your config file. It stores your API key, chosen LLM model, timeout, and allowed shell commands. Think of it as `.env` but structured as JSON. You edit it; SkillBench reads it. diff --git a/lib/skill_bench/clients/README.md b/lib/skill_bench/clients/README.md index cf89bb4..d0554f8 100644 --- a/lib/skill_bench/clients/README.md +++ b/lib/skill_bench/clients/README.md @@ -28,6 +28,7 @@ graph TD Mistral[Mistral] OpenCode[OpenCode] OpenRouter[OpenRouter] + Xai[Xai] Mock[Mock] %% Connections @@ -45,6 +46,7 @@ graph TD Base -.-> Mistral Base -.-> OpenCode Base -.-> OpenRouter + Base -.-> Xai Base -.-> Mock end @@ -77,6 +79,7 @@ graph TD | **Groq** | `:groq` | `GROQ_*` | High-speed inference | | **DeepSeek** | `:deepseek` | `DEEPSEEK_*` | Cost-effective alternative | | **OpenCode** | `:opencode` | `OPENCODE_*` | **Custom endpoint required** (self-hosted proxy / LiteLLM / vLLM) | +| **xAI** | `:xai` | `SKILL_BENCH_XAI_*` / `XAI_*` | Grok via `https://api.x.ai` | | **Null Client** | `:null` | N/A | Mock / Fallback testing | --- diff --git a/lib/skill_bench/clients/all.rb b/lib/skill_bench/clients/all.rb index 933a85a..9938412 100644 --- a/lib/skill_bench/clients/all.rb +++ b/lib/skill_bench/clients/all.rb @@ -20,4 +20,5 @@ require_relative 'providers/deepseek' require_relative 'providers/mistral' require_relative 'providers/openrouter' +require_relative 'providers/xai' require_relative 'providers/mock' diff --git a/lib/skill_bench/clients/provider_schemas.rb b/lib/skill_bench/clients/provider_schemas.rb index 8e13e30..0333ef1 100644 --- a/lib/skill_bench/clients/provider_schemas.rb +++ b/lib/skill_bench/clients/provider_schemas.rb @@ -51,6 +51,10 @@ class ProviderSchemas openrouter: { api_key: nil, model: 'anthropic/claude-3.5-sonnet' + }.freeze, + xai: { + api_key: nil, + model: 'grok-4' }.freeze }.freeze diff --git a/lib/skill_bench/clients/providers/xai.rb b/lib/skill_bench/clients/providers/xai.rb new file mode 100644 index 0000000..87381cb --- /dev/null +++ b/lib/skill_bench/clients/providers/xai.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require_relative '../base_client' +require_relative '../provider_registry' + +module SkillBench + module Clients + module Providers + # xAI (Grok) LLM client. + # Uses xAI's OpenAI-compatible chat completions API with bearer-token auth. + class Xai < BaseClient + SkillBench::Clients::ProviderRegistry.register(:xai, self) + + # Returns the provider identifier. + # + # @return [Symbol] + def provider_name + :xai + end + + protected + + # Returns the base URL for the xAI API. + # + # The version segment lives in {#request_path} so Faraday does not drop + # it (an absolute request path replaces any path component of the + # connection base URL). + # + # @return [String] + def base_url + @base_url_config || 'https://api.x.ai' + end + + # Returns the request path for chat completions. + # + # @return [String] + def request_path + @request_path_config || '/v1/chat/completions' + end + end + end + end +end diff --git a/lib/skill_bench/config/defaults.rb b/lib/skill_bench/config/defaults.rb index 86ff913..56d1099 100644 --- a/lib/skill_bench/config/defaults.rb +++ b/lib/skill_bench/config/defaults.rb @@ -36,7 +36,8 @@ def self.config groq: { api_key: nil, model: 'llama-3.3-70b-versatile' }, deepseek: { api_key: nil, model: 'deepseek-chat' }, opencode: { api_key: nil, model: 'opencode-model', base_url: nil }, - openrouter: { api_key: nil, model: 'anthropic/claude-3.5-sonnet' } + openrouter: { api_key: nil, model: 'anthropic/claude-3.5-sonnet' }, + xai: { api_key: nil, model: 'grok-4' } } } end diff --git a/lib/skill_bench/config/env_overrides.rb b/lib/skill_bench/config/env_overrides.rb index 8a1f1ce..7518466 100644 --- a/lib/skill_bench/config/env_overrides.rb +++ b/lib/skill_bench/config/env_overrides.rb @@ -49,7 +49,11 @@ class EnvOverrides 'SKILL_BENCH_OPENCODE_MODEL' => %i[opencode model], 'OPENCODE_MODEL' => %i[opencode model], 'SKILL_BENCH_OPENROUTER_API_KEY' => %i[openrouter api_key], - 'SKILL_BENCH_OPENROUTER_MODEL' => %i[openrouter model] + 'SKILL_BENCH_OPENROUTER_MODEL' => %i[openrouter model], + 'SKILL_BENCH_XAI_API_KEY' => %i[xai api_key], + 'XAI_API_KEY' => %i[xai api_key], + 'SKILL_BENCH_XAI_MODEL' => %i[xai model], + 'XAI_MODEL' => %i[xai model] }.freeze # Returns provider overrides from the given environment. diff --git a/test/evaluator/clients/providers/xai_test.rb b/test/evaluator/clients/providers/xai_test.rb new file mode 100644 index 0000000..3deab78 --- /dev/null +++ b/test/evaluator/clients/providers/xai_test.rb @@ -0,0 +1,114 @@ +# frozen_string_literal: true + +require 'test_helper' + +module SkillBench + module Clients + module Providers + class XaiTest < Minitest::Test + def setup + Config.reset + Config.current_llm_provider = :xai + end + + def test_call_returns_message_content_on_success + Config.setup do |config| + config.set_provider_api_key(:xai, 'test_xai_key') + end + + stub_request(:post, 'https://api.x.ai/v1/chat/completions') + .to_return( + status: 200, + body: { choices: [{ message: { content: 'Hello from Grok', role: 'assistant' } }] }.to_json, + headers: { 'Content-Type' => 'application/json' } + ) + + old_stderr = $stderr + $stderr = StringIO.new + begin + result = Xai.call( + api_key: 'test_xai_key', + model: 'grok-4', + system_prompt: 'System', + messages: [{ role: 'user', content: 'Hi' }] + ) + ensure + $stderr = old_stderr + end + + assert result[:success] + assert_equal 'Hello from Grok', result[:response][:message]['content'] + end + + def test_call_sends_request_to_xai_endpoint_with_bearer_auth + Config.setup do |config| + config.set_provider_api_key(:xai, 'test_xai_key') + end + + stub = stub_request(:post, 'https://api.x.ai/v1/chat/completions') + .with( + headers: { 'Authorization' => 'Bearer test_xai_key' }, + body: hash_including('model' => 'grok-4') + ) + .to_return( + status: 200, + body: { choices: [{ message: { content: 'ok', role: 'assistant' } }] }.to_json, + headers: { 'Content-Type' => 'application/json' } + ) + + old_stderr = $stderr + $stderr = StringIO.new + begin + Xai.call( + api_key: 'test_xai_key', + model: 'grok-4', + system_prompt: 'System', + messages: [{ role: 'user', content: 'Hi' }] + ) + ensure + $stderr = old_stderr + end + + assert_requested stub + end + + def test_call_returns_error_on_missing_api_key + Config.setup do |config| + config.set_provider_api_key(:xai, nil) + end + + result = Xai.call( + api_key: nil, + system_prompt: 'System', + messages: [] + ) + + refute result[:success] + assert_equal 'API Key not set for Xai', result[:response][:error][:message] + end + + def test_provider_name + client = Xai.new(system_prompt: '', messages: []) + + assert_equal :xai, client.provider_name + end + + def test_base_url + client = Xai.new(system_prompt: '', messages: []) + + assert_equal 'https://api.x.ai', client.send(:base_url) + end + + def test_request_path + client = Xai.new(system_prompt: '', messages: []) + + assert_equal '/v1/chat/completions', client.send(:request_path) + end + + def test_schema_default_model_is_grok4 + assert_equal 'grok-4', ProviderSchemas.for(:xai)[:model] + end + end + end + end +end diff --git a/test/evaluator/config/env_overrides_test.rb b/test/evaluator/config/env_overrides_test.rb index 75b8d09..4730b68 100644 --- a/test/evaluator/config/env_overrides_test.rb +++ b/test/evaluator/config/env_overrides_test.rb @@ -35,6 +35,22 @@ def test_omits_absent_env_values assert result[:success] assert_equal({}, result[:response][:overrides]) end + + def test_maps_xai_api_key_from_prefixed_and_native_env + result = EnvOverrides.call( + env: { + 'SKILL_BENCH_XAI_API_KEY' => 'prefixed-key', + 'XAI_API_KEY' => 'native-key', + 'SKILL_BENCH_XAI_MODEL' => 'grok-4' + } + ) + + assert result[:success] + assert_equal( + { xai: { api_key: 'native-key', model: 'grok-4' } }, + result[:response][:overrides] + ) + end end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index c9d2021..1a60321 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -21,7 +21,7 @@ # # Strip both SKILL_BENCH__ and legacy _ # for every EnvOverrides-capable setting on every registered provider. -%w[OPENAI ANTHROPIC GEMINI OLLAMA AZURE GROQ DEEPSEEK MISTRAL OPENCODE OPENROUTER] +%w[OPENAI ANTHROPIC GEMINI OLLAMA AZURE GROQ DEEPSEEK MISTRAL OPENCODE OPENROUTER XAI] .product(%w[API_KEY MODEL BASE_URL ENDPOINT LOCATION PROJECT_ID API_VERSION]) .each do |provider, setting| ENV.delete("#{provider}_#{setting}")