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 从公开仓库中收录这些内容。

举报或申请下架