Skip to main content

LangChain Adapter

The LangChain adapter provides unified access to multiple LLM providers — OpenAI, Anthropic, Ollama, and xAI, plus any OpenAI-compatible endpoint — with a consistent interface for messages, tool calling, and structured output.

This adapter powers the Level 3 (LLM call) layer in the agent architecture. It can also be invoked directly for one-shot LLM calls. Covia is model-agnostic; the default models below are what a backend uses when you don't set model, not a recommendation.

Backends

OperationProviderDefault ModelAPI Key Secret
langchain:openaiOpenAIgpt-5.4-miniOPENAI_API_KEY
langchain:anthropicAnthropicclaude-sonnet-4-5ANTHROPIC_API_KEY
langchain:ollamaOllama (local)qwenNone required
langchain:xaixAI (Grok)grok-4XAI_API_KEY

Other OpenAI-compatible providers (DeepSeek, Google Gemini, gateways) work through langchain:openai by setting the url field — e.g. "url": "https://api.deepseek.com/v1".

Setting API Keys

Store API keys via the secrets manager:

{ "operation": "v/ops/secret/set", "input": { "key": "OPENAI_API_KEY", "value": "sk-..." } }
{ "operation": "v/ops/secret/set", "input": { "key": "ANTHROPIC_API_KEY", "value": "sk-ant-..." } }

Keys are resolved from the caller's secret store at invocation time. A backend that requires a key but can't resolve one fails fast with an error naming the secret it expected — it does not silently continue.

Usage

Simple Prompt

{
"operation": "v/ops/langchain/openai",
"input": {
"prompt": "What is the capital of France?",
"model": "gpt-5.4-mini"
}
}

Response: { "response": "The capital of France is Paris." }

Messages with System Prompt

{
"operation": "v/ops/langchain/anthropic",
"input": {
"model": "claude-sonnet-4-5",
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "Explain lattice technology in one paragraph." }
]
}
}

Response:

{
"role": "assistant",
"content": "Lattice technology is a mathematical framework..."
}

Tool Calling

Provide tool definitions and the LLM can request tool calls:

{
"operation": "v/ops/langchain/openai",
"input": {
"model": "gpt-5.4-mini",
"messages": [
{ "role": "user", "content": "What's the weather in London?" }
],
"tools": [
{
"name": "get_weather",
"description": "Get current weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": { "type": "string" }
},
"required": ["city"]
}
}
]
}
}

Response:

{
"role": "assistant",
"toolCalls": [
{ "id": "call_abc123", "name": "get_weather", "arguments": { "city": "London" } }
]
}

To continue the conversation, execute the tool and send the result back:

{
"messages": [
{ "role": "user", "content": "What's the weather in London?" },
{ "role": "assistant", "toolCalls": [{ "id": "call_abc123", "name": "get_weather", "arguments": { "city": "London" } }] },
{ "role": "tool", "id": "call_abc123", "name": "get_weather", "content": "{\"temp\": 15, \"condition\": \"cloudy\"}" }
],
"tools": [...]
}

Structured Output

Request JSON output conforming to a schema:

{
"operation": "v/ops/langchain/openai",
"input": {
"model": "gpt-5.4-mini",
"messages": [
{ "role": "user", "content": "Extract the person's name and age from: 'Alice is 30 years old'" }
],
"responseFormat": {
"name": "PersonInfo",
"schema": {
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer" }
},
"required": ["name", "age"],
"additionalProperties": false
}
}
}
}

The OpenAI backend enables strict mode by default — the response is guaranteed to conform to the schema.

Input Reference

ParameterTypeDefaultDescription
promptstringSimple prompt (alternative to messages)
systemPromptstringSystem message (with prompt mode)
messagesarrayConversation messages (system, user, assistant, tool)
toolsarrayTool definitions for function calling
modelstringBackend defaultModel name override
responseFormatstring or object"text""text", "json", or {name, schema}
apiKeystringFrom secret storeOverride API key
urlstringBackend defaultOverride API endpoint (use for OpenAI-compatible providers)

Assistant responses also carry tokens ({input, output, total}) and finishReason when the provider reports them.