# How to Override the Default Backend for a Specific Platform in Agent Reach

> Learn how to override the default backend for a specific platform in Agent Reach. This guide shows you how to force a specific backend using configuration keys or environment variables.

- Repository: [Pnant/Agent-Reach](https://github.com/Panniantong/Agent-Reach)
- Tags: how-to-guide
- Published: 2026-07-06

---

**Agent Reach selects backends automatically based on installed tools, but you can force a specific backend by setting a `<platform>_backend` configuration key in `~/.agent-reach/config.yaml` or via environment variables.**

Agent Reach is an open-source automation framework that abstracts interactions across social media platforms like Twitter, Reddit, and YouTube. While the framework automatically probes for available tools to determine the best backend, you can override the default backend for a specific platform when you need precise control over which tool handles your requests.

## Understanding Backend Selection in Agent Reach

### How Automatic Backend Detection Works

By default, Agent Reach dynamically selects a backend for each platform based on what tools are installed and authenticated on your system. As implemented in `Panniantong/Agent-Reach`, each channel module (such as [`agent_reach/channels/xiaohongshu.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/channels/xiaohongshu.py)) implements a `check()` method that probes for available backends like OpenCLI or platform-specific CLIs.

### The Backend Override Mechanism

You can force a particular backend by setting a platform-specific configuration key that follows the pattern:

```

<platform>_backend = <backend-identifier>

```

Here, `<platform>` is the lowercase name of the channel (e.g., `twitter`, `xiaohongshu`, `youtube`), and `<backend-identifier>` is the string the channel uses to label its backends. When this key is present, the channel's `check()` method will **prefer** the configured backend, setting it as the `active_backend` attribute before the default probing logic executes.

## Configuration Methods for Backend Overrides

### Persistent Configuration via CLI

The most reliable way to store your preference is through the configuration file. Agent Reach reads values from `~/.agent-reach/config.yaml` and exposes a CLI command to modify settings via [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py):

```bash
python -m agent_reach.cli config set xiaohongshu_backend xhs-cli

```

This command persists the override to your configuration file, ensuring that all subsequent operations use the specified backend for that platform.

### Temporary Override via Environment Variables

For one-off operations or testing different backends without changing your persistent configuration, use environment variables. The configuration system in [`agent_reach/config.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/config.py) automatically maps uppercase environment variables to the corresponding config keys:

```bash
XIAOHONGSHU_BACKEND=xhs-cli python -m agent_reach.cli doctor

```

This approach is ideal for CI/CD pipelines or when you need to test a specific backend without affecting your default setup.

### Programmatic Configuration in Python

You can also set overrides directly in your Python code using the `Config` class. This method allows you to switch backends dynamically based on runtime conditions:

```python
from agent_reach.config import Config

# Initialize configuration

cfg = Config()

# Set backend override (persists to config.yaml)

cfg.set("twitter_backend", "twitter-cli")

```

After setting this value, any channel interaction through `agent_reach.core.read` or the CLI will use the configured backend as the `active_backend`.

## Verification and Testing

To verify your override is working, check that the channel reports your chosen backend as active. The test suite in [`tests/test_channels.py`](https://github.com/Panniantong/Agent-Reach/blob/main/tests/test_channels.py) demonstrates that a configuration value like `xiaohongshu_backend=xhs-cli` forces the channel to use the specified backend even when OpenCLI is available and ready.

You can confirm the active backend by running:

```bash
python -m agent_reach.cli doctor

```

This command displays which backend is currently active for each configured platform.

## Summary

- **Pattern**: Use `<platform>_backend = <backend-identifier>` to force a specific backend for any platform.
- **Persistent storage**: Use `python -m agent_reach.cli config set <key> <value>` to save overrides to `~/.agent-reach/config.yaml`.
- **Temporary override**: Set uppercase environment variables like `XIAOHONGSHU_BACKEND=xhs-cli` for single-session changes.
- **Programmatic control**: Import `Config` from [`agent_reach/config.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/config.py) and call `cfg.set()` to modify backends in Python scripts.
- **Implementation**: The `check()` method in each channel file (e.g., [`agent_reach/channels/xiaohongshu.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/channels/xiaohongshu.py)) reads these values and sets `active_backend` accordingly.

## Frequently Asked Questions

### How do I find the correct backend identifier for my platform?

The backend identifier is the string that the channel's `check()` method uses to label available backends. Check the specific channel implementation in `agent_reach/channels/<platform>.py` to see what strings are valid for that platform. Common identifiers include `xhs-cli`, `twitter-cli`, `twint`, and `yt-dlp`.

### Can I override multiple platforms at once?

Yes. You can set multiple `<platform>_backend` keys in your configuration file or environment. Each platform operates independently, so you can force Twitter to use `twint` while setting YouTube to use `yt-dlp` by setting both `twitter_backend` and `youtube_backend` in your config or environment variables.

### What happens if the specified backend is not installed?

If you configure a backend that is not available on your system, the channel's `check()` method will fail to initialize that backend. Agent Reach may fall back to available alternatives or raise an error depending on the channel implementation. Always verify backend availability using `python -m agent_reach.cli doctor` before relying on a specific override.

### Where does Agent Reach store configuration files?

Agent Reach stores persistent configuration in `~/.agent-reach/config.yaml`. The `Config` class in [`agent_reach/config.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/config.py) handles loading from this location and from environment variables, with environment variables taking precedence over file-based settings.