Deep Agents
Text-to-SQL Agent with Deep Agents
Build a natural language to SQL agent that converts questions into database queries, validates them, and returns formatted results — using Deep Agents.
SQLdatabaseNL2SQLdata
Working Code
from deepagents import create_deep_agentfrom langchain_core.tools import toolfrom langchain_community.utilities import SQLDatabasefrom langchain_community.agent_toolkits import SQLDatabaseToolkit
db = SQLDatabase.from_uri("sqlite:///sales.db", sample_rows_in_table_info=3)toolkit = SQLDatabaseToolkit(db=db, llm=model)sql_tools = toolkit.get_tools()
agent = create_deep_agent( model="anthropic:claude-sonnet-4-5-20250929", tools=[sql_tools], system_prompt="You are a SQL analyst. Convert natural language questions into SQL queries. Only use SELECT statements. Limit results to 10 rows.",)
result = agent.invoke({ "messages": [("user", "Show me top 5 customers by total spending this quarter")]})print(result["messages"][-1].content)Step by Step
1
Install dependencies
Install Deep Agents and the required tools for this use case.
2
Define your tools
Create the domain-specific tool functions your agent will use to interact with external services.
3
Create the agent and run
Initialize the Deep Agents agent with your tools, set the system prompt, and execute a query.
Build with other frameworks
Ready to build with Deep Agents?
Generate a production-ready project with Deep Agents pre-configured — FastAPI + Next.js, auth, streaming, and more.
Get StartedReady to build your first production AI agent?
Open-source tools, battle-tested patterns, zero boilerplate. Configure your stack and ship in minutes — not months.