Agent

by get-convex6ca54f6e2e75No license6 starsListed Oct 8, 2026Updated Oct 8, 2026Repository updated today

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.

Instructions onlyAI & Agents
AI-generated overview

Adds an AI agent, chatbot, or RAG backend on Convex using @convex-dev/agent with durable threads and vector search.

What it does
Guides the setup of an in-app AI agent backend on Convex using @convex-dev/agent, covering installation, agent definition with tools and instructions, thread creation, message streaming, and persistence of history. It also describes adding RAG by embedding documents into a vector index and retrieving them in a tool. Model calls default to the Convex AI Gateway, with a provider-key fallback where the gateway is unavailable.
When to use it
Use when a user wants an AI assistant, chatbot, or agent feature, including a 'chat with my docs' capability, built on Convex. It fits projects needing durable conversation threads, tool calls, and retrieval over documents.
Requirements
Convex project with the @convex-dev/agent and @convex-dev/ai-sdk-provider packages, agent component registered in convex.config.ts, and Convex 1.45+ on a Convex Cloud deployment with a paid plan for the AI Gateway. Embeddings or gateway fallback require a provider API key stored in Convex env via the env micro power. No scripts ship with the skill.

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.

Source and attribution

Source:get-convex/convex-backend-skillinskills/agentat commit6ca54f6

License: No license

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal