Extending Archestra
Archestra provides modular extension points for adding model providers, knowledge data sources, and custom vector search backends. Paths on this page are relative to platform/.
Adding LLM Providers
A provider touches two parts of Archestra. The LLM Proxy route receives client requests, applies security guardrails, logs token usage, and forwards requests to the provider. Chat queries the provider's models and renders completions in the built-in interface.
Most providers serve an OpenAI-compatible API. They reuse OpenAI's schemas and adapter with minimal custom code. Providers with proprietary wire formats also require custom schemas, adapters, and a translator for the Model Router. The Moonshot (Kimi) provider (backend/src/routes/proxy/adapters/kimi.ts) serves as the reference implementation for OpenAI-compatible providers.
TypeScript-Guided Changes
- In
shared/model-constants.ts, add the provider ID toSupportedProvidersSchema. Add itsprovider:endpointvalue (for examplekimi:chatCompletions) toSupportedProvidersDiscriminatorSchema. - Run
pnpm type-checkfromplatform/. - Each compile error highlights a
Record<SupportedProvider, …>or exhaustive switch requiring an entry for the new provider.
OpenAI-Compatible Providers
- Types: Create
backend/src/types/llm-providers/<provider>/withapi.ts,messages.ts,tools.ts, andindex.ts. Re-export OpenAI schemas with.passthrough()to retain custom fields. Export the namespace frombackend/src/types/llm-providers/index.tsand updatebackend/src/types/interaction.ts. - Adapter: Build an adapter in
backend/src/routes/proxy/adapters/<provider>.tsusingcreateOpenAiCompatibleAdapterFactoryand export it fromadapters/index.ts. - Proxy Route: Copy
backend/src/routes/proxy/routes/kimi.tstobackend/src/routes/proxy/routes/<provider>.ts. Register the route IDs inshared/routes.ts, export the plugin frombackend/src/routes/index.ts, and register it inbackend/src/server.ts. - Configuration: In
backend/src/config.ts, exposellm.<provider>.baseUrlandchat.<provider>.apiKey. Add both toplatform/.env.exampleand the Configuration reference. - Chat Support: Add a model fetcher in
backend/src/routes/chat/model-fetchers/index.ts(usemakeBearerFetcherfor standardGET /modelsendpoints), configureproviderModelConfigsinbackend/src/clients/llm-client.ts, and register error handlers inbackend/src/routes/chat/errors.ts. - Frontend & Logging: Add the provider logo in
frontend/public/icons/, register credentials infrontend/src/components/llm-provider-api-key-form.tsx, and add a log parser inshared/interactions/llmProviders/.
Native API Providers
Providers with distinct wire formats (such as Anthropic, Gemini, Bedrock, or Cohere) require:
- Schemas: Zod request, response, message, and tool schemas in
backend/src/types/llm-providers/<provider>/. - Adapters: Implement
LLMRequestAdapter,LLMResponseAdapter,LLMStreamAdapter, andLLMProviderfrombackend/src/types/llm-provider.ts. - Model Router: Implement
<provider>-openai.tsand<provider>-openai-translator.tsinbackend/src/routes/proxy/adapters/to translate between the native protocol and OpenAI Chat Completions. - Error Handling: Map SDK-specific errors to unified types in
backend/src/routes/chat/errors.ts.
Additional Registrations and Testing
- Add the provider to
MODEL_ROUTER_SUPPORTED_PROVIDERSinshared/model-constants.tsandopenAiWireProvidersinbackend/src/routes/proxy/routes/model-router.ts. - Add provider support to
frontend/src/app/connection/clients.tsandshared/opencode-provider-routes.ts. - Run
pnpm codegento updatedocs/openapi.jsonand generated client libraries. - Add test cases to
backend/src/routes/proxy/routes/provider-matrix.rollback.test.ts.
Adding Knowledge Connectors
A knowledge connector synchronizes documents from external services (issue trackers, wikis, cloud drives) into an Archestra knowledge base on a scheduled interval. Connectors run as backend classes defining configuration schemas, sync checkpoints, and batch document generators.
TypeScript-Guided Changes
- Add the type literal to
USER_SELECTABLE_CONNECTOR_TYPESinbackend/src/types/knowledge-connector.ts. - Run
pnpm type-checkfromplatform/and resolve backend errors. - Run
pnpm codegento regenerate the typed client, then runpnpm type-checkto identify frontend form requirements.
Schemas and Connector Class
Define configuration and checkpoint schemas in backend/src/types/knowledge-connector.ts:
export const AcmeConfigSchema = z.object({
type: z.literal("acme"),
acmeBaseUrl: z.string(),
projectKeys: z.array(z.string()).optional(),
});
export const AcmeCheckpointSchema = z.object({
type: z.literal("acme"),
lastSyncedAt: z.string().optional(),
});
Create backend/src/knowledge-base/connectors/acme/acme-connector.ts extending BaseConnector:
validateConfig(config): Validates format and URL schemas, returning{ valid, error? }.testConnection({ config, credentials }): Proves credentials work via a lightweight API call.sync({ config, credentials, checkpoint }): Async generator yielding batches of documents and updated checkpoints. UsebuildCheckpointwith the newest item's timestamp rather than clock time.- Use
fetchWithRetry()(built-in 30s timeout and exponential backoff) andrateLimit().
Registration and UI
- Add the factory to
connectorRegistryinbackend/src/knowledge-base/connectors/registry.ts. - Add the display name to
CONNECTOR_TYPE_LABELSinshared/knowledge-base.ts. - Create
frontend/src/app/knowledge/knowledge-bases/_parts/acme-config-fields.tsxand register it inconnector-dialog-config.tsx. Add the icon tofrontend/public/icons/. - Add unit tests in
backend/src/knowledge-base/connectors/acme/acme-connector.test.ts.
Adding Knowledge Retrieval Backends
A retrieval backend indexes knowledge chunks and executes semantic vector and keyword searches. PostgreSQL with pgvector is Archestra's default built-in backend. Deployments can configure secondary search clusters (such as OpenSearch) to index chunks externally while keeping PostgreSQL as the authoritative store for documents and access control.
The Contract
Implement KnowledgeRetrievalBackend in backend/src/knowledge-base/retrieval-backend.ts:
insertChunks: Persists chunks and indexes searchable text fields.indexEmbeddings: Stores embedding vectors for a specific dimension.vectorSearchandkeywordSearch: Executes ranking queries against semantic embeddings and keyword indexes.findNeighborsandfindParentSiblings: Retrieves adjacent chunks for context expansion.deleteDocumentChunks: Idempotently removes indexed chunks when documents change or delete.
Security and Verification
Always set requiresResultVerification = true on external backends. Archestra reloads every candidate chunk from PostgreSQL and enforces connector, ACL, environment, and metadata permissions. The external index supplies search ranking scores, while PostgreSQL provides authoritative document content and citations.
Registration and Configuration
- Expose backend connection parameters under
kbinbackend/src/config.ts. - Register the implementation in
backend/src/knowledge-base/retrieval-backends/registry.tsbased onconfig.kb.retrievalBackend. - Document environment variables in
platform/.env.exampleand Configuration. - Run backend tests with
pnpm --filter @backend test -- knowledge-base.
