CorfedoCorfedoDocs

LangChain

Give a LangChain agent Corfedo's code tools, or use Corfedo AI as the ChatCorfedo chat model, in TypeScript or Python.

Corfedo's LangChain integration gives your agent Corfedo's read tools, or makes Corfedo AI the chat model ChatCorfedo. It is available for LangChain.js and for LangChain in Python.

Before you begin

  • An API key file with Search and read code. Add Ask Corfedo AI to use ChatCorfedo. See API keys.
  • The packages:
npm install @corfedo/client @corfedo/langchain @langchain/core

Node.js 22.12 or later and @langchain/core 1.x.

Give your agent Corfedo's tools

import { CorfedoClient } from '@corfedo/client';
import { createCorfedoLangChainTools } from '@corfedo/langchain';

const client = CorfedoClient.fromApiKeyFile(process.env.CORFEDO_API_KEY_FILE!);
const tools = createCorfedoLangChainTools(client);
const answer = await yourModel.bindTools(tools).invoke('Where is the retry policy configured?');

You own the model and the agent loop. Each tool returns Corfedo's result as JSON text. To pick single tools, pass { groups: [], tools: ['search_code', 'read_file'] } in TypeScript or groups=[], tools=['search_code', 'read_file'] in Python.

Check: the model's tool calls name search_code or read_file, and the agent's answer cites files from your repositories.

Use Corfedo AI as the chat model

import { ChatCorfedo } from '@corfedo/langchain';

const model = new ChatCorfedo({ client });
const first = await model.invoke('How are search requests routed?', {
  configurable: { corfedo: { tools: ['search_code'] } },
});
const next = await model.invoke('Which modules call that code?', {
  corfedo: { conversationId: first.response_metadata.corfedo.conversationId },
});

The conversation lives in Corfedo. A call sends the new user message, or the results of the tools Corfedo AI asked for. The conversation comes from the conversation ID option or from the latest AI message in the history.

Corfedo options are the conversation ID, sources, references, limits and Corfedo's own tools. Pass them in configurable.corfedo so they reach calls inside agents and graphs. A direct corfedo call option wins per field. The profile chosen for the API answers.

Tools you bind with bindTools or bind_tools are client tools your agent runs. withStructuredOutput or with_structured_output asks for an answer that follows a JSON schema. Responses carry the conversation and run IDs, the outcome and the citations in response_metadata.corfedo. Aborting a call ends its subscription, not the run. client.ai.cancel with the run ID stops the run.

Check: the second answer refers to the first, which shows the conversation continued.

Troubleshooting

What you seeWhyWhat to do
CorfedoUnsupportedInputErrorThe call has a system message, non-text content, stop sequences or a tool choice other than autoRemove it. The profile owns instructions and settings.
CorfedoRunErrorThe run ended without an answerRead its outcome
CorfedoOutputDiscardedErrorText already streamed was replaced after the run recoveredRead the answer through the core client
A streamed answer contains earlier step textA streamed aggregate includes text of steps that ended with tool callsUse the completed answer from the run

On this page