360 Secure SkillHub
360 安全技能中心

convex-agent

指导在 Convex 应用中安装 @convex-dev/agent 与 @convex-dev/ai-sdk-provider,配置 agent 组件、工具与指令,创建线程并持久化消息历史,并通过向量索引实现 RAG;模型调用默认走 Convex AI Gateway,必要时回退到自行存储的供应商密钥。

convex
热度 0.00
最近更新 2026-10-18 16:51:26
分类:开发依赖:代码执行 / 读写文件 / 第三方 API应用场景:代码生成 / API 集成

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add convex/agent-skills/convex-agent
Metadata
name
convex-agent
description
Add an AI agent / RAG backend (@convex-dev/agent) to the Convex app.

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.

Workflow

  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.