360 Secure SkillHub
360 安全技能中心

convex-agent

指导在 Convex 应用中安装 @convex-dev/agent 与 @convex-dev/ai-sdk-provider,配置 agent 组件,定义工具与指令,持久化线程和消息,并通过 Convex AI Gateway 调用模型及嵌入实现向量检索 RAG;网关不可用时改用环境变量中的提供商密钥。

分类:开发
convex
热度 57.81
最近更新 2026-12-04 17:56:24

安装

发给 Agent
帮我安装这个技能: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.46+, a paid plan, and a cloud deployment or a local one linked to a project).
  3. Create threads + stream messages; persist history in Convex.
  4. For RAG: embed docs into a vector index and retrieve in the tool. Use convexGateway.embeddingModel("openai/text-embedding-3-small") for the embeddings.
  5. Only if the gateway is unavailable (free plan, self-hosted, anonymous local deployment): 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, anonymous local deployment).
  • Never expose a provider API key client-side; when one is needed (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.