Skip to content

feat: integrate with Clawdbot for auto-routing and model provider#220

Closed
johnlanni wants to merge 4 commits into
mainfrom
feat/clawdbot-integration
Closed

feat: integrate with Clawdbot for auto-routing and model provider#220
johnlanni wants to merge 4 commits into
mainfrom
feat/clawdbot-integration

Conversation

@johnlanni
Copy link
Copy Markdown
Contributor

@johnlanni johnlanni commented Jan 29, 2026

概述

本 PR 为 Higress AI Gateway 添加了与 Clawdbot 的深度集成,支持基于消息内容的自动路由功能,并将 Higress 作为统一的模型 provider 供 Clawdbot 使用。

主要改动

1. 改进安装脚本 (all-in-one/get-ai-gateway.sh)

  • 自动检测 Clawdbot 安装: 检查 ~/clawd 目录是否存在
  • 交互式配置: 提示用户是否启用自动路由功能
  • 默认模型配置: 允许用户配置无规则匹配时使用的默认模型
  • 直接修改配置文件: 容器启动后直接修改 /data/wasmplugins/model-router.internal.yaml
  • 自动安装: 检测到 Clawdbot 时自动安装 plugin 和 skill

2. Clawdbot Plugin (all-in-one/clawdbot-integration/plugin/)

基于 API Key 认证方式的模型 provider 插件:

  • 支持 OpenAI Completions API: 兼容 Higress 的 /v1/chat/completions 接口
  • 自动路由模型: 注册 higress/auto 模型用于基于内容的路由
  • 交互式配置: 通过 clawdbot models auth login --provider higress 配置
  • 灵活的模型列表: 支持自定义可用模型列表

3. Higress Auto Router Skill (all-in-one/skill/higress-auto-router/)

自然语言配置路由规则:

  • 自然语言理解: 用户可以描述路由意图,例如:
    • "我希望在解决困难问题时路由到claude-opus-4.5的模型"
    • "route to qwen-coder when writing code"
  • 智能触发词生成: 自动生成易记的触发短语,如:
    • 深入思考 / deep thinking → 推理模型
    • 写代码 / code: → 编码模型
    • 创意写作 / creative: → 创意写作模型
  • 直接修改配置文件: 直接修改 /data/wasmplugins/model-router.internal.yaml
  • 无需 Console API: 不依赖 Higress Console API,直接操作配置文件

使用方式

安装

cd all-in-one
./get-ai-gateway.sh

安装向导会自动:

  1. 检测 Clawdbot 安装
  2. 提示是否启用自动路由
  3. 配置默认模型
  4. 安装 plugin 和 skill
  5. 容器启动后自动配置 model-router 的自动路由

配置模型 Provider

clawdbot models auth login --provider higress

配置自动路由规则

在 Clawdbot 中直接说:

"我希望在解决困难问题时路由到claude-opus-4.5的模型"

Skill 会自动:

  1. 分析意图
  2. 生成触发短语:深入思考 / deep thinking
  3. 直接修改 model-router.internal.yaml 文件
  4. 重启 Higress 容器
  5. 确认配置完成

使用自动路由

发送请求时使用 higress/auto 作为模型:

{
  "model": "higress/auto",
  "messages": [
    {
      "role": "user",
      "content": "深入思考 如何设计一个高并发系统?"
    }
  ]
}

Higress 会根据消息内容自动路由到合适的模型。

技术细节

配置文件修改

脚本会在容器启动后:

  1. 等待 /data/wasmplugins/model-router.internal.yaml 文件生成
  2. 备份原始配置文件
  3. 使用 sedmodelToHeader 行后插入 autoRouting 配置
spec:
  defaultConfig:
    modelToHeader: x-higress-llm-model
    autoRouting:
      enable: true
      defaultModel: qwen-turbo

Plugin 配置

plugins:
  entries:
    higress-ai-gateway:
      enabled: true
      config:
        gatewayUrl: http://localhost:8080
        consoleUrl: http://localhost:8001
        autoRoutingDefaultModel: qwen-turbo

models:
  providers:
    higress:
      baseUrl: http://localhost:8080/v1
      apiKey: higress-local
      api: openai-completions
      authHeader: false
      models:
        - id: higress/auto
          name: Higress Auto Router
          api: openai-completions

优势

  1. 用户友好: 无需手动编辑配置文件,通过自然语言配置
  2. 智能路由: 根据消息内容自动选择最合适的模型
  3. 统一管理: Higress 作为统一网关,管理多个模型 provider
  4. 易于扩展: 可以通过添加新的触发短语和规则来扩展路由逻辑
  5. 无 API 依赖: 直接修改配置文件,不依赖 Higress Console API

注意事项

  • 需要 Higress AI Gateway 正在运行
  • 需要安装并配置好对应的 LLM provider API keys
  • 确保 model-router 插件已启用
  • 配置修改后需要重启 Higress 容器才能生效

相关文档


@higress-group/higress-team 请 review,如有问题欢迎讨论!


