惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
月光博客
月光博客
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
阮一峰的网络日志
阮一峰的网络日志
博客园_首页
Last Week in AI
Last Week in AI
The Cloudflare Blog
IT之家
IT之家
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
S
SegmentFault 最新的问题
量子位
大猫的无限游戏
大猫的无限游戏
Recent Announcements
Recent Announcements
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
I
InfoQ
人人都是产品经理
人人都是产品经理
G
Google Developers Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Engineering at Meta
Engineering at Meta

LangChain Forum - Latest topics

Seeking help regarding the connection between Websocket and tool calls Tool invocation error with empty error message when using `InjectedState` + `Command` return in async tool How to use @langchain/react FileSystem middleware Using ChatSnowflake with agents Built llmsessioncontract on AgentMiddleware: runtime enforcement of tool-call protocols — feedback wanted DeltaChannelHistory not found in langgraph-api:3.12 Improving citation accuracy and reducing hallucinations in custom Parent-Child RAG pipeline (Gemma3:4B + FAISS+BM25 + Cross-encoder reranker) Built a live autonomous AI agent network using LangGraph-style economics — looking for feedback How are you validating LangChain agent output before it executes shell commands? Cross-site pattern pool for production agent failures — looking for 5 pilot teams (open spec, CC-BY-4.0) Metadata filter not filtering for alerts Using custom MCP servers with assistants How to use tool calling using ChatLlamaCpp and Gemma 4 E4B with create_agent? CLI - No Longer Sending traces to Langsmith Connecting the Slack integration fails with invalid_team_for_non_distributed_app The Docs says open router can be used with init_chat_model but throws an error Interested to contribute to langgraph postgre checkpointer for multiple adapter support Modal Inference Trouble understanding and editing experiment summary evaluators feedbacks SSL certificate error from httpx with LangGraph server [Feature Request] Wire allowed_msgpack_modules in langgraph.json Serving an agent with the LangGraph CLI dev command Proposal: implement delete_for_runs for SQLite checkpoint savers WikipediaLoader endup in JSONDecodeError Human-in-the-loop approval dashboard for LangGraph agents — open source, free to deploy Ombre — open source security and audit layer for LangChain apps Should interrupt() be split into two primitives — one for human input, one for s2s data fetching? Unable to delete runs from annotation queue First Bedrock call after idle is slow on TTFT (follow-ups in the same trace are fast)
Inaccurate results from the SQL agent tutorial
2026-04-04 · via LangChain Forum - Latest topics

hi @orimdominic

In your index.js you wrote:

const agent = createAgent({
  model: chatModel,
  tool: [executeSql],
});

The correct parameter name is tools (plural):

const agent = createAgent({
  model: chatModel,
  tools: [executeSql],
});

Source: createAgent type definition - CreateAgentParams.tools:

tools?: (ServerTool | ClientTool)[];

Even after fixing the tools typo, the tool would crash with a ReferenceError. Here’s why:

Your executeSql tool is defined at the module level and references db:

// Module level
const executeSql = tool(
  async ({ query }) => {
    // ...
    const result = await db.run(q);  // <-- what `db`?
  },
  // ...
);

But db is only created inside the post() function:

async function post(req, res) {
  // ...
  const db = await SqlDatabase.fromDataSourceParams({ appDataSource: datasource });
  // `db` is local to post() -- executeSql can't see it
}

The tutorial solves this with a module-level singleton pattern (see tutorial code):

let db;

async function getDb() {
  if (!db) {
    const datasource = new DataSource({ type: "sqlite", database: "./companies.db" });
    db = await SqlDatabase.fromDataSourceParams({ appDataSource: datasource });
  }
  return db;
}

Then the tool references the module-level db (or calls getDb()):

const executeSql = tool(
  async ({ query }) => {
    const q = sanitizeSqlQuery(query);
    const database = await getDb();
    const result = await database.run(q);
    return typeof result === "string" ? result : JSON.stringify(result, null, 2);
  },
  // ...
);

Bonus: use the systemPrompt parameter

The tutorial passes the system prompt as a parameter to createAgent, not via the messages array:

const agent = createAgent({
  model: chatModel,
  tools: [executeSql],
  systemPrompt: getSystemPrompt,
});

Your current approach of injecting a SystemMessage into the messages array works, but using the dedicated systemPrompt parameter is cleaner and ensures the system prompt is handled optimally by the framework (e.g., with Anthropic’s cache control support).

Source: CreateAgentParams.systemPrompt