Skip to main content

LangChain Adapter

The LangChain adapter provides unified access to multiple LLM providers — OpenAI, Anthropic, and Ollama — 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.

Backends

OperationProviderDefault ModelAPI Key Secret
langchain:openaiOpenAIgpt-4o-miniOPENAI_API_KEY
langchain:anthropicAnthropicclaude-sonnet-4-5-20250514ANTHROPIC_API_KEY
langchain:ollamaOllama (local)qwenNone required
langchain:ollama_qwen3Ollama (Qwen3)qwen3None required

Setting API Keys

Store API keys via the secrets manager:

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

Keys are resolved from the caller's secret store at invocation time.

Usage

Simple Prompt

{
"operation": "langchain:openai",
"input": {
"prompt": "What is the capital of France?",
"model": "gpt-4o"
}
}

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

Messages with System Prompt

{
"operation": "langchain:anthropic",
"input": {
"model": "claude-sonnet-4-5-20250514",
"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": "langchain:openai",
"input": {
"model": "gpt-4o",
"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": "langchain:openai",
"input": {
"model": "gpt-4o",
"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