From 73b487e3cbe763bcc50c7a936f92b87a00a24dbf Mon Sep 17 00:00:00 2001 From: Dita Aji Pratama Date: Fri, 24 Jul 2026 19:07:09 +0700 Subject: [PATCH] Slop Code --- config.py | 1 + interfaces/tui/agent.py | 9 ++++++++- lib/agent_loop.py | 21 ++++++++++++++++----- lib/gadget.py | 4 ++-- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/config.py b/config.py index eeec69c..fa2f2d8 100644 --- a/config.py +++ b/config.py @@ -44,6 +44,7 @@ for prov in _providers: "base_url" : base_url, "api_key" : api_key, "default" : is_default, + "vision" : m.get("vision", False), }) diff --git a/interfaces/tui/agent.py b/interfaces/tui/agent.py index 4f3dfe4..e4d08a3 100644 --- a/interfaces/tui/agent.py +++ b/interfaces/tui/agent.py @@ -3,6 +3,7 @@ import threading from datetime import datetime import config from lib import ntro, agent_loop +from tools.vision import ImagePayload def _add_msg(app, role, content, **kwargs): @@ -159,7 +160,13 @@ def _agent_loop(app): })) app.scroll = 999999 result = agent_loop.execute_tool(tc, app.TOOL_HANDLERS) - _add_msg(app, "tool", str(result), tool_call_id=tc["id"]) + if isinstance(result, ImagePayload): + _add_msg(app, "tool", [ + {"type": "text", "text": f"[Image loaded: {result.path}]"}, + {"type": "image_url", "image_url": {"url": f"data:{result.mime};base64,{result.data}"}} + ], tool_call_id=tc["id"]) + else: + _add_msg(app, "tool", str(result), tool_call_id=tc["id"]) else: if response.content: _add_msg(app, "assistant", response.content) diff --git a/lib/agent_loop.py b/lib/agent_loop.py index 73fbbde..9dd98cf 100644 --- a/lib/agent_loop.py +++ b/lib/agent_loop.py @@ -1,5 +1,6 @@ import json from datetime import datetime +from tools.vision import ImagePayload def _ts(): return datetime.now().strftime('%H:%M:%S') @@ -55,11 +56,21 @@ def run_agent_loop(session, llm_client, TOOLS, TOOL_HANDLERS, max_iterations, on if tc['function']['name'] == 'end_session': session_ended = True result = execute_tool(tc, TOOL_HANDLERS) - session.messages.append({ - 'role': 'tool', - 'tool_call_id': tc['id'], - 'content': str(result), - }) + if isinstance(result, ImagePayload): + session.messages.append({ + 'role': 'tool', + 'tool_call_id': tc['id'], + 'content': [ + {"type": "text", "text": f"[Image loaded: {result.path}]"}, + {"type": "image_url", "image_url": {"url": f"data:{result.mime};base64,{result.data}"}} + ] + }) + else: + session.messages.append({ + 'role': 'tool', + 'tool_call_id': tc['id'], + 'content': str(result), + }) else: if response.content: print(f'[{_ts()}] Response generated ({len(response.content)} chars)', flush=True) diff --git a/lib/gadget.py b/lib/gadget.py index d2d00dc..c79cea3 100644 --- a/lib/gadget.py +++ b/lib/gadget.py @@ -10,8 +10,8 @@ def tool_schemas(tools_definition): def tool_handlers(tools_definition): return {t["name"]: t["handler"] for t in tools_definition} -def strip_thinking(text: str) -> str: - if not text: +def strip_thinking(text): + if not text or not isinstance(text, str): return text # Strip XML-style thinking blocks (case-insensitive, DOTALL for multiline) text = re.sub(r']*>.*?', '', text, flags=re.DOTALL | re.IGNORECASE)