Execution times are biblical: 41 seconds! Many operations are repeated an exaggerated number of times

I have a simple assistant with file search and one function. In the shop there is a database structure for invoicing with tables products customers invoice headers and invoice lines. The user asks “add invoice number 10 to the customer pizzeria il talento”.
From my log it is clear that the execution times are biblical: 41 seconds!!!
Many operations are repeated an exaggerated number of times and consume an enormous amount of tokens.
(Many times the RUN fails and many times no response is generated.)
(in the playground i get this error that i don’t get in my software: Error streaming run: Runs in status “queued” do not accept tool outputs.)

LOG: (I hope this can help in some way!)

[2024-08-23 **10:19:57**]  addMessage: asst_tfLdda9k8nXxHPi233oVshCd aggiungi una fattura numero 10 al cliente pizzeria il talento thread_1QUrReOzsymwpi1unGvbTul6
[2024-08-23 10:19:57]  addMessage response: {
  "id": "msg_IwmLJZkw5DFoU25NJq5MvWJt",
  "object": "thread.message",
  "created_at": 1724401197,
  "assistant_id": null,
  "thread_id": "thread_1QUrReOzsymwpi1unGvbTul6",
  "run_id": null,
  "role": "user",
  "content": [
    {
      "type": "text",
      "text": {
        "value": "aggiungi una fattura numero 10 al cliente pizzeria il talento",
        "annotations": []
      }
    }
  ],
  "attachments": [],
  "metadata": {}
}
[2024-08-23 10:19:57]  creaRun: https://api.openai.com/v1/threads/thread_1QUrReOzsymwpi1unGvbTul6/runs
[2024-08-23 10:19:58]  Id del Run: run_WqI7DOqbpCMXT08qN1hCkf1k
[2024-08-23 10:19:59]  Ciclowhile: in_progress run_WqI7DOqbpCMXT08qN1hCkf1k, nAction 0
[2024-08-23 10:20:00]  cicloLetturaRun_1: {
  "id": "run_WqI7DOqbpCMXT08qN1hCkf1k",
  "object": "thread.run",
  "created_at": 1724401197,
  "assistant_id": "asst_tfLdda9k8nXxHPi233oVshCd",
  "thread_id": "thread_1QUrReOzsymwpi1unGvbTul6",
  "status": "in_progress",
  ...
}
[2024-08-23 10:20:00]  run step: {
  "object": "list",
  "data": [],
  "first_id": null,
  "last_id": null,
  "has_more": false
}
[2024-08-23 10:20:01]  Ciclowhile: in_progress run_WqI7DOqbpCMXT08qN1hCkf1k, nAction 0
[2024-08-23 10:20:02]  cicloLetturaRun_2: {
  "id": "run_WqI7DOqbpCMXT08qN1hCkf1k",
  "object": "thread.run",
  "created_at": 1724401197,
  "assistant_id": "asst_tfLdda9k8nXxHPi233oVshCd",
  "thread_id": "thread_1QUrReOzsymwpi1unGvbTul6",
  "status": "in_progress",
  ...
}
[2024-08-23 10:20:02]  run step: {
  "object": "list",
  "data": [
    {
      ...
      "status": "in_progress",
      "cancelled_at": null,
      "completed_at": null,
      "expires_at": 1724401797,
      "failed_at": null,
      "last_error": null,
      "step_details": {
        "type": "tool_calls",
        "tool_calls": [
          {
            "id": "call_xUUzZWXR8YdTP6xomtHdhPtO",
            "type": "file_search",
            "file_search": {}
          }
	...
}
[2024-08-23 10:20:02]  Ciclowhile: in_progress run_WqI7DOqbpCMXT08qN1hCkf1k, nAction 0
[2024-08-23 10:20:03]  cicloLetturaRun_3: {
  "id": "run_WqI7DOqbpCMXT08qN1hCkf1k",
  "object": "thread.run",
  "created_at": 1724401197,
  "assistant_id": "asst_tfLdda9k8nXxHPi233oVshCd",
  "thread_id": "thread_1QUrReOzsymwpi1unGvbTul6",
  "status": "in_progress",
  ...
}
[2024-08-23 10:20:04]  run step: {
  "object": "list",
  "data": [
    {
      "id": "step_6V7F6LqQJjA5rFfurEYxT8fz",
      "object": "thread.run.step",
      "created_at": 1724401203,
      "run_id": "run_WqI7DOqbpCMXT08qN1hCkf1k",
      "assistant_id": "asst_tfLdda9k8nXxHPi233oVshCd",
      "thread_id": "thread_1QUrReOzsymwpi1unGvbTul6",
      "type": "message_creation",
      "status": "in_progress",
      ...
}
[2024-08-23 10:20:04]  Ciclowhile: in_progress run_WqI7DOqbpCMXT08qN1hCkf1k, nAction 0
[2024-08-23 10:20:05]  cicloLetturaRun_4: {
  "id": "run_WqI7DOqbpCMXT08qN1hCkf1k",
  "object": "thread.run",
  "created_at": 1724401197,
  "assistant_id": "asst_tfLdda9k8nXxHPi233oVshCd",
  "thread_id": "thread_1QUrReOzsymwpi1unGvbTul6",
  "status": "in_progress",
  ...
}
[2024-08-23 10:20:05]  run step: {
  "object": "list",
  "data": [
    {
      "id": "step_6V7F6LqQJjA5rFfurEYxT8fz",
      "object": "thread.run.step",
      "created_at": 1724401203,
      "run_id": "run_WqI7DOqbpCMXT08qN1hCkf1k",
      "assistant_id": "asst_tfLdda9k8nXxHPi233oVshCd",
      "thread_id": "thread_1QUrReOzsymwpi1unGvbTul6",
      "type": "message_creation",
      "status": "in_progress",
      "cancelled_at": null,
      "completed_at": null,
      "expires_at": 1724401797,
      "failed_at": null,
      "last_error": null,
      "step_details": {
        "type": "message_creation",
        "message_creation": {
          "message_id": "msg_5kheZDH3P4b8yjE6fUQcYIjQ"
        }
      },
      "usage": null
    },
    {
      "id": "step_JfY2pbFzvYBuR8ULbeBBYOG2",
      "object": "thread.run.step",
      "created_at": 1724401202,
      "run_id": "run_WqI7DOqbpCMXT08qN1hCkf1k",
      "assistant_id": "asst_tfLdda9k8nXxHPi233oVshCd",
      "thread_id": "thread_1QUrReOzsymwpi1unGvbTul6",
      "type": "tool_calls",
      "status": "completed",
      ...
}
[2024-08-23 10:20:06]  Ciclowhile: in_progress run_WqI7DOqbpCMXT08qN1hCkf1k, nAction 0
[2024-08-23 10:20:07]  cicloLetturaRun_5: {
  "id": "run_WqI7DOqbpCMXT08qN1hCkf1k",
  "object": "thread.run",
  "created_at": 1724401197,
  "assistant_id": "asst_tfLdda9k8nXxHPi233oVshCd",
  "thread_id": "thread_1QUrReOzsymwpi1unGvbTul6",
  "status": "in_progress",
  ...
}
[2024-08-23 10:20:07]  run step: {
  "object": "list",
  "data": [
    {
      "id": "step_6V7F6LqQJjA5rFfurEYxT8fz",
      "object": "thread.run.step",
      "created_at": 1724401203,
      "run_id": "run_WqI7DOqbpCMXT08qN1hCkf1k",
      "assistant_id": "asst_tfLdda9k8nXxHPi233oVshCd",
      "thread_id": "thread_1QUrReOzsymwpi1unGvbTul6",
      "type": "message_creation",
      "status": "in_progress",
      ...
    },
    {
      "id": "step_JfY2pbFzvYBuR8ULbeBBYOG2",
	  ...
      "status": "completed",
      ...
      "step_details": {
        "type": "tool_calls",
        "tool_calls": [
          {
            "id": "call_xUUzZWXR8YdTP6xomtHdhPtO",
            "type": "file_search",
            "file_search": {}
          }
        ]
      },
      ...
}
[2024-08-23 10:20:07]  Ciclowhile: in_progress run_WqI7DOqbpCMXT08qN1hCkf1k, nAction 0
[2024-08-23 10:20:08]  cicloLetturaRun_6: {
  "id": "run_WqI7DOqbpCMXT08qN1hCkf1k",
  "object": "thread.run",
  "created_at": 1724401197,
  "assistant_id": "asst_tfLdda9k8nXxHPi233oVshCd",
  "thread_id": "thread_1QUrReOzsymwpi1unGvbTul6",
  "status": "in_progress",
  ...
}
[2024-08-23 10:20:09]  run step: {
  "object": "list",
  "data": [
    {
      "id": "step_6V7F6LqQJjA5rFfurEYxT8fz",
      ...
      "status": "in_progress",
      "cancelled_at": null,
      ...
    },
    {
      "id": "step_JfY2pbFzvYBuR8ULbeBBYOG2",
      ...
      "status": "completed",
      ...
}
[2024-08-23 10:20:09]  Ciclowhile: in_progress run_WqI7DOqbpCMXT08qN1hCkf1k, nAction 0
[2024-08-23 10:20:10]  cicloLetturaRun_7: {
  "id": "run_WqI7DOqbpCMXT08qN1hCkf1k",
  "object": "thread.run",
  "created_at": 1724401197,
  "assistant_id": "asst_tfLdda9k8nXxHPi233oVshCd",
  "thread_id": "thread_1QUrReOzsymwpi1unGvbTul6",
  "status": "in_progress",
  ...
}
[2024-08-23 10:20:11]  run step: {
  "object": "list",
  "data": [
    {
      "id": "step_qLtWwF7b7Ov59Kz4G78c4d12",
      ...
      "status": "in_progress",
      "cancelled_at": null,
      "completed_at": null,
      "expires_at": 1724401797,
      "failed_at": null,
      "last_error": null,
      "step_details": {
        "type": "tool_calls",
        "tool_calls": [
          {
            "id": "call_VuJvKbe5mKOqkLhmdiQTS2dv",
            "type": "function",
            "function": {
              "name": "eseguiSQL",
              "arguments": "{\n  \"sql\": \"SELECT id FROM clienti WHERE ragsoc = 'Pizzeria Il Talento';\"\n}",
              "output": null
            }
          }
        ]
      },
      "usage": null
    },
    {
      "id": "step_6V7F6LqQJjA5rFfurEYxT8fz",
      ...
      "status": "completed",
      "cancelled_at": null,
      "completed_at": 1724401210,
      "expires_at": 1724401797,
      "failed_at": null,
      "last_error": null,
      "step_details": {
        "type": "message_creation",
        "message_creation": {
          "message_id": "msg_5kheZDH3P4b8yjE6fUQcYIjQ"
        }
      },
      ...
    },
    {
      "id": "step_JfY2pbFzvYBuR8ULbeBBYOG2",
      ...
      "status": "completed",
      ...
}
[2024-08-23 10:20:11]  Ciclowhile: requires_action run_WqI7DOqbpCMXT08qN1hCkf1k, nAction 0
[2024-08-23 10:20:11]  required_action: {
    "type": "submit_tool_outputs",
    "submit_tool_outputs": {
        "tool_calls": [
            {
                "id": "call_VuJvKbe5mKOqkLhmdiQTS2dv",
                "type": "function",
                "function": {
                    "name": "eseguiSQL",
                    "arguments": "{\n  \"sql\": \"SELECT id FROM clienti WHERE ragsoc = 'Pizzeria Il Talento';\"\n}"
                }
            }
        ]
    }
}
[2024-08-23 10:20:11]  funzione: eseguiSQL: SELECT id FROM clienti WHERE ragsoc = 'Pizzeria Il Talento';
[2024-08-23 10:20:11]  eseguequerysql: https:.../fattur/apiVarie.php
[2024-08-23 10:20:11]  eseguiSQL: {"sql":"SELECT id FROM clienti WHERE ragsoc = 'Pizzeria Il Talento';"}
[2024-08-23 10:20:11]  ActionRequired aggiungi: [{"id":3}] generico
[2024-08-23 10:20:11]  eseguiSQL jsonResponse: [{"id":3}]
[2024-08-23 10:20:11]  assistente outputs: [{"id":3}]
[2024-08-23 10:20:11]  assistente toolOutputs: {"tool_outputs":[{"tool_call_id":"call_VuJvKbe5mKOqkLhmdiQTS2dv","output":"[{\"id\":3}]"}]}
[2024-08-23 10:20:13]  cicloLetturaRun_1: 
[2024-08-23 10:20:13]  run step: {
  "object": "list",
  "data": [
    {
      "id": "step_qLtWwF7b7Ov59Kz4G78c4d12",
      ...
      "status": "completed",
      ...
      "step_details": {
        "type": "tool_calls",
        "tool_calls": [
          {
            "id": "call_VuJvKbe5mKOqkLhmdiQTS2dv",
            "type": "function",
            "function": {
              "name": "eseguiSQL",
              "arguments": "{\n  \"sql\": \"SELECT id FROM clienti WHERE ragsoc = 'Pizzeria Il Talento';\"\n}",
              "output": "[{\"id\":3}]"
            }
          }
        ]
      }
	  ...
}
[2024-08-23 10:20:14]  Ciclowhile: queued run_WqI7DOqbpCMXT08qN1hCkf1k, nAction 1
[2024-08-23 10:20:15]  cicloLetturaRun_2: {
  "id": "run_WqI7DOqbpCMXT08qN1hCkf1k",
  "object": "thread.run",
  "created_at": 1724401197,
  "assistant_id": "asst_tfLdda9k8nXxHPi233oVshCd",
  "thread_id": "thread_1QUrReOzsymwpi1unGvbTul6",
  "status": "queued",
  ...
}
[2024-08-23 10:20:15]  run step: {
  "object": "list",
  "data": [
    {
      "id": "step_qLtWwF7b7Ov59Kz4G78c4d12",
      ...
      "status": "completed",
      ...
      "step_details": {
        "type": "tool_calls",
        "tool_calls": [
          {
            "id": "call_VuJvKbe5mKOqkLhmdiQTS2dv",
            "type": "function",
            "function": {
              "name": "eseguiSQL",
              "arguments": "{\n  \"sql\": \"SELECT id FROM clienti WHERE ragsoc = 'Pizzeria Il Talento';\"\n}",
              "output": "[{\"id\":3}]"
            }
          }
        ]
      }
	  ...
}
[2024-08-23 10:20:15]  Ciclowhile: in_progress run_WqI7DOqbpCMXT08qN1hCkf1k, nAction 1
[2024-08-23 10:20:16]  cicloLetturaRun_3: {
  "id": "run_WqI7DOqbpCMXT08qN1hCkf1k",
  "object": "thread.run",
  "created_at": 1724401197,
  "assistant_id": "asst_tfLdda9k8nXxHPi233oVshCd",
  "thread_id": "thread_1QUrReOzsymwpi1unGvbTul6",
  "status": "in_progress",
  ...
}
[2024-08-23 10:20:17]  run step: {
  "object": "list",
  "data": [
    {
      "id": "step_qLtWwF7b7Ov59Kz4G78c4d12",
      ...
            "function": {
              "name": "eseguiSQL",
              "arguments": "{\n  \"sql\": \"SELECT id FROM clienti WHERE ragsoc = 'Pizzeria Il Talento';\"\n}",
              "output": "[{\"id\":3}]"
            }
          }
        ]
      },
...
}
[2024-08-23 10:20:17]  Ciclowhile: in_progress run_WqI7DOqbpCMXT08qN1hCkf1k, nAction 1
[2024-08-23 10:20:18]  cicloLetturaRun_4: {
  "id": "run_WqI7DOqbpCMXT08qN1hCkf1k",
  ...
  "status": "in_progress",
  ...
}
[2024-08-23 10:20:18]  run step: {
  "object": "list",
  "data": [
    {
      "id": "step_geBXaByYFZYt7pc3O78gCn2M",
      ..
      "type": "message_creation",
      "status": "in_progress",
      ...
      "step_details": {
        "type": "message_creation",
        "message_creation": {
          "message_id": "msg_zFTMtm3FrrEYwhDIeMBIEMdf"
        }
      },
      "usage": null
    },
    {
      "id": "step_qLtWwF7b7Ov59Kz4G78c4d12",
      ...
      "status": "completed",
      ...
      "step_details": {
        "type": "tool_calls",
        "tool_calls": [
          {
            "id": "call_VuJvKbe5mKOqkLhmdiQTS2dv",
            "type": "function",
            "function": {
              "name": "eseguiSQL",
              "arguments": "{\n  \"sql\": \"SELECT id FROM clienti WHERE ragsoc = 'Pizzeria Il Talento';\"\n}",
              "output": "[{\"id\":3}]"
            }
          }
        ]
      },
      ...
}
[2024-08-23 10:20:19]  Ciclowhile: in_progress run_WqI7DOqbpCMXT08qN1hCkf1k, nAction 1
[2024-08-23 10:20:20]  cicloLetturaRun_5: {
  "id": "run_WqI7DOqbpCMXT08qN1hCkf1k",
  "object": "thread.run",
  "created_at": 1724401197,
  "assistant_id": "asst_tfLdda9k8nXxHPi233oVshCd",
  "thread_id": "thread_1QUrReOzsymwpi1unGvbTul6",
  "status": "in_progress",
  
}
[2024-08-23 10:20:20]  run step: {
  "object": "list",
  "data": [
    ...
      "step_details": {
        "type": "tool_calls",
        "tool_calls": [
          {
            "id": "call_VuJvKbe5mKOqkLhmdiQTS2dv",
            "type": "function",
            "function": {
              "name": "eseguiSQL",
              "arguments": "{\n  \"sql\": \"SELECT id FROM clienti WHERE ragsoc = 'Pizzeria Il Talento';\"\n}",
              "output": "[{\"id\":3}]"
  ...
}
[2024-08-23 10:20:20]  Ciclowhile: in_progress run_WqI7DOqbpCMXT08qN1hCkf1k, nAction 1
[2024-08-23 10:20:21]  cicloLetturaRun_6: {
  "id": "run_WqI7DOqbpCMXT08qN1hCkf1k",
  "object": "thread.run",
  "created_at": 1724401197,
  "assistant_id": "asst_tfLdda9k8nXxHPi233oVshCd",
  "thread_id": "thread_1QUrReOzsymwpi1unGvbTul6",
  "status": "in_progress",
  ...
}
[2024-08-23 10:20:22]  run step: {
  "object": "list",
  "data": [
    {
      "id": "step_geBXaByYFZYt7pc3O78gCn2M",
      ...
      "step_details": {
        "type": "message_creation",
        "message_creation": {
          "message_id": "msg_zFTMtm3FrrEYwhDIeMBIEMdf"
        }
      },
      "usage": null
    },
    {
      "id": "step_qLtWwF7b7Ov59Kz4G78c4d12",
      "object": "thread.run.step",
      "created_at": 1724401210,
      ...
      "type": "tool_calls",
      "status": "completed",
      ...
            "function": {
              "name": "eseguiSQL",
              "arguments": "{\n  \"sql\": \"SELECT id FROM clienti WHERE ragsoc = 'Pizzeria Il Talento';\"\n}",
              "output": "[{\"id\":3}]"
            }
          }
        ]
      }
  ...
}
[2024-08-23 10:20:22]  Ciclowhile: in_progress run_WqI7DOqbpCMXT08qN1hCkf1k, nAction 1
[2024-08-23 10:20:23]  cicloLetturaRun_7: {
  "id": "run_WqI7DOqbpCMXT08qN1hCkf1k",
  "object": "thread.run",
  "created_at": 1724401197,
  "assistant_id": "asst_tfLdda9k8nXxHPi233oVshCd",
  "thread_id": "thread_1QUrReOzsymwpi1unGvbTul6",
  "status": "in_progress",
  ...
}
[2024-08-23 10:20:23]  run step: {
  "object": "list",
  "data": [
    {
      ...
        "tool_calls": [
          {
            "id": "call_VuJvKbe5mKOqkLhmdiQTS2dv",
            "type": "function",
            "function": {
              "name": "eseguiSQL",
              "arguments": "{\n  \"sql\": \"SELECT id FROM clienti WHERE ragsoc = 'Pizzeria Il Talento';\"\n}",
              "output": "[{\"id\":3}]"
            }
          }
        ]
      }...
}
[2024-08-23 10:20:24]  Ciclowhile: in_progress run_WqI7DOqbpCMXT08qN1hCkf1k, nAction 1
[2024-08-23 10:20:25]  cicloLetturaRun_8: {
  "id": "run_WqI7DOqbpCMXT08qN1hCkf1k",
  "object": "thread.run",
  "created_at": 1724401197,
  "assistant_id": "asst_tfLdda9k8nXxHPi233oVshCd",
  "thread_id": "thread_1QUrReOzsymwpi1unGvbTul6",
  "status": "in_progress",
  ...
}
[2024-08-23 10:20:25]  run step: {
  "object": "list",
  "data": [
    {
      "id": "step_WyAoramRKH7rMEThBLf6Es9u",
      ...
        "tool_calls": [
          {
            "id": "call_VuJvKbe5mKOqkLhmdiQTS2dv",
            "type": "function",
            "function": {
              "name": "eseguiSQL",
              "arguments": "{\n  \"sql\": \"SELECT id FROM clienti WHERE ragsoc = 'Pizzeria Il Talento';\"\n}",
              "output": "[{\"id\":3}]"
            }
          }
        ]
      }...
}
[2024-08-23 10:20:27]  Ciclowhile: in_progress run_WqI7DOqbpCMXT08qN1hCkf1k, nAction 1
[2024-08-23 10:20:28]  cicloLetturaRun_9: {
  "id": "run_WqI7DOqbpCMXT08qN1hCkf1k",
  "object": "thread.run",
  "created_at": 1724401197,
  "assistant_id": "asst_tfLdda9k8nXxHPi233oVshCd",
  "thread_id": "thread_1QUrReOzsymwpi1unGvbTul6",
  "status": "in_progress",
  ...
}
[2024-08-23 10:20:29]  run step: {
  "object": "list",
  "data": [
    {
      "id": "step_WyAoramRKH7rMEThBLf6Es9u",
      ...
      "step_details": {
        "type": "tool_calls",
        "tool_calls": [
          {
            "id": "call_R6cPALJXOSkNWgfCzNyqgdKe",
            "type": "function",
            "function": {
              "name": "eseguiSQL",
              "arguments": "{\n  \"sql\": \"INSERT INTO testatefattura (numero, data, idcliente, modalitapag, totaleft) VALUES (10, '2023-10-01', 3, 'bonifico', 0);\"\n}",
              "output": null
            }
          }
        ]
      }...
            "function": {
              "name": "eseguiSQL",
              "arguments": "{\n  \"sql\": \"SELECT id FROM clienti WHERE ragsoc = 'Pizzeria Il Talento';\"\n}",
              "output": "[{\"id\":3}]"
            }
          }
        ]
      }...
}
[2024-08-23 10:20:29]  Ciclowhile: requires_action run_WqI7DOqbpCMXT08qN1hCkf1k, nAction 1
[2024-08-23 10:20:29]  required_action: {
    "type": "submit_tool_outputs",
    "submit_tool_outputs": {
        "tool_calls": [
            {
                "id": "call_R6cPALJXOSkNWgfCzNyqgdKe",
                "type": "function",
                "function": {
                    "name": "eseguiSQL",
                    "arguments": "{\n  \"sql\": \"INSERT INTO testatefattura (numero, data, idcliente, modalitapag, totaleft) VALUES (10, '2023-10-01', 3, 'bonifico', 0);\"\n}"
                }
            }
        ]
    }
}
[2024-08-23 10:20:29]  funzione: eseguiSQL: INSERT INTO testatefattura (numero, data, idcliente, modalitapag, totaleft) VALUES (10, '2023-10-01', 3, 'bonifico', 0);
[2024-08-23 10:20:29]  eseguequerysql: https://.../fattur/apiVarie.php
[2024-08-23 10:20:29]  eseguiSQL: {"sql":"INSERT INTO testatefattura (numero, data, idcliente, modalitapag, totaleft) VALUES (10, '2023-10-01', 3, 'bonifico', 0);"}
[2024-08-23 10:20:29]  ActionRequired aggiungi: [] generico
[2024-08-23 10:20:29]  eseguiSQL jsonResponse: []
[2024-08-23 10:20:29]  assistente outputs: []
[2024-08-23 10:20:29]  assistente toolOutputs: {"tool_outputs":[{"tool_call_id":"call_R6cPALJXOSkNWgfCzNyqgdKe","output":"[]"}]}
[2024-08-23 10:20:31]  cicloLetturaRun_1: 
...
...
...
[2024-08-23 10:20:37]  Ciclowhile: completed run_WqI7DOqbpCMXT08qN1hCkf1k, nAction 2
[2024-08-23 10:20:38]  cicloLetturaRun_5: {
  "id": "run_WqI7DOqbpCMXT08qN1hCkf1k",
  ...
  "status": "completed",
  ...
}
[2024-08-23 10:20:38]  run step: {
  "object": "list",
  "data": [
    {
      "id": "step_KcJZOOBZLpEchYMO1vpfDdtH",
      ...
      "type": "message_creation",
      "status": "completed",
      "cancelled_at": null,
      ...
      "step_details": {
        "type": "message_creation",
        "message_creation": {
          "message_id": "msg_vrGTMfxDW3oIdzGN6Xxpky8Z"
        }
      }...
    {
      "id": "step_WyAoramRKH7rMEThBLf6Es9u",
      ...
      "created_at": 1724401224,
      ...
      "status": "completed",
      "cancelled_at": null,
      "completed_at": 1724401230,
      ...
        "tool_calls": [
          {
            "id": "call_R6cPALJXOSkNWgfCzNyqgdKe",
            "type": "function",
            "function": {
              "name": "eseguiSQL",
              "arguments": "{\n  \"sql\": \"INSERT INTO testatefattura (numero, data, idcliente, modalitapag, totaleft) VALUES (10, '2023-10-01', 3, 'bonifico', 0);\"\n}",
              "output": "[]"
            }
          }
        ]
      }...
      "step_details": {
        "type": "message_creation",
        "message_creation": {
          "message_id": "msg_zFTMtm3FrrEYwhDIeMBIEMdf"
        }
      }...
    {
      "id": "step_qLtWwF7b7Ov59Kz4G78c4d12",
      ...
      "status": "completed",
      ...
      "step_details": {
        "type": "tool_calls",
        "tool_calls": [
          {
            "id": "call_VuJvKbe5mKOqkLhmdiQTS2dv",
            "type": "function",
            "function": {
              "name": "eseguiSQL",
              "arguments": "{\n  \"sql\": \"SELECT id FROM clienti WHERE ragsoc = 'Pizzeria Il Talento';\"\n}",
              "output": "[{\"id\":3}]"
            }
          }
        ]
      }...
    {
      "id": "step_6V7F6LqQJjA5rFfurEYxT8fz",
      ...
      "step_details": {
        "type": "message_creation",
        "message_creation": {
          "message_id": "msg_5kheZDH3P4b8yjE6fUQcYIjQ"
        }
      }...
    {
      "id": "step_JfY2pbFzvYBuR8ULbeBBYOG2",
      ...
      "status": "completed",
      "cancelled_at": null,
      "completed_at": 1724401203,
      "expires_at": null,
      "failed_at": null,
      "last_error": null,
      "step_details": {
        "type": "tool_calls",
        "tool_calls": [
          {
            "id": "call_xUUzZWXR8YdTP6xomtHdhPtO",
            "type": "file_search",
            "file_search": {}
          }
        ]
      }...
}
[2024-08-23 10:20:38]  cicloLetturaRun: {"id":"run_WqI7DOqbpCMXT08qN1hCkf1k","object":"thread.run","created_at":1724401197,"assistant_id":"asst_tfLdda9k8nXxHPi233oVshCd","thread_id":"thread_1QUrReOzsymwpi1unGvbTul6","status":"completed","started_at":1724401230,"expires_at":null,"cancelled_at":null,"failed_at":null,"completed_at":1724401236,"required_action":null,"last_error":null,"model":"gpt-4o","instructions":"sei esperto di SQL crea sempre una query per soddisfare le richieste dell'utente e poi esegui la query con la funzione eseguiSQL, chiedi tutti i parametri all'utente gradualmente e proponi sempre  i valori di default. Per Esempio per inserire una fattura formata da testata e righe chiedi prima i dati della testata, poi la inserisci e poi chiedi i dati delle righe. ","tool_resources":[],"metadata":[],"temperature":0,"top_p":1,"max_completion_tokens":null,"max_prompt_tokens":null,"truncation_strategy":{"type":"auto","last_messages":null},"incomplete_details":null,"usage":{"prompt_tokens":11529,"completion_tokens":1052,"total_tokens":12581},"response_format":{"type":"text"},"tool_choice":"auto","parallel_tool_calls":false}
[2024-08-23 10:20:38]  listMessage ruolo assistant: La testata della fattura è stata inserita con successo.

### Inserimento delle Righe della Fattura

Ora, chiediamo i dettagli delle righe della fattura.

1. **ID prodotto**: (chiedere all'utente)
2. **Descrizione**: (chiedere all'utente)
3. **Quantità**: (default: 1)
4. **Prezzo unitario**: (chiedere all'utente)

Procediamo con l'inserimento delle righe della fattura.

#### Dettagli delle Righe della Fattura

- **ID prodotto**: Puoi fornire l'ID del prodotto?
- **Descrizione**: Puoi fornire la descrizione del prodotto?
- **Quantità**: (default: 1)
- **Prezzo unitario**: Puoi fornire il prezzo unitario del prodotto?

Una volta ottenuti questi dettagli, possiamo calcolare l'imponibile come \( \text{Quantità} \times \text{Prezzo unitario} \) e inserire le righe della fattura.
[2024-08-23 10:20:38]  listMessage ruolo: assistant
[2024-08-23 10:20:38]  listMessage aggiunta generico: []
[2024-08-23 10:20:38]  CicloRun: 1724401197.0762 1724401238.9179
[2024-08-23 **10:20:38**]  CicloRun: Duration of the function: 
                       **41.841644048691** secondi

!!! :dizzy_face:

Which operations are being called more than you are expecting?

Skimming through this I didn’t see anything particularly problematic, but I may have missed something.

The Runs and related Steps are clearly visible from the logo I attached.

Thanks! Regards

The tool call you mentioned, particularly something like "file_search", appears to be performing an operation that searches for relevant files or data in response to the user’s request (in this case, adding an invoice). However, based on the context and typical usage patterns, using such a tool might indeed seem like overkill if the operation could be efficiently handled by querying a local database instead.

Why the Tool Might Be Overkill:

  1. Complexity: Using a tool like "file_search" may involve external resources or complex logic that isn’t necessary for a straightforward task like adding an invoice to a client’s record.
  2. Performance: Tool calls can introduce additional overhead, especially if they involve network requests, file I/O, or other time-consuming operations. A local database query would generally be faster and more efficient.
  3. Scalability: Relying on external tools for basic operations can make the system more difficult to scale. If each operation involves an unnecessary tool call, it could slow down the system as the number of operations increases.

Why a Local Database Parse Would Be Better:

  • Efficiency: A local database can quickly and efficiently retrieve and update records without the overhead of external tool calls.
  • Simplicity: It simplifies the architecture, reducing the number of dependencies and potential points of failure.
  • Maintainability: It’s easier to maintain and debug, as the logic is centralized within the application and not dependent on external tools.

Suggested Approach:

  • Local Database Operations: For simple tasks like adding an invoice, it would be more efficient to directly query and update the local database. This could be done using SQL commands or through an ORM (Object-Relational Mapping) system.
  • Minimize Tool Usage: Reserve tool calls for operations that truly require external resources or complex processing that cannot be efficiently handled by the local database.

Conclusion:

It seems more appropriate to handle the task of adding an invoice through direct database interactions rather than invoking an external tool. By optimizing this process to use a local database parse, you would likely improve both the performance and maintainability of your system.

The SQL DB might not be optimized for the data type of … and also the agent is working with function calls to systems designed for non zero values. Let’s break this down:

  1. Zero value:
    Inserting an invoice with a total value of 0 is unusual and potentially problematic. In many business processes, an invoice with no value might be considered invalid or incomplete. This could indeed cause issues or slower processing in some database systems, especially if there are triggers or constraints checking for valid invoice amounts.

  2. Upsert of nothing:
    The operation performed wasn’t actually an upsert (update or insert), but a straight insert. However, inserting a record with minimal or potentially invalid data could cause issues.

  3. Invalid payment process:
    You’re right to question this. A zero value paired with a payment method of “bonifico” (bank transfer) is inconsistent. Usually, you wouldn’t have a payment method specified for a zero-value invoice.

  4. Database response time:
    While these factors might not directly cause the database to respond slower, they could trigger additional checks or validations that might add to the processing time. More importantly, they might cause issues down the line when trying to process or report on this invoice.

  5. Transaction not occurring:
    If the database has constraints or triggers set up to validate invoice data, it’s possible that this insert didn’t actually commit to the database due to failing these checks. The empty array response ([]) you received could indicate that no rows were affected, which might mean the insert failed silently.

To improve this process, you should:

  1. Wait to create the invoice until we have valid line items and a total.
  2. Implement proper error checking and validation before attempting to insert.
  3. Return and check the actual result of the SQL operation to confirm it succeeded.
  4. Consider using a draft or pending status for invoices that are being created but not yet complete.

Also less than one minute for invalid multi langual translation in invalid formats with 0 values for financial transactions like 'Bank Transfers" that require non 0 values to trigger their responses is super fast since it’s essentially impossible

I am currently studying all the possibilities offered by chatGPT, so my examples are simple and not optimized. Thanks to these examples, however, I have found that it has become practically mandatory to use streaming due to the response times. Furthermore, the version without streaming gives many errors. The error messages are also spartan, practically useless. The documentation is very lacking. I think I will make a comparison with Gemini advanced.
Regards
G.Poidomani

Hello I’m sure that it’s nothing that can’t be resolved with some optimize code and creative prompting intertwined with structured responses. You’ll find out that with the new models from Google that it can take as much as two to four minutes to get a response on something as simple as finish this code base but if you’d like some additional help and feel free to private message me for my phone number and I’d be glad to help you out with whatever your actual use cases since I imagine it’s not 0 value being transfer inserts and probably more along the lines of functional financial situations that involve actual bank transfers which would require another level of security on top of the methodology that I see presented and the code that you provided and would also require some additional tooling to ensure the accuracy, like maybe a calculator for a language model who’s trying to run math equations originating to matching you know financial information, like transaction numbers and amounts of costs and taxes being transfer numbers tallies and whatnot… if you feel like you’re in over your head just send me a message and I’ll send my phone number.

That doesn’t answer the question.

¯⁠\⁠_⁠(⁠ツ⁠)⁠_⁠/⁠¯

Hi @poidomani47

I’d recommend following the latency optimization guide provided by OpenAI.