Skip to content

Feature: Support local OpenAI-compatible providers (Ollama, LM Studio) via localProvider in AgentDefinition #678

@vraj00222

Description

@vraj00222

Problem

Right now, every LLM call Codebuff makes goes through its backend → OpenRouter, regardless of what model string is set in an AgentDefinition. There is no way to point an agent at a locally-running model.

This blocks three real use cases:

  • Privacy — code never leaves the machine
  • Offline / air-gapped — no internet, no Codebuff
  • Cost splitting — cheap tasks (file picking) locally, complex reasoning on cloud

Related: #288 requested LiteLLM integration. This is a narrower, zero-dependency alternative — no new packages, no Python proxy.


Proposed Solution

Add an optional localProvider field to AgentDefinition. When present, the CLI calls the local endpoint directly, bypassing the Codebuff backend entirely.

Type change

// .agents/types/agent-definition.ts

export interface AgentDefinition {
  // ...existing fields unchanged

  localProvider?: {
    baseUrl: string  // e.g. "http://localhost:11434/v1"
    apiKey?: string  // optional — Ollama ignores it
  }
}

Dispatch logic

// cli/src/<agent-dispatch>

if (agent.localProvider) {
  const client = new OpenAI({
    baseURL: agent.localProvider.baseUrl,
    apiKey: agent.localProvider.apiKey ?? 'ollama',
  })
  return client.chat.completions.create({ model: agent.model, messages, stream: true })
}

// Default: existing Codebuff backend → OpenRouter path

openai is already in the dependency tree via OpenRouter — zero new packages needed.

Global fallback (env var)

CODEBUFF_LOCAL_BASE_URL=http://localhost:11434/v1

If set, applies as a fallback localProvider for any agent that doesn't define one explicitly.


Scope

  • Files touched: ~3 (agent-definition.ts, CLI dispatch, env schema)
  • Lines of code: ~80
  • New dependencies: None
  • Breaking changes: None — fully backward-compatible

Happy to Submit a PR for this if the approach looks good.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions