loggorilla implementation for agent_loop
This commit is contained in:
parent
d84328d7a1
commit
de4e3cadb4
@ -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 "")
|
||||
@ -77,18 +78,17 @@ def run_agent_loop(session, llm_client, TOOLS, TOOL_HANDLERS, max_iterations, on
|
||||
text_parts = [b.get('text', '') for b in response.content
|
||||
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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user