Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/oss/langgraph/sql-agent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Use the `SQLDatabase` wrapper available in the `langchain_community` package to
```python
from langchain_community.agent_toolkits import SQLDatabaseToolkit

toolkit = SQLDatabaseToolkit(db=db, llm=llm)
toolkit = SQLDatabaseToolkit(db=db, llm=model)

tools = toolkit.get_tools()

Expand Down Expand Up @@ -304,7 +304,7 @@ def list_tables(state: MessagesState):
def call_get_schema(state: MessagesState):
# Note that LangChain enforces that all models accept `tool_choice="any"`
# as well as `tool_choice=<string name of tool>`.
llm_with_tools = llm.bind_tools([get_schema_tool], tool_choice="any")
llm_with_tools = model.bind_tools([get_schema_tool], tool_choice="any")
response = llm_with_tools.invoke(state["messages"])

return {"messages": [response]}
Expand Down Expand Up @@ -335,7 +335,7 @@ def generate_query(state: MessagesState):
}
# We do not force a tool call here, to allow the model to
# respond naturally when it obtains the solution.
llm_with_tools = llm.bind_tools([run_query_tool])
llm_with_tools = model.bind_tools([run_query_tool])
response = llm_with_tools.invoke([system_message] + state["messages"])

return {"messages": [response]}
Expand Down Expand Up @@ -369,7 +369,7 @@ def check_query(state: MessagesState):
# Generate an artificial user message to check
tool_call = state["messages"][-1].tool_calls[0]
user_message = {"role": "user", "content": tool_call["args"]["query"]}
llm_with_tools = llm.bind_tools([run_query_tool], tool_choice="any")
llm_with_tools = model.bind_tools([run_query_tool], tool_choice="any")
response = llm_with_tools.invoke([system_message, user_message])
response.id = state["messages"][-1].id

Expand Down Expand Up @@ -407,7 +407,7 @@ async function listTables(state: typeof MessagesAnnotation.State) {

// Example: force a model to create a tool call
async function callGetSchema(state: typeof MessagesAnnotation.State) {
const llmWithTools = llm.bindTools([getSchemaTool], {
const llmWithTools = model.bindTools([getSchemaTool], {
tool_choice: "any",
});
const response = await llmWithTools.invoke(state.messages);
Expand Down Expand Up @@ -435,7 +435,7 @@ async function generateQuery(state: typeof MessagesAnnotation.State) {
const systemMessage = new SystemMessage(generateQuerySystemPrompt);
// We do not force a tool call here, to allow the model to
// respond naturally when it obtains the solution.
const llmWithTools = llm.bindTools([queryTool]);
const llmWithTools = model.bindTools([queryTool]);
const response = await llmWithTools.invoke([systemMessage, ...state.messages]);

return { messages: [response] };
Expand Down Expand Up @@ -469,7 +469,7 @@ async function checkQuery(state: typeof MessagesAnnotation.State) {
}
const toolCall = lastMessage.tool_calls[0];
const userMessage = new HumanMessage(toolCall.args.query);
const llmWithTools = llm.bindTools([queryTool], {
const llmWithTools = model.bindTools([queryTool], {
tool_choice: "any",
});
const response = await llmWithTools.invoke([systemMessage, userMessage]);
Expand Down