From de4e3cadb46370c3e9ff369d21a8ce152c73ffa1 Mon Sep 17 00:00:00 2001 From: Dita Aji Pratama Date: Sun, 27 Sep 2026 06:21:49 +0700 Subject: [PATCH] loggorilla implementation for agent_loop --- lib/agent_loop.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/agent_loop.py b/lib/agent_loop.py index 34850cd..b9f01ef 100644 --- a/lib/agent_loop.py +++ b/lib/agent_loop.py @@ -2,6 +2,7 @@ import json from datetime import datetime from lib.personality import PERSONALITY from tools.vision import ImagePayload +from scripts import loggorilla def _ts(): return datetime.now().strftime('%H:%M:%S') @@ -30,7 +31,7 @@ def run_agent_loop(session, llm_client, TOOLS, TOOL_HANDLERS, max_iterations, on session_ended = False for step in range(max_iterations): - print(f'[{_ts()}] Step {step + 1} — calling LLM...', flush=True) + loggorilla.prcss("agent_loop", f"Step {step + 1} — calling LLM...") disable_reasoning = PERSONALITY.disable_reasoning @@ -45,7 +46,7 @@ def run_agent_loop(session, llm_client, TOOLS, TOOL_HANDLERS, max_iterations, on session.messages.append(amsg) tnames = [tc['function']['name'] for tc in response.tool_calls] - print(f'[{_ts()}] Using tools: {", ".join(tnames)}', flush=True) + loggorilla.fyinf("agent_loop", f"Using tools: {', '.join(tnames)}") if on_tool_calls: on_tool_calls(response.content or "") @@ -75,20 +76,19 @@ def run_agent_loop(session, llm_client, TOOLS, TOOL_HANDLERS, max_iterations, on session.messages.append({'role': 'assistant', 'content': response.content}) if isinstance(response.content, list): text_parts = [b.get('text', '') for b in response.content - if isinstance(b, dict) and b.get('type') == 'text'] + if isinstance(b, dict) and b.get('type') == 'text'] text = '\n'.join(text_parts) if text_parts else "[Image generated]" - print(f'[{_ts()}] Response generated (multimodal)', flush=True) + loggorilla.prcss("agent_loop", "Response generated (multimodal)") return text, session_ended - print(f'[{_ts()}] Response generated ({len(response.content)} chars)', flush=True) + loggorilla.prcss("agent_loop", f"Response generated ({len(response.content)} chars)") return response.content, session_ended # Respons kosong: tetap bawa flag session_ended — bisa jadi # end_session sudah dipanggil di iterasi sebelumnya. return None, session_ended - print(f'[{_ts()}] Max iterations ({max_iterations}) reached', flush=True) + loggorilla.prcss("agent_loop", f"Max iterations ({max_iterations}) reached") session.messages.append({ 'role': 'assistant', 'content': 'Max iterations reached without final answer.', }) return None, session_ended -