mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
feat(providers): pluggable agent providers + Grok (xAI) backend
Add a roboco/llm/providers/ seam — an AgentProvider lifecycle ABC and a ProviderRegistry keyed by ModelProvider — so the orchestrator can drive agent backends other than Claude Code. The first non-Claude backend is GrokProvider for xAI's grok-build-0.1. xAI is OpenAI-compatible only (no Anthropic-Messages endpoint), so a Grok agent runs an OpenAI-protocol runtime pointed at https://api.x.ai/v1 rather than the ANTHROPIC_BASE_URL injection the other providers use. It reuses the orchestrator's existing mount/auth assembly, so it inherits the same MCP gateway + tool-manifest wiring as every other agent by construction, and passes its prompt via env (never an argv positional). The change is purely additive: only GROK routes through the registry; Anthropic / Ollama Cloud / self-hosted spawns run the existing _spawn_container path unchanged. Includes: - ModelProvider.GROK (migration 038) + a seeded Grok provider row (migration 039) + a grok-build-0.1 catalog entry - GET/PUT /api/providers/grok-key to store the xAI key (Fernet-encrypted, reusing the existing provider-key machinery) - ClaudeCodeProvider reference adapter over the current spawn - unit tests for the registry, GrokProvider (gateway wiring, no ANTHROPIC_* leak, prompt-injection safety, failure paths) and routing The dedicated roboco-agent-grok image and the exact OpenAI-protocol CLI invocation are the remaining piece to finalise with xAI.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"""Add 'grok' to the postgres modelprovider enum.
|
||||
|
||||
Grok (``ModelProvider.GROK`` — xAI's OpenAI-compatible grok-build-0.1) is a new
|
||||
agent backend. Seeding its provider row (migration 039) and routing agents to it
|
||||
requires the postgres ``modelprovider`` enum to carry the value. Mirrors the
|
||||
enum-add pattern of migration 037; the row seed is split into 039 because a
|
||||
newly added enum value cannot be used in the same transaction that adds it.
|
||||
|
||||
Revision ID: 038_modelprovider_grok
|
||||
Revises: 037_agentrole_pr_reviewer
|
||||
Create Date: 2026-06-18
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from alembic import op
|
||||
|
||||
revision = "038_modelprovider_grok"
|
||||
down_revision = "037_agentrole_pr_reviewer"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Unguarded (renders in offline --sql so the enum-migration-parity test
|
||||
# sees it) and idempotent. PG 16 permits ADD VALUE inside a transaction.
|
||||
op.execute("ALTER TYPE modelprovider ADD VALUE IF NOT EXISTS 'grok'")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# Postgres does not support removing enum values without a destructive
|
||||
# type recreation. Forward-only by design (see migration 037).
|
||||
pass
|
||||
@@ -0,0 +1,60 @@
|
||||
"""Idempotently seed the Grok (xAI) provider row.
|
||||
|
||||
The ``modelprovider`` enum carries ``'grok'`` as of migration 038. This
|
||||
migration seeds the corresponding ``provider_configs`` row so the Settings UI
|
||||
can store the xAI key without an extra provisioning call.
|
||||
|
||||
The row starts disabled with the public xAI base URL and no key — the operator
|
||||
sets the key via PUT /api/providers/grok/key, which encrypts it and enables the
|
||||
provider. ON CONFLICT (name) DO NOTHING keeps this safe to re-run.
|
||||
|
||||
Revision ID: 039_seed_grok_provider
|
||||
Revises: 038_modelprovider_grok
|
||||
Create Date: 2026-06-18
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "039_seed_grok_provider"
|
||||
down_revision = "038_modelprovider_grok"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.execute(
|
||||
sa.text(
|
||||
"""
|
||||
INSERT INTO provider_configs
|
||||
(id, name, type, base_url, auth_token_encrypted, enabled, created_at)
|
||||
VALUES
|
||||
(
|
||||
gen_random_uuid(),
|
||||
'Grok (xAI)',
|
||||
'grok',
|
||||
'https://api.x.ai/v1',
|
||||
NULL,
|
||||
false,
|
||||
now()
|
||||
)
|
||||
ON CONFLICT (name) DO NOTHING
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# Drop model_assignments pointing at the Grok row first to avoid a FK
|
||||
# RESTRICT violation on provider_configs.id.
|
||||
op.execute(
|
||||
sa.text(
|
||||
"DELETE FROM model_assignments "
|
||||
"WHERE provider_config_id IN ("
|
||||
" SELECT id FROM provider_configs WHERE name = 'Grok (xAI)'"
|
||||
")"
|
||||
)
|
||||
)
|
||||
op.execute(sa.text("DELETE FROM provider_configs WHERE name = 'Grok (xAI)'"))
|
||||
Reference in New Issue
Block a user