Files
pocketpaw/docs/backends/copilot-sdk.mdx
Rohit Kushwaha 869407bf69 refactor: provider adapter pattern + LiteLLM support (#595)
* feat: add LiteLLM provider support and unified env resolution

Add LiteLLM as a provider option for all backends (Claude SDK, OpenAI
Agents, Google ADK, Copilot SDK), enabling access to 100+ LLM providers
including HuggingFace, Ollama, vLLM, Together AI, Groq, Mistral, and
more through a single proxy or direct SDK integration.

Key changes:
- New config fields: litellm_api_base, litellm_api_key, litellm_model
- OpenAI Agents: native LitellmModel extension with proxy fallback
- Google ADK: LiteLlm model wrapper for cross-provider support
- Claude SDK: routes through LiteLLM proxy via ANTHROPIC_BASE_URL
- Copilot SDK: LiteLLM via OpenAI-compatible BYOK config
- resolve_backend_env() pushes unified POCKETPAW_* keys to env vars
  each SDK expects, fixing the issue where switching backends required
  manually reconfiguring environment variables

* fix: complete LiteLLM integration across dashboard, health checks, and WS

- Fix health check false warning: add 'litellm' to provider skip list
  in check_api_key_primary() for Claude SDK, OpenAI Agents, and
  Google ADK backends
- Add google_adk_provider to WS settings handler and broadcast
- Add litellm_api_base, litellm_api_key, litellm_model to WS handler
- Add 'LiteLLM (100+ Providers)' option to provider dropdowns in
  settings UI for Claude SDK and OpenAI Agents backends
- Add LiteLLM config fields (proxy URL, API key, model) shown when
  litellm provider is selected in the settings modal

* fix: add LiteLLM provider to Copilot SDK and Google ADK settings UI

- Add LiteLLM option to Copilot SDK provider dropdown
- Add provider dropdown to Google ADK settings (was missing entirely)
- Add LiteLLM config fields (proxy URL, API key, model) for Google ADK
  when litellm provider is selected

* fix: sync env vars at runtime when API keys change via dashboard

resolve_backend_env() now accepts force=True to overwrite existing env
vars. Called after every settings/API-key save so backends immediately
see updated keys without a restart. Codex CLI subprocess gets an
explicit env snapshot via env=os.environ.copy().

* refactor: provider adapter pattern for LLM providers

Extract provider-specific logic (config resolution, client creation,
env var setup, error formatting) into adapter classes under
llm/providers/. Six adapters: Anthropic, Ollama, OpenAICompatible,
OpenRouter, Gemini, LiteLLM.

LLMClient delegates to adapters internally while keeping its public
API stable. Backends (OpenAI Agents, Google ADK, Copilot SDK) now use
adapters directly, replacing 70+ line if/elif chains with ~5 line
adapter calls. Adding a new provider means adding one adapter file
and registering it, no backend changes needed.

30 new tests for adapters, registry, model resolution, and LLMClient
delegation.

* fix: _stderr_lines UnboundLocalError and test_fast_path failures

Move _stderr_lines initialization before the try block so the except
handler can always access it. Add missing _HookMatcher and is_litellm
to test mocks.

* style: format test files and fix UP038 lint

* docs: add Discord deployment config with multi-provider support

Add Docker Compose, Dockerfile, env example, and identity files for
headless Discord bot deployment. Supports direct Anthropic, LiteLLM
proxy, OpenAI-compatible, and OpenAI Agents backends out of the box.

* chore: remove Discord deploy files (moved to separate PR #597)

Deploy config now lives under deploy/discord/ in the
deploy/discord-docker branch to keep this PR focused on
the provider adapter pattern and LiteLLM integration.

* fix: LiteLLM max_tokens setting, config persistence, and health recheck

- Add litellm_max_tokens config option so users can cap output tokens
  for models like DeepSeek (8192 limit)
- Fix LiteLLM settings not persisting on reload: litellmApiBase,
  litellmModel, litellmMaxTokens were missing from SETTINGS_MAP in
  app.js, so the frontend never loaded them back from the server
- Also add 13 other missing backend settings to SETTINGS_MAP
  (openaiAgentsModel, googleAdkProvider, codexCliModel, etc.)
- Re-run health checks after settings save so switching to LiteLLM
  immediately clears the "no Anthropic API key" degraded warning
- Claude SDK fast-path respects provider max_tokens instead of
  hardcoding 1024

* fix: LiteLLM proxy routing, adapter bugs, and remove plan docs

- Fix LiteLLM + OpenAI Agents: use OpenAI-compat proxy path when
  base_url is set instead of native LitellmModel which tried to route
  directly (causing Vertex AI credential errors)
- Fix operator precedence in _to_provider_config() base_url resolution
- Fix dashboard unable to clear LiteLLM API key (falsy vs None check)
- Fix fragile hasattr duck-typing in openai_agents, add explicit
  provider == "litellm" guard
- Replace unnecessary getattr() with direct attribute access in
  google_adk now that the field exists in Settings
- Pass api_key and base_url to ADK LiteLlm wrapper explicitly
- Remove plan design doc

* docs: add OpenRouter and LiteLLM provider documentation

- Add dedicated OpenRouter and LiteLLM sections to LLM providers guide
  with configuration examples for proxy vs direct SDK mode
- Update backend compatibility matrix to include both new providers
- Update per-backend provider tables (Claude SDK, OpenAI Agents,
  Google ADK, Copilot SDK) with LiteLLM and OpenRouter support
- Add OpenRouter and LiteLLM config fields to configuration reference
- Update getting-started configuration with OpenRouter and LiteLLM
  environment variable examples
- Replace OpenRouter-only section in backends index with combined
  OpenRouter + LiteLLM section
2026-03-14 03:46:02 +05:30

123 lines
3.9 KiB
Plaintext

---
title: "Copilot SDK: GitHub Multi-Provider Backend"
description: "The Copilot SDK backend uses GitHub's Copilot SDK with support for Copilot, OpenAI, Azure, and Anthropic providers. JSON-RPC event-driven agent execution."
section: Agent Backends
ogType: article
keywords: ["copilot sdk", "github copilot", "copilot cli", "multi-provider", "json-rpc"]
tags: ["backends", "copilot"]
---
# Copilot SDK: GitHub Multi-Provider Backend
The Copilot SDK backend wraps GitHub's **Copilot SDK** (`github-copilot-sdk`), providing multi-provider agent capabilities with JSON-RPC event-driven execution.
## Overview
- **Status**: Beta
- **Provider support**: Copilot, OpenAI, Azure, Anthropic, LiteLLM
- **Built-in tools**: shell, file_ops, git, web_search
- **MCP support**: No
- **Architecture**: Python SDK wrapper with CopilotClient singleton
## Prerequisites
Install the Copilot CLI:
```bash
pip install github-copilot-sdk
```
Ensure the `copilot` CLI is on your PATH. For the default Copilot provider, you need an active GitHub Copilot subscription.
## Configuration
```bash
export POCKETPAW_AGENT_BACKEND="copilot_sdk"
```
### Backend-Specific Settings
| Setting | Env Variable | Default | Description |
|---------|-------------|---------|-------------|
| `copilot_sdk_provider` | `POCKETPAW_COPILOT_SDK_PROVIDER` | `"copilot"` | Provider: `copilot`, `openai`, `azure`, `anthropic`, `litellm` |
| `copilot_sdk_model` | `POCKETPAW_COPILOT_SDK_MODEL` | `""` (auto) | Model to use |
| `copilot_sdk_max_turns` | `POCKETPAW_COPILOT_SDK_MAX_TURNS` | `0` (unlimited) | Max turns per query |
### Provider Configuration
<Tabs items={["Copilot (default)", "OpenAI", "Azure", "Anthropic", "LiteLLM"]}>
<Tab title="Copilot (default)">
```bash
export POCKETPAW_COPILOT_SDK_PROVIDER="copilot"
# Uses your GitHub Copilot subscription, no separate API key needed
```
</Tab>
<Tab title="OpenAI">
```bash
export POCKETPAW_COPILOT_SDK_PROVIDER="openai"
export POCKETPAW_OPENAI_API_KEY="sk-..."
```
</Tab>
<Tab title="Azure">
```bash
export POCKETPAW_COPILOT_SDK_PROVIDER="azure"
# Configure Azure OpenAI credentials
```
</Tab>
<Tab title="Anthropic">
```bash
export POCKETPAW_COPILOT_SDK_PROVIDER="anthropic"
export POCKETPAW_ANTHROPIC_API_KEY="sk-ant-..."
```
</Tab>
<Tab title="LiteLLM">
```bash
export POCKETPAW_COPILOT_SDK_PROVIDER="litellm"
export POCKETPAW_LITELLM_API_BASE="http://localhost:4000"
export POCKETPAW_LITELLM_MODEL="gpt-4o"
```
</Tab>
</Tabs>
## Built-in Tools
| Copilot Tool | Policy Mapping |
|-------------|---------------|
| `shell` | `shell` |
| `file_ops` | `write_file` |
| `git` | `shell` |
| `web_search` | `browser` |
## How It Works
1. PocketPaw creates a `CopilotClient` singleton for the session
2. Messages are sent via the JSON-RPC event-driven interface
3. The Copilot CLI handles tool execution and multi-turn reasoning
4. History is injected for multi-turn context
5. Responses stream back as `AgentEvent` objects
## When to Use
Choose Copilot SDK when:
- You have a GitHub Copilot subscription and want to use it as your agent backbone
- You want multi-provider flexibility (switch between Copilot, OpenAI, Azure, and Anthropic)
- You want git-aware coding assistance integrated into PocketPaw
## Related
<CardGroup>
<Card title="Claude Agent SDK" icon="lucide:sparkles" href="/backends/claude-sdk">
The recommended backend with native tools and MCP integration.
</Card>
<Card title="OpenAI Agents SDK" icon="lucide:brain" href="/backends/openai-agents">
OpenAI's agent framework with GPT models and Ollama support.
</Card>
<Card title="All Agent Backends" icon="lucide:layers" href="/backends">
Compare all six backends side by side with capability badges.
</Card>
<Card title="Self-Host PocketPaw" icon="lucide:server" href="/guides/self-host-ai-agent">
Deploy PocketPaw on your own infrastructure.
</Card>
</CardGroup>