Prerequisites
Before you begin, ensure you have:- A SambaCloud account with an active API key
- Python 3.10 or higher installed.
langgraphandlangchain-sambanovado not support Python 3.9 or earlier. - A model that supports function calling, if your graph calls tools. The examples on this page use
Meta-Llama-3.3-70B-Instruct, which supports it. For the full list, see Function calling and JSON mode. A tool-calling graph on a model without function-calling support never emits a tool call, so the graph returns a plain text answer and skips your tool node entirely.
Installation and setup
- Create a virtual environment:
- Install the required libraries:
- Set your API key:
langchain-sambanova 1.1.1, langgraph 1.2.10, and langchain 1.3.14. To reproduce that exact set, pin them: pip install langchain-sambanova==1.1.1 langchain==1.3.14 langgraph==1.2.10.Quickstart
Instantiate a SambaCloud chat model and send your first message:ChatSambaNova reads your key from the SAMBANOVA_API_KEY environment variable. invoke returns an AIMessage, so response.content is the reply text. Once this prints a response, you can wire the model into a graph.
Build a graph
Add the model to a single-node graph. TheMessagesState schema uses the add_messages reducer, so each node’s return value is appended to the conversation instead of replacing it:
graph.invoke returns the final state, not a single reply. Because MessagesState accumulates, result["messages"] holds the whole conversation: your input first, the model’s AIMessage last. That is why the example reads result["messages"][-1].content rather than result.content.
If you print the whole state instead, you can see the shape you are indexing into:
Add a tool and a conditional edge
A single node is not yet an agent. To let the model decide when to call a tool, bind the tools to the model, add aToolNode that runs them, and route between the two with a conditional edge. tools_condition inspects the last message: if it contains tool calls it returns "tools", otherwise it ends the graph. The edge from tools back to model is what makes the loop, so the model sees each tool result and can call another tool or answer:
get_exchange_rate tool above returns hardcoded rates so the example runs without a second API key. Swap in a real rates API before you rely on the numbers.pretty_print on each message is the fastest way to confirm the loop actually ran. You should see four messages: your question, the model’s tool call, the tool result, and the final answer.
from langchain.agents import create_agent returns an equivalent compiled ReAct agent in one call. Build the graph yourself when you need to add your own nodes, custom routing, or state fields.Persist state across turns
Eachgraph.invoke call starts from a fresh state, so the graph above cannot remember anything. To keep a conversation, compile with a checkpointer and pass a thread_id. The checkpointer saves state per thread, and the thread_id selects which conversation you are continuing:
conversation-1, so the model still has the first turn. Change thread_id to a new value and the model no longer knows the name.
InMemorySaver keeps state in the process and loses it on exit, which is what you want for local development. MemorySaver is a backwards-compatible alias for the same class. For anything you deploy, use a durable checkpointer such as PostgresSaver from langgraph-checkpoint-postgres.Example use cases
You can use LangGraph with SambaCloud to create multi-agent workflows such as web search, Retrieval-Augmented Generation (RAG), and SQL agents. The examples below are complete, runnable versions of those patterns.- Agentic Search: a notebook that builds a chatbot combining a web search tool with a SambaCloud model.
- Agentic Graph RAG: a full application, not a notebook, that answers natural-language questions over a healthcare graph database using intelligent routing and generated Cypher queries. Built with LangGraph and FastAPI, with a web interface.
Troubleshooting
command not found: python
command not found: python
python executable, only python3. Use python3 -m venv .venv to create the environment. After you activate it with source .venv/bin/activate, python works as expected inside the environment.sambanova.SambaNovaError: The api_key client option must be set
sambanova.SambaNovaError: The api_key client option must be set
ChatSambaNova builds its HTTP client while the object is being constructed, so an unset SAMBANOVA_API_KEY fails on the ChatSambaNova(...) line before any request is sent. Confirm the key is visible to the process with echo $SAMBANOVA_API_KEY. An export applies only to the shell it ran in, so a new terminal or a new editor session needs it again.sambanova.AuthenticationError: Error code: 401 - Incorrect API key provided
sambanova.AuthenticationError: Error code: 401 - Incorrect API key provided
ModuleNotFoundError: No module named 'langgraph' or 'langchain_sambanova'
ModuleNotFoundError: No module named 'langgraph' or 'langchain_sambanova'
source .venv/bin/activate again, confirm the prompt shows (.venv), then re-run the install command from step 2.A model error when you did not set a model
A model error when you did not set a model
model=, ChatSambaNova falls back to its own default, Llama-4-Maverick-17B-128E-Instruct, which SambaCloud has retired and no longer serves, so the request fails rather than quietly running on a different model. Always pass model= explicitly, using an ID from SambaCloud models.ChatSambaNovaCloud does not work
ChatSambaNovaCloud does not work
ChatSambaNovaCloud. In langchain-sambanova 1.x that name is a deprecated placeholder with no implementation: the class is decorated @deprecated(since="0.2.0", removal="1.0.0") and has an empty body. Use ChatSambaNova, which serves both SambaCloud and SambaStack and selects between them from base_url.AttributeError: 'dict' object has no attribute 'content'
AttributeError: 'dict' object has no attribute 'content'
.content on the graph result. graph.invoke returns the state dictionary, not a message, so read the last message out of the state first with result["messages"][-1].content. Only llm.invoke returns an AIMessage you can read .content from directly.ValueError: Checkpointer requires one or more of the following 'configurable' keys: thread_id, checkpoint_ns, checkpoint_id
ValueError: Checkpointer requires one or more of the following 'configurable' keys: thread_id, checkpoint_ns, checkpoint_id
thread_id on every call: graph.invoke(payload, {"configurable": {"thread_id": "conversation-1"}}). Reuse the same value to continue a conversation and use a new value to start a fresh one.langgraph.errors.GraphRecursionError: Recursion limit of 25 reached
langgraph.errors.GraphRecursionError: Recursion limit of 25 reached
END. In a tool-calling graph this usually means the model calls a tool, dislikes the result, and calls it again. Print the messages with message.pretty_print() to see what is repeating. Fix the tool so it returns a usable answer or a clear error string rather than raising, and sharpen its docstring so the model knows when it is done. Raise the ceiling only once the loop itself is correct: graph.invoke(payload, {"recursion_limit": 50}).LangGraphDeprecatedSinceV10: create_react_agent has been moved to langchain.agents
LangGraphDeprecatedSinceV10: create_react_agent has been moved to langchain.agents
langgraph-prebuilt 1.1 and later, create_react_agent is deprecated. Replace from langgraph.prebuilt import create_react_agent with from langchain.agents import create_agent and call create_agent(model, tools). ToolNode and tools_condition are not deprecated, so the hand-built graph shown above stays valid.The model answers in text and never calls your tool
The model answers in text and never calls your tool
ToolNode(tools) only runs tool calls, it does not advertise them. You need both ToolNode(tools) in the graph and .bind_tools(tools) on the model.Additional resources
- LangGraph documentation for the full graph API, persistence backends, and streaming options
- langchain-sambanova on PyPI for constructor options and
ChatSambaNovareference - SambaCloud models for current model IDs, context windows, and which models support function calling
- Function calling and JSON mode to confirm which models can emit tool calls
- SambaCloud API reference

