Files
roboco/alembic/versions/038_modelprovider_grok.py
T
Renn F a956083f9f 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.
2026-06-18 06:14:27 +02:00

34 lines
1.1 KiB
Python

"""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