> ## Documentation Index
> Fetch the complete documentation index at: https://docs.onecortex.io/llms.txt
> Use this file to discover all available pages before exploring further.

# LangChain

> Deploy a LangChain chain or AgentExecutor as it is, with its tool calls and results.

## What is supported

LangChain 1.x chains and `AgentExecutor` (from `langchain-classic`): anything with `invoke` and `input_keys`. A LangChain agent made with `create_agent` is a LangGraph graph, and runs as one: see [LangGraph](/frameworks/langgraph).

## A complete agent

```yaml agent.yml theme={null}
apiVersion: v1
runtime: python3.12
entrypoint: agent.py:executor
dependencies: requirements.txt
```

```text requirements.txt theme={null}
langchain-classic>=1.0
langchain-openai>=1.0
```

```python agent.py theme={null}
from langchain_classic.agents import AgentExecutor, create_tool_calling_agent
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI


@tool
def word_count(text: str) -> int:
    """Counts the words in a piece of text."""
    return len(text.split())


# Reads OPENAI_API_KEY, which you add as a secret on the agent's Config tab.
model = ChatOpenAI(model="gpt-5")
prompt = ChatPromptTemplate.from_messages([
    ("system", "Count the words in what the user says, then answer."),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}"),
])
executor = AgentExecutor(agent=create_tool_calling_agent(model, [word_count], prompt), tools=[word_count])
```

Add `OPENAI_API_KEY` as a secret on the agent's **Config** tab, then deploy. Any model works: this one is an example. See [Configuration and secrets](/build/configuration).

<Card title="A complete LangChain example" icon="github" href="https://github.com/onecortex-io/examples/tree/main/expense-assistant">
  `expense-assistant`: A tool calling agent run by an `AgentExecutor`, converting and recording expenses. It runs with no model key.
</Card>

## The prompt and the reply

The prompt goes in the chain's `input` key, or its first input key if it has no `input`. A chain with `chat_history` gets an empty history.

## Events it reports

| Events | From |
| - | - |
| `text` | The chain's final output, once. The model's tokens are not streamed, because an executor streams its reasoning through the same channel |
| `tool_call_start`, `tool_call_args`, `tool_call_end` | Each tool call, complete |
| `tool_result` | Each tool's output, with `isError` when it raised |
| `done` or `error` | The end of the run: always exactly one |

See [Streaming and events](/build/streaming).

## The caller's fields

Under `configurable.onecortex` in the run's config, for a chain that reads it. An `AgentExecutor` does not pass its config to tools, so an executor's tools cannot read them: build the agent as a LangGraph graph instead.

## Known limits

* The reply arrives once, at the end, not token by token.
* An `AgentExecutor`'s tools cannot read the caller's fields.

## Troubleshooting

| You see | Do this |
| - | - |
| A tool's error arrives as an ordinary result | An executor turns a tool's exception into an answer for the model. That is LangChain's behaviour, reported as it is. |

More on [Troubleshooting](/production/troubleshooting) and [Errors](/production/errors).
