Agent

作者 get-convex6ca54f6e2e75無授權條款6 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫今天更新

Add an AI agent / chatbot / RAG backend on Convex with @convex-dev/agent (durable threads, messages, tools, vector search). TRIGGER when the user wants an AI assistant/chatbot/agent or 'chat with my docs' feature. Calls models through the Convex AI Gateway — no provider key to manage.

僅含說明AI & Agents
AI 產生的概覽

在 Convex 上使用 @convex-dev/agent 加入 AI 代理、聊天機器人或 RAG 後端,支援持久化執行緒與向量檢索。

功能
指導在 Convex 上建置應用程式內的 AI 代理後端,使用 @convex-dev/agent,涵蓋安裝、定義含工具與指示的代理、建立執行緒、串流訊息,以及持久化歷史記錄。也說明如何將文件嵌入向量索引並在工具中檢索,以加入 RAG。模型呼叫預設走 Convex AI Gateway,在閘道無法使用時改用供應商金鑰。
適用情境
適用於使用者想在 Convex 上打造 AI 助理、聊天機器人或代理功能,包括「與我的文件對話」能力時。適合需要持久化對話執行緒、工具呼叫與文件檢索的專案。
執行需求
需要 Convex 專案,安裝 @convex-dev/agent 與 @convex-dev/ai-sdk-provider 套件,並在 convex.config.ts 註冊 agent 元件;使用 AI Gateway 需 Convex 1.45+ 的 Convex Cloud 部署與付費方案。嵌入或閘道備援需透過 env 微功能將供應商 API 金鑰存入 Convex 環境變數。此技能未附帶指令碼。

Add an AI agent / RAG backend

Install @convex-dev/agent for durable threads, message history, tool-calls, and vector search/RAG — the backend for an in-app AI agent. Call models through the Convex AI Gateway by default: Convex holds the provider credentials, so there is no LLM key to obtain, store, or rotate.

Steps

  1. Install @convex-dev/agent + @convex-dev/ai-sdk-provider; add the agent component to convex.config.ts.
  2. Define the agent (tools, instructions) with languageModel: convexGateway("provider/model") — no API key needed (needs convex 1.45+ on a Convex Cloud deployment, paid plan).
  3. Create threads + stream messages; persist history in Convex.
  4. For RAG: embed docs into a vector index and retrieve in the tool. The gateway does not serve embeddings yet, so store the embedding provider's key via the env micro power.
  5. Only if the gateway is unavailable (free plan, self-hosted, local backend): call the provider SDK with a key stored via the env micro power.

Rules

  • Default to the Convex AI Gateway (convexGateway from @convex-dev/ai-sdk-provider) for model calls; fall back to a provider key in Convex env only where the gateway is unavailable (free plan, self-hosted, local backend).
  • Never expose a provider API key client-side; when one is needed (embeddings, gateway fallback), keep it in Convex env via the env micro power.
  • Run model calls in actions ('use node' if the SDK needs it).
  • Persist threads/messages in Convex for durability + reactivity.

來源與署名

來源:get-convex/convex-backend-skill位於skills/agent提交6ca54f6

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架