Agent skill · software engineering · jeremylongshore

langchain-model-inference

Invoke Claude, GPT-4o, and Gemini through LangChain 1.0 without tripping

Why this skill is useful

Adds executable scripts for initializing and routing models in LangChain 1.0, addressing specific quirks and pitfalls not covered in standard documentation.

What it needs

Requires langchain-anthropic, langchain-openai, python installed locally. Requires anthropic, google, openai account access. About 5k tokens when loaded. Last updated 2026-08-07. 2,604 stars on the source repository.

What this skill does

LangChain Model Inference (Python) Overview AIMessage.content is a str on simple OpenAI calls and a list[dict] on Claude the instant any tooluse, thinking, or image block enters the response. Code that does message.content.lower() crashes with AttributeError: 'list' object has no attribute 'lower' — the #1 first-production-call LangChain 1.0 bug on Anthropic. And that is one of four separate "content shape" pitfalls in this skill: P02 — AIMessage.content list-vs-string divergence P03 — withstructuredoutput(method="functioncalling") silently drops Optional[list[X]] fields on ~40% of real schemas P05 — temperature=0 is not deterministic on Anthropic even though it is on OpenAI P58 — Claude expects the system message at position 0; middleware that reorders messages makes it silently ignored This skill walks through ChatAnthropic, ChatOpenAI, and ChatGoogleGenerativeAI initialization; model routing; token counting that is actually correct during streaming; content-block iteration; and a decision tree for withstructuredoutput methods that holds up on real schemas. Pin: langchain-core 1.0.x, langchain-anthropic 1.0.x, langchain-openai 1.0.x, langchain-google-genai 1.0.x. Pain-catalog anchors: P01, P02, P03, P04, P05, P53, P54, P58, P63, P64, P65. Prerequisites Python 3.10+ langchain-core >= 1.0, < 2.0 At least one provider package: pip install langchain-anthropic langchain-openai Provider API key(s): ANTHROPICAPIKEY, OPENAIAPIKEY, GOOGLEAPIKEY Instructions Step 1 — Initialize a chat model with explicit, version-safe defaults Explicit timeout and maxretries are not optional in production — the defaults are wrong for every workload we have measured. maxretries=6 (the default on ChatOpenAI) means a single logical call can bill as 7 requests on flaky networks. Step 2 — Iterate AIMessage.content as typed blocks, not strings AIMessage.text() (1.0+) does this for you in most cases — prefer it. Roll your own only when you need to filter by block type (tooluse, image, thinking). …

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills jeremylongshore/langchain-model-inference--83990d

View the source on GitHub

Browse the @skills marketplace