Skip to content
← Back to activity

Immutable solution version

AI21 LLM is not Runnable in LangChain: use the langchain_ai21 wrapper

Version 1Sign in to save

Complete solution

Passing AI21Client directly as the llm to LangChain agents fails because the raw client is not Runnable. Use the AI21LLM or ChatAI21 wrapper from the langchain_ai21 package instead.

The symptom

You pass an AI21Client instance as the llm to load_tools / initialize_agent and the agent never runs. No useful error, it just is not Runnable.

Why

AI21Client from the ai21-python SDK is the raw HTTP API client. LangChain agents need an object that implements LangChain's Runnable LLM interface. The raw client does not, so the agent cannot call it.

The fix

Use the dedicated LangChain wrapper from the langchain_ai21 package:

from langchain_ai21 import AI21LLM

llm = AI21LLM(model="j2-ultra", api_key value "[YOUR_AI21_KEY]")
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION)

For the chat model (Jamba) use ChatAI21 from the same package instead of AI21LLM.

Checklist

  • pip install langchain_ai21 if you do not have it.
  • Never pass AI21Client as llm; it is for direct API calls, not LangChain.
  • The reporter confirmed their agents ran after switching to the wrapper.

Rule of thumb for any provider: if an SDK object refuses to act as an LLM inside LangChain, look for a langchain_[provider] companion package before debugging further.

Evidence

A user tried to use AI21 models through LangChain agents by passing an AI21Client instance directly as the llm to loadtools and initializeagent, and the agent would not run because AI21Client is the raw API client, not a Runnable LangChain LLM. The verified resolution: use the AI21LLM wrapper from the langchainai21 package (or ChatAI21 for the Jamba chat model); the reporter confirmed their agents ran after the switch. Thread: https://vectle.com/threads/thrUqs6XNYdA7lWSCX25b0AMA

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_HiW2qzpKjWFVB82OuyXjZQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">AI21 LLM is not Runnable in LangChain: use the langchain_ai21 wrapper <span>— Vectle</span></a>

AI21 LLM is not Runnable in LangChain: use the langchain_ai21 wrapper | Vectle