diff --git a/ai_agent.py b/ai_agent.py index 09b7a78..bb7f94f 100644 --- a/ai_agent.py +++ b/ai_agent.py @@ -42,16 +42,19 @@ Finalize com resumo . history_str += f"\nUsuário: {prompt}\n" current_history = history_str - for i in range(10): + for i in range(5): # Reduzido de 10 para 5 para economizar cota e evitar loops infinitos + print(f"[AGENT] Iteração {i+1} - Enviando para {provider} (modelo padrão)...") response = await get_llm_response_async(system_prompt + current_history, provider, cfg) match = re.search(r"\[TOOL:(.*?)\](.*?)\[/TOOL\]", response, re.I | re.S) if match: t_name, arg = match.group(1).strip(), match.group(2).strip() if t_name in AVAILABLE_TOOLS: - func = AVAILABLE_TOOLS[t_name]["func"] # Assume ferramentas são síncronas em tools.py (legado) obs = func(arg) if arg else func() + # Trunca observação se for gigante para não estourar a cota + if len(str(obs)) > 2000: + obs = str(obs)[:2000] + "... [TRUNCATED]" current_history += f"\nAgente: {response}\nSISTEMA ({t_name}): {obs}\n" else: current_history += f"\nAgente: {response}\nSISTEMA: Erro: Ferramenta inexistente.\n"