Note

Medium Risk
Touches the installer/startup script and auto-edits model-router.internal.yaml, so misconfiguration could break local gateway startup or routing behavior. Changes are scoped to optional Clawdbot/auto-routing paths and add new integration files rather than modifying core gateway runtime code.

Overview
Adds a new Clawdbot integration for Higress AI Gateway, including a provider plugin that guides users through configuring gateway/console URLs, optional API key, and an editable model list (including higress/auto for auto-routing), then patches Clawdbot configs to register the provider and enable the plugin.

Enhances get-ai-gateway.sh to detect a local Clawdbot workspace, optionally enable auto-routing during setup, install the plugin/skill into Clawdbot directories, persist auto-routing settings in default.cfg, and on start inject autoRouting config into model-router.internal.yaml (with backup + reload trigger) and show updated usage instructions. Also adds documentation for the higress-auto-router skill that updates routing rules via natural language by editing the in-container YAML and reloading.

Written by Cursor Bugbot for commit 9649654. This will update automatically on new commits. Configure here.

@johnlanni johnlanni requested a review from CH3CHO as a code owner January 29, 2026 00:29
Comment thread all-in-one/clawdbot-integration/plugin/index.ts Outdated
Comment thread all-in-one/clawdbot-integration/plugin/index.ts Outdated
Comment thread all-in-one/get-ai-gateway.sh
Comment thread all-in-one/clawdbot-integration/plugin/index.ts
Comment thread all-in-one/clawdbot-integration/plugin/index.ts
…nsole API

- Remove Console API calls from SKILL.md
- Add configureAutoRouting function to modify model-router.yaml directly
- Wait for container to generate config files before modification
- Use sed to inject auto-routing configuration into model-router.internal.yaml
- Backup original config file before modification
- Remove unused ai-gateway-with-autorouting.sh script
Comment thread all-in-one/clawdbot-integration/plugin/index.ts
Comment thread all-in-one/get-ai-gateway.sh Outdated
Comment thread all-in-one/get-ai-gateway.sh
Comment thread all-in-one/get-ai-gateway.sh
Comment thread all-in-one/get-ai-gateway.sh
Comment thread all-in-one/clawdbot-integration/plugin/clawdbot.plugin.json Outdated
- Use docker exec to modify model-router.internal.yaml inside container
- Remove container restart requirement
- Use docker cp for safer file modification (copy out, modify, copy back)
- Trigger configuration reload by touching the file
- Higress hot-reloads config from /data/wasmplugins/ automatically
- Add example Python implementation for skill
Plugin fixes (index.ts):
- Fix double prefix issue: check if modelId already starts with 'higress/'
- Fix spinner reuse: create separate spinner (spin2) for fetching models
- Add .trim() to autoRoutingDefaultModel input

Plugin manifest fix (clawdbot.plugin.json):
- Remove duplicate configSchema to avoid inconsistency with emptyPluginConfigSchema()

Shell script fixes (get-ai-gateway.sh):
- Add loadSavedConfig() to read ENABLE_AUTO_ROUTING from config on restart
- Use awk instead of sed for cross-platform compatibility (macOS/Linux)
- Add docker exec touch to trigger hot-reload without container restart
- Create generic installFiles() to reduce duplication
- Simplify user instructions in outputWelcomeMessage()
- Save AUTO_ROUTING config to config file for persistence
@johnlanni
Copy link
Copy Markdown
Contributor Author

Closing due to branch conflict. Replaced with new PR from feat/clawdbot-integration-v2.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.


async function testGatewayConnection(gatewayUrl: string): Promise<boolean> {
try {
const response = await fetch(`${gatewayUrl}/v1/models`, {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double /v1 suffix in URL paths breaks API

High Severity

The normalizeBaseUrl() function adds a /v1 suffix to URLs, but testGatewayConnection(), fetchAvailableModels(), and the provider config all append /v1 again. This creates malformed URLs like http://localhost:8080/v1/v1/models. The gateway connection test and model fetching will fail, and the baseUrl in the provider configuration will be incorrect.

Additional Locations (2)

Fix in Cursor Fix in Web

next
}
{ print }
' "$MODEL_ROUTER_FILE" > "$TEMP_FILE"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate autoRouting inserted on container recreation

Medium Severity

The awk script inserts an autoRouting block after matching modelToHeader: x-higress-llm-model without checking if one already exists. When a container is deleted and recreated (data folder persists, CONFIGURED_MARK exists), configureAutoRouting runs again on the existing YAML file that already has autoRouting. This inserts a duplicate block, producing invalid YAML with duplicate keys that would break configuration parsing.

Fix in Cursor Fix in Web

else
sed -i "$@"
fi
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused sedInPlace function is dead code

Low Severity

The sedInPlace function is defined to provide cross-platform sed in-place editing for macOS vs Linux, but it is never called anywhere in the script. The script uses awk for YAML modifications instead. This dead code adds maintenance burden and confuses developers who may expect it to be used.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant