[GH-ISSUE #1998] [BUG]: sql request sent 2 times #1302

Closed
opened 2026-02-22 18:24:10 -05:00 by yindo · 1 comment
Owner

Originally created by @nicho2 on GitHub (Jul 30, 2024).
Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/1998

How are you running AnythingLLM?

Docker (local)

What happened?

I use lmstudio and i see at each time i request a sql command with agent skill, the request is sending two times to the llm and to the database.

I have two times the request with : content": "You are a program which picks the most optimal function and parameters to call....

To avoid that, i have modify in lmstudio.js the "complete" function

 async complete(messages, functions = null) {
    try {
      let completion;
      if (functions.length > 0) {
        const { toolCall, text } = await this.functionCall(
          messages,
          functions,
          this.#handleFunctionCallChat.bind(this)
        );

in

  async complete(messages, functions = null) {
    try {
      let completion;
      if (functions.length > 0 && messages.slice(-1)[0].role !== "function") {
        const { toolCall, text } = await this.functionCall(
          messages,
          functions,
          this.#handleFunctionCallChat.bind(this)
        );

to avoid to recall the functionCall if the last message is the answer of the database request

but i'm not sure of my modification , but it's works

Are there known steps to reproduce?

No response

Originally created by @nicho2 on GitHub (Jul 30, 2024). Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/1998 ### How are you running AnythingLLM? Docker (local) ### What happened? I use lmstudio and i see at each time i request a sql command with agent skill, the request is sending two times to the llm and to the database. I have two times the request with : content": "You are a program which picks the most optimal function and parameters to call.... To avoid that, i have modify in lmstudio.js the "complete" function async complete(messages, functions = null) { try { let completion; if (functions.length > 0) { const { toolCall, text } = await this.functionCall( messages, functions, this.#handleFunctionCallChat.bind(this) ); in async complete(messages, functions = null) { try { let completion; if (functions.length > 0 && messages.slice(-1)[0].role !== "function") { const { toolCall, text } = await this.functionCall( messages, functions, this.#handleFunctionCallChat.bind(this) ); to avoid to recall the functionCall if the last message is the answer of the database request but i'm not sure of my modification , but it's works ### Are there known steps to reproduce? _No response_
yindo added the possible bug label 2026-02-22 18:24:10 -05:00
yindo closed this issue 2026-02-22 18:24:11 -05:00
Author
Owner

@timothycarambat commented on GitHub (Jul 30, 2024):

This will actually break a lot more function calls than you expect. For the OSS models we have function call throttling on every function that we think could be expensive, otherwise it's not a bug for an LLM to make the same tool call twice as some of them will do this for whatever reason to reach a text response.

I am not sure specific tool was being called, but if it is a low overhead one like sql-list-tables that is pretty inconsequential so its permissible especially since its not out of the realm of possibilities an agent needs to list the tables twice for a single action.

There is a call we have on mostly every skill called Deduplicator and that basically blocks OSS from infinite recursion of function calls via either one-time, a JSON signature that prevents functions with parameters from running more than once, and also a time-based cooldown. Given the variance between every OSS model and their ability to use tools and their outputs this is how we can prevent the duplication. An LLM calling a tool twice is not the end of the world, but calling it infinitely is.

Given the patch above, it would work in the case of general SQL queries but would fail on any call more than 2 steps long.

@timothycarambat commented on GitHub (Jul 30, 2024): This will actually break a lot more function calls than you expect. For the OSS models we have function call throttling on every function that we think could be expensive, otherwise it's not a bug for an LLM to make the same tool call twice as some of them will do this for whatever reason to reach a text response. I am not sure specific tool was being called, but if it is a low overhead one like _sql-list-tables_ that is pretty inconsequential so its permissible especially since its not out of the realm of possibilities an agent needs to list the tables twice for a single action. There is a call we have on mostly every skill called `Deduplicator` and that basically blocks OSS from infinite recursion of function calls via either one-time, a JSON signature that prevents functions with parameters from running more than once, and also a time-based cooldown. Given the variance between every OSS model and their ability to use tools and their outputs this is how we can prevent the duplication. An LLM calling a tool twice is not the end of the world, but calling it infinitely is. Given the patch above, it would work in the case of general SQL queries but would fail on any call more than 2 steps long.
yindo changed title from [BUG]: sql request sent 2 times to [GH-ISSUE #1998] [BUG]: sql request sent 2 times 2026-06-05 14:40:00 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#1302