Skip to content

Commit 61099ef

Browse files
committed
Enhance AI chat functionality by increasing maximum tool calling rounds from 4 to 25 and adding a warning for reaching the maximum limit. Updated system message to emphasize schema discovery before querying.
1 parent 961a6c0 commit 61099ef

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

utils/ai.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,16 @@ def chat(messages: List[Dict[str, str]], model: str = "openrouter/auto") -> Gene
6262
'You are a network analysis assistant with access to routing database tools. '
6363
'When useful, call the available tools to fetch precise data before answering. '
6464
'If the user asks for ASN, prefixes, neighbors, flaps, or stats, use tools. '
65-
'Think through problems step by step and use tools when needed to get accurate data.'
65+
'Think through problems step by step and use tools when needed to get accurate data. '
66+
'Always start with schema discovery tools to understand the database structure before querying.'
6667
)
6768
}
6869

6970
conversation = [system_message] + list(messages)
7071
tools = _build_tools_schema()
7172

72-
# Maximum 4 rounds of tool calling
73-
for round_num in range(4):
73+
# Maximum rounds of tool calling
74+
for round_num in range(25):
7475
try:
7576
# Create chat completion with tools
7677
response = client.chat.completions.create(
@@ -176,6 +177,11 @@ def chat(messages: List[Dict[str, str]], model: str = "openrouter/auto") -> Gene
176177
yield {'type': 'error', 'message': str(e)}
177178
return
178179

180+
# Check if we hit the maximum rounds limit
181+
if round_num >= max_rounds:
182+
app.logger.warning(f"Reached maximum tool calling rounds ({max_rounds})")
183+
yield {'type': 'assistant_delta', 'delta': 'I\'ve reached the maximum number of tool calling rounds. Let me provide a response based on the information gathered so far.'}
184+
179185
# Fallback if no response
180186
yield {'type': 'assistant_delta', 'delta': 'I apologize, but I encountered an issue processing your request.'}
181187
yield {'type': 'assistant_done'}

0 commit comments

Comments
 (0)