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 datetime import datetime
|
||||||
from lib.personality import PERSONALITY
|
from lib.personality import PERSONALITY
|
||||||
from tools.vision import ImagePayload
|
from tools.vision import ImagePayload
|
||||||
|
from scripts import loggorilla
|
||||||
|
|
||||||
def _ts():
|
def _ts():
|
||||||
return datetime.now().strftime('%H:%M:%S')
|
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
|
session_ended = False
|
||||||
|
|
||||||
for step in range(max_iterations):
|
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
|
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)
|
session.messages.append(amsg)
|
||||||
|
|
||||||
tnames = [tc['function']['name'] for tc in response.tool_calls]
|
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:
|
if on_tool_calls:
|
||||||
on_tool_calls(response.content or "")
|
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})
|
session.messages.append({'role': 'assistant', 'content': response.content})
|
||||||
if isinstance(response.content, list):
|
if isinstance(response.content, list):
|
||||||
text_parts = [b.get('text', '') for b in response.content
|
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]"
|
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
|
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
|
return response.content, session_ended
|
||||||
# Respons kosong: tetap bawa flag session_ended — bisa jadi
|
# Respons kosong: tetap bawa flag session_ended — bisa jadi
|
||||||
# end_session sudah dipanggil di iterasi sebelumnya.
|
# end_session sudah dipanggil di iterasi sebelumnya.
|
||||||
return None, session_ended
|
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({
|
session.messages.append({
|
||||||
'role': 'assistant',
|
'role': 'assistant',
|
||||||
'content': 'Max iterations reached without final answer.',
|
'content': 'Max iterations reached without final answer.',
|
||||||
})
|
})
|
||||||
return None, session_ended
|
return None, session_ended
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user