Skip to main content

RAG and Agent Config Setup

rag_config and agent_config rows choose which LLM Yew Search uses for two jobs:

  • RAG config - the model that turns retrieved search results into an answer.
  • Agent config - the model for internal agent processes that run through the MCP server.

Both follow the embedding config pattern (see Embedding Config Setup): a provider routing key plus near-raw credentials/config JSON, passed to a LangChain chat model built by backend/src/common/llm/build-chat-model.ts. A RAG config is used by GET /v1/search/summary, which takes its id as ragConfigId (see Search summaries). How the agent backend runs an agent config is not built yet.

Creating a config​

POST /v1/rag-config
{
"provider": "anthropic",
"credentials": { "apiKey": "sk-ant-..." },
"config": { "model": "claude-sonnet-5-5" },
"name": "Sonnet answers",
"prompt": "Answer briefly and say which document each fact came from."
}
POST /v1/agent-config
{
"provider": "openai",
"credentials": { "apiKey": "sk-..." },
"config": { "model": "gpt-5" },
"prompt": "Work carefully and explain each step you take.",
"maxSteps": 10
}

Fields on both:

  • provider - required, one of the provider keys below
  • credentials.apiKey - required by every hosted provider except openai (which allows a keyless OpenAI-compatible server). Never returned by the API.
  • config.model - required
  • config.baseUrl - optional, for a self-hosted or proxied endpoint. Leave it out to use the provider's default API.
  • name - optional display label, falls back to config.model
  • prompt - optional personality added to the model's built-in behavior when it runs. Plain text, no placeholders.

Agent configs also have maxSteps - the most steps (model calls or tool rounds) one run may take before it's stopped, from 1 to 100, default 10. It's a separate field rather than part of the prompt so code enforces it, not the model.

Saving is checked in two steps:

  1. An unknown provider is rejected with 400 before anything else runs.
  2. The config's LangChain adapter sends the provider one short test request ("Reply with the single word OK.", capped at 16 output tokens, 60-second timeout) - the chat-model counterpart of the embedding config's embedQuery("ok") check. A wrong API key, an unknown model, an unreachable base URL or a missing model is returned as 422 with the raw LangChain/provider error, and nothing is saved. On hosted providers this costs a few tokens per save.

Updating and deleting​

PATCH /v1/rag-config/:id and PATCH /v1/agent-config/:id accept any of the create fields. credentials and config replace the stored object as a whole, and any change to provider, credentials or config is checked again the same way (a test request is sent). Changing only name, prompt or maxSteps sends nothing to the provider. Leave credentials out to keep the stored key. Send null for name or prompt to clear it.

DELETE /v1/rag-config/:id and DELETE /v1/agent-config/:id remove the config and its stored key. Nothing references these configs yet, so deleting one has no side effects.

Configs belong to one user. Another user's config id returns 404.

Provider shapes​

providercredentials.apiKeyconfig.baseUrl maps to
openaiOptional at save (needed by api.openai.com)configuration.baseURL - any OpenAI-compatible server (vLLM, LM Studio, OpenRouter, Azure OpenAI)
anthropicRequiredanthropicApiUrl
ollamaNot usedbaseUrl (e.g. http://ollama.local:11434)
google-genaiRequiredbaseUrl
mistralaiRequiredserverURL

To add a provider, add a case to buildChatModel() (with a dynamic import, like the others) and add its key to CHAT_MODEL_PROVIDERS and to PROVIDERS in frontend/src/lib/components/ChatModelConfigPage.svelte.

Frontend​

The RAG Configs and Agent Configs pages in the sidebar list, create, edit and delete configs. Both use the shared ChatModelConfigPage.svelte component. When editing, a blank API key field keeps the saved key.