- 
                Notifications
    You must be signed in to change notification settings 
- Fork 445
docs: Add javascript version of langgraph/sql-agent #1050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
docs: Add javascript version of langgraph/sql-agent #1050
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds the JavaScript/TypeScript version of the SQL agent tutorial, translating the Python implementation to JS. The tutorial demonstrates how to build a custom SQL agent using LangGraph that can interact with a SQLite database to answer questions.
Key changes:
- Adds JavaScript implementations alongside existing Python code using custom language fences (:::pythonand:::js)
- Includes JS-specific installation instructions with npm/yarn/pnpm examples
- Implements the complete SQL agent workflow in TypeScript, including database setup, tool creation, graph construction, and human-in-the-loop features
        
          
                src/oss/langgraph/sql-agent.mdx
              
                Outdated
          
        
      | ); | ||
| ``` | ||
| <Note> | ||
| The above implementation follows the [tool interrupt example](/oss/langgraph/add-human-in-the-loop#add-interrupts-to-any-tool) in the broader [human-in-the-loop](/oss/langgraph/add-human-in-the-loop) guide. Refer to that guide for details and alternatives. | 
    
      
    
      Copilot
AI
    
    
    
      Oct 21, 2025 
    
  
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent link reference: Line 899 uses /oss/langgraph/add-human-in-the-loop while line 1003 uses /oss/langgraph/human-in-the-loop. These should point to the same guide. Please verify the correct path and update for consistency.
| The above implementation follows the [tool interrupt example](/oss/langgraph/add-human-in-the-loop#add-interrupts-to-any-tool) in the broader [human-in-the-loop](/oss/langgraph/add-human-in-the-loop) guide. Refer to that guide for details and alternatives. | |
| The above implementation follows the [tool interrupt example](/oss/langgraph/human-in-the-loop#add-interrupts-to-any-tool) in the broader [human-in-the-loop](/oss/langgraph/human-in-the-loop) guide. Refer to that guide for details and alternatives. | 
| We will use a handy SQL database wrapper available in the `@langchain/classic/sql_db` module to interact with the database. The wrapper provides a simple interface to execute SQL queries and fetch results: | ||
|  | ||
| ```typescript | ||
| import { SqlDatabase } from "@langchain/classic/sql_db"; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using this wrapper as we already have it. Did we want to modify this to directly use typeorm rather than pulling from classic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK to pull from classic if it's doing enough work for users, alternatively better to use typeorm if the code foot print is sufficiently small.
cc @hntrl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's doing a bit of work. Mainly around getting db schema in dialect-agnostic way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not feeling to strong about whether to import things from @langchain/core vs langchain. IMHO if we re-export primitives from langchain we should do this consistently across all docs to avoid confusions.
| We'll create custom tools to interact with the database: | ||
|  | ||
| ```typescript | ||
| import { tool } from "@langchain/core/tools"; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import { tool } from "@langchain/core/tools"; | |
| import { tool } from "langchain"; | 
| ::: | ||
| :::js | ||
| ```typescript | ||
| import { AIMessage, ToolMessage, SystemMessage, HumanMessage } from "@langchain/core/messages"; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import { AIMessage, ToolMessage, SystemMessage, HumanMessage } from "@langchain/core/messages"; | |
| import { AIMessage, ToolMessage, SystemMessage, HumanMessage } from "langchain"; | 
| :::js | ||
| ```typescript | ||
| import { RunnableConfig } from "@langchain/core/runnables"; | ||
| import { tool } from "@langchain/core/tools"; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import { tool } from "@langchain/core/tools"; | |
| import { tool } from "langchain"; | 
Just translates the Python version of the langgraph sql-agent tutorial to js.
BaseMessage.toFormattedString()langchainjs#9228