Repository navigation
Conversation
to_lang_graph() built ChatOpenAI for every node that had no model_factory, whatever the node config's provider.name said, so an Anthropic or Bedrock node failed or ran on OpenAI. Each node's default model now comes from the handler's _make_default_chat_model, the same factory a single-agent call uses, so a node gets the same model class, forwarded parameters, Bedrock region prefix, and missing-extra ImportError. A caller's model_factory still wins. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
jeffdupont
left a comment
There was a problem hiding this comment.
Thanks, this is a real bug: a graph node with a non-OpenAI provider used to get ChatOpenAI anyway. The fix and the mixed-provider tests look right.
Should fix: update the shared cross-SDK contract with this. The contract still describes the ChatOpenAI default for the JS and Python toLangGraph when no model factory is given. The fix itself looks right (each node now gets the model its own provider calls for, as Go already does), so please update the contract with or right after this PR: per-node provider routing, the fallback for an unrecognised provider name, parameter forwarding, and mixed-provider graphs.
Should fix: the root README still has the broken example. You fixed node["config"] to node.config in packages/langchain-agents/README.md, but the root README.md (around line 373) still has lambda node: ChatOpenAI(model=node["config"]["model"]["name"]), which fails because GraphNode is an object. Please fix it there too and add the provider-routing note to that section.
| ) | ||
| kwargs["model"] = model_cfg.get("name") or "gpt-4o" | ||
| chat_model = lc_openai.ChatOpenAI(**kwargs) | ||
| chat_model = _make_default_chat_model(node.config) |
There was a problem hiding this comment.
This is the behaviour change the shared contract still describes as ChatOpenAI (see the summary): fine as a fix; please update the contract with or right after it.
There was a problem hiding this comment.
Agreed. I'm updating the shared contract in a separate ai-sdks-monorepo PR covering per-node provider routing, the fallback for an unrecognised provider, parameter forwarding, and mixed-provider graphs. I'll link it here when it's up.
There was a problem hiding this comment.
The contract update is in https://github.com/launchdarkly/ai-sdks-monorepo/pull/170. It replaces the ChatOpenAI default with per-node routing through the same table as the handlers, and this PR follows it. 5a7b6f4 adds the graph-span ERROR and mixed-provider tests it asks for.
…outing GraphDefinition and GraphNode are objects, so the traverse and to_lang_graph examples read attributes instead of dict keys. The to_lang_graph section now says each node's default model follows its provider.name. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Fixed the root README in 288a044: the |
… mixed-provider run Match the per-node routing rules in ai-sdks-monorepo TESTING.md (PR 170): a missing optional package now also asserts the import error is kept as the cause and the launchdarkly.graph span ends with ERROR, and a three-provider graph (Anthropic, Bedrock, OpenAI) runs a hand-off through a real StateGraph with one model of each class built. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
The contract change is up for review: https://github.com/launchdarkly/ai-sdks-monorepo/pull/170. It replaces the
A Gemini node gets the Gemini route from #320 through the same function, with nothing extra needed here. I'll add a missing 🤖 Generated with Claude Code |
Human
When a LangChain agent graph ran through
to_lang_graph()without amodel_factory, every node gotChatOpenAI, whatever provider the node's config named, so an Anthropic or Bedrock node either failed or quietly ran on OpenAI. Now each node gets the same model a single-agent call on that config would get:ChatAnthropicfor Anthropic,ChatBedrockConversefor Bedrock, andChatOpenAIotherwise, and one graph can mix providers. Amodel_factoryyou pass still wins.Bot
What changed
packages/langchain-agents/src/launchdarkly_ai_langchain_agents/native_graph.py: the inlineChatOpenAIconstruction in_traverse_nodeis replaced by a call to the handler's own_make_default_chat_model(node.config). No second factory exists. A node therefore gets the handler's per-provider class, its forwarded-parameter list and renames (for examplemax_tokens_to_sampletomax_tokens,stoptostop_sequences), the Bedrockmodel.regioninference-profile prefix, and thepip install "launchdarkly-ai-langchain-agents[anthropic]"or[aws]hint when the extra is missing. The now-unused imports of the OpenAI key lists,select_forwarded_parameters, andmodel_parametersare gone. Themodel_factorydocstring no longer says the default isChatOpenAI.langchainwire.DefaultModelits handlers use._make_default_chat_modelreaches graph nodes through this change once both merge, with no further edit.packages/langchain-agents/README.mdandpackages/langchain-agents/agents.mdnow say graph nodes pick their model by provider. Both also dropped a stale claim that hand-off tools are bound withparallel_tool_calls=False; the code never passes it, because Bedrock Converse rejects it, and routes only the first hand-off instead. The READMEmodel_factoryexample now readsnode.config, sinceGraphNodeis an object, not a dict.Graph behavior checked against non-OpenAI models
bind_toolsis called with no extra kwargs, and the hand-off tool's injectedtool_call_idstays out of the schema the model sees. Covered with the realChatAnthropicandChatBedrockConverseclasses.ChatAnthropic._get_request_payloadaccepts with the node's system prompt lifted intosystem._extract_usagereadsusage_metadata, which every LangChain chat model fills, so it is unchanged.launchdarkly.graphspan, which carries no provider or finish-reason attribute, so nothing there depended on OpenAI.Tests
New classes in
packages/langchain-agents/tests/test_native_graph.py, in the style of the existing handler tests (constructors mocked throughsys.modules):TestNativeGraphDefaultModelFollowsProvider: an Anthropic node buildsChatAnthropicwith the renamed forwarded parameters; a Bedrock node buildsChatBedrockConversewith the region-prefixed model id; anOpenAI, empty, or missing provider keepsChatOpenAI; a three-node graph gives each node its own provider's class; amodel_factorywins for every provider; and a missinglangchain-anthropicorlangchain-awssurfaces the install-hintImportErrorfrominvoke()and tracks$ld:ai:graph:invocation_failure.TestNativeGraphRealProviderModels: a router hands off through a realStateGraphwith the realChatAnthropicandChatBedrockConverseclasses, with only_ageneratereplaced.Seven of the new tests fail on
mainand pass here.Verification
All run from the repo root, matching
.github/workflows/ci.yml:uv run ruff check .: all checks passeduv run ruff format --check .: 258 files already formatteduv run mypy packages/*/src: no issues in 107 source filesuv run pytest: 4255 passed, 24 skippeduv run python scripts/api_report.py --check: 14 API reports are current (no public signature changed)make build: all packages builtmake check-packaging: passedAlso merged this branch with #320 locally: no conflicts, the
langchain-agentssuite passes (272 tests), and a Gemini graph node buildsChatGoogleGenerativeAI.Not verified: no node was run against a live Anthropic, Bedrock, or OpenAI endpoint.
🤖 Generated with Claude Code
Note
Overview
to_lang_graph()no longer forcesChatOpenAIon every node whenmodel_factoryis omitted. Each node now calls the handler’s_make_default_chat_model(node.config), so Anthropic, Bedrock, and OpenAI (or unknown) nodes get the same chat class, forwarded parameters, region-prefixed Bedrock ids, and optional-extra install hints as a single-agent invocation. A custommodel_factorystill overrides that default.Docs are aligned with
GraphNodeattribute access (not dict keys), per-provider default models in mixed graphs, and hand-off routing (noparallel_tool_calls=False; only the first transfer in a turn routes).uv.lockbumps several package versions (e.g.launchdarkly-ai-langchain-agents1.0.1).Tests add broad coverage for provider selection, missing extras, real
ChatAnthropic/ChatBedrockConversehand-offs, and a three-provider mixed graph.Reviewed by Cursor Bugbot for commit 5a7b6f4. Bugbot is set up for automated code reviews on this repo. Configure here.