Skip to content
AI chat model runni...
 
Notifications
Clear all

AI chat model running twice and incurring costs twice

6 Posts
4 Users
0 Reactions
4 Views
ezraluandre
(@ezraluandre)
Posts: 2
New Member
Topic starter
 

Hi, I'd like to inquire about an AI chat model running twice due to tool usage. I have an AI agent that needs to check a database. If it finds recorded data for the same item, it should remove that item from the output. For example, the AI agent receives a batch of data and searches the database. If there's no duplicate data, all the data is outputted. However, if there are duplicates, it should only output the non-duplicated data.

When I ran the AI agent, I observed that the AI chat model executed twice: once before the tool usage and once after. Upon reviewing the logs, I saw the first call where the AI agent stated something like, "I will check the database for duplicate data." The second call then produced the output that would be used for the subsequent node.

The issue is that when I examined the second AI chat model call, it had the same input prompt as the first call. Furthermore, checking the usage logs confirmed that it indeed incurred double the cost. Is this the expected behavior for the AI agent, or is there something else going on?

 
Posted : 15/07/2025 6:54 am
alexhuy
(@alexhuy)
Posts: 7
Active Member
 

Hi

Since you're utilizing the AI Agent node, it's expected for the model to execute twice: once to determine if a tool should be used, and again after the tool has returned data. This behavior is inherent to the agent's design, following ReAct logic. Both of these executions are counted individually towards usage.

 
Posted : 15/07/2025 8:22 am
ezraluandre
(@ezraluandre)
Posts: 2
New Member
Topic starter
 

Thanks for clarifying. I initially thought this behavior was unusual, given how AI chat models typically operate. A problem occurred when I used the HTTP request node for a query search, causing the AI chat model to run nine times, which was nine times the cost of a single task. Since this is the expected behavior, I believe I need to find a solution to prevent the AI chat model from running multiple times.

 
Posted : 15/07/2025 3:08 pm
zynate
(@zynate)
Posts: 5
Active Member
 

Yes, this is anticipated. The AI Agent invokes the chat model two times: initially to determine which tools to employ (for planning), and subsequently after receiving tool results (for final reasoning). Each invocation utilizes tokens independently, meaning you will be charged for both.

 
Posted : 15/07/2025 3:10 pm
alexhuy
(@alexhuy)
Posts: 7
Active Member
 

You can use alternative methods for searching, such as SerpAPI or Tavily.

 
Posted : 15/07/2025 3:21 pm
system
(@system)
Posts: 332
Reputable Member
 

This thread was automatically closed 7 days following the last response. New replies are no longer permitted.

 
Posted : 22/07/2025 3:22 pm
Share: