Compare commits
No commits in common. "8ea335e937282fbc011cff679f01d51fbe1b4932" and "c3820094444ee238d1264dc1af9d2bd1955a5625" have entirely different histories.
8ea335e937
...
c382009444
@ -1,6 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import config
|
|
||||||
from lib.personality import PERSONALITY
|
from lib.personality import PERSONALITY
|
||||||
from tools.vision import ImagePayload
|
from tools.vision import ImagePayload
|
||||||
from scripts import loggorilla
|
from scripts import loggorilla
|
||||||
@ -8,36 +7,25 @@ from scripts import loggorilla
|
|||||||
def _ts():
|
def _ts():
|
||||||
return datetime.now().strftime('%H:%M:%S')
|
return datetime.now().strftime('%H:%M:%S')
|
||||||
|
|
||||||
def _cap_output(result):
|
|
||||||
# Jaring pengaman ukuran output tool. Hormati semantics config:
|
|
||||||
# AGENT_MAX_TOOL_OUTPUT <= 0 = unlimited (tidak dipotong).
|
|
||||||
limit = getattr(config, "AGENT_MAX_TOOL_OUTPUT", 0)
|
|
||||||
if not limit or limit <= 0:
|
|
||||||
return result
|
|
||||||
if isinstance(result, str) and len(result) > limit:
|
|
||||||
omitted = len(result) - limit
|
|
||||||
return result[:limit] + f"\n... [truncated: {omitted} chars omitted]"
|
|
||||||
return result
|
|
||||||
|
|
||||||
def execute_tool(tool_call, TOOL_HANDLERS):
|
def execute_tool(tool_call, TOOL_HANDLERS):
|
||||||
tname = tool_call['function']['name']
|
tname = tool_call['function']['name']
|
||||||
targs = json.loads(tool_call['function']['arguments'])
|
targs = json.loads(tool_call['function']['arguments'])
|
||||||
handler = TOOL_HANDLERS.get(tname)
|
handler = TOOL_HANDLERS.get(tname)
|
||||||
if not handler:
|
if not handler:
|
||||||
return _cap_output(f'Tool {tname} not found')
|
return f'Tool {tname} not found'
|
||||||
try:
|
try:
|
||||||
if tname == 'search_code':
|
if tname == 'search_code':
|
||||||
return _cap_output(handler(
|
return handler(
|
||||||
pattern=targs['pattern'],
|
pattern=targs['pattern'],
|
||||||
search_type=targs['search_type'],
|
search_type=targs['search_type'],
|
||||||
path=targs.get('path', '.'),
|
path=targs.get('path', '.'),
|
||||||
))
|
)
|
||||||
elif tname == 'git_operation':
|
elif tname == 'git_operation':
|
||||||
return _cap_output(handler(args=targs['args']))
|
return handler(args=targs['args'])
|
||||||
else:
|
else:
|
||||||
return _cap_output(handler(**targs))
|
return handler(**targs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return _cap_output(f'Error executing tool: {str(e)}')
|
return f'Error executing tool: {str(e)}'
|
||||||
|
|
||||||
def run_agent_loop(session, llm_client, TOOLS, TOOL_HANDLERS, max_iterations, on_tool_calls=None, tool_reminder=None):
|
def run_agent_loop(session, llm_client, TOOLS, TOOL_HANDLERS, max_iterations, on_tool_calls=None, tool_reminder=None):
|
||||||
session_ended = False
|
session_ended = False
|
||||||
|
|||||||
@ -6,15 +6,6 @@ import glob as glob_module
|
|||||||
|
|
||||||
from lib import workspace
|
from lib import workspace
|
||||||
|
|
||||||
# Batas panjang satu baris hasil pencarian. Mencegah satu baris raksasa
|
|
||||||
# (mis. file minified/generated satu-line) menembus context window model.
|
|
||||||
MAX_MATCH_LINE = 500
|
|
||||||
|
|
||||||
def _clip(line):
|
|
||||||
if len(line) > MAX_MATCH_LINE:
|
|
||||||
return line[:MAX_MATCH_LINE] + f"... [+{len(line) - MAX_MATCH_LINE} chars]"
|
|
||||||
return line
|
|
||||||
|
|
||||||
schema_read_file = {
|
schema_read_file = {
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"function": {
|
"function": {
|
||||||
@ -154,7 +145,7 @@ def search_code(pattern, search_type, path="."):
|
|||||||
with open(file_path, 'r', encoding='utf-8', errors='replace') as f:
|
with open(file_path, 'r', encoding='utf-8', errors='replace') as f:
|
||||||
for i, line in enumerate(f.readlines(), 1):
|
for i, line in enumerate(f.readlines(), 1):
|
||||||
if re.search(pattern, line):
|
if re.search(pattern, line):
|
||||||
results.append(f"{file_path}:{i}: {_clip(line.strip())}")
|
results.append(f"{file_path}:{i}: {line.strip()}")
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
return "\n".join(results[:50]) if results else "No matches found"
|
return "\n".join(results[:50]) if results else "No matches found"
|
||||||
@ -220,7 +211,7 @@ def search_grep(pattern, path=".", include=None):
|
|||||||
with open(file_path, 'r', encoding='utf-8', errors='replace') as f:
|
with open(file_path, 'r', encoding='utf-8', errors='replace') as f:
|
||||||
for i, line in enumerate(f.readlines(), 1):
|
for i, line in enumerate(f.readlines(), 1):
|
||||||
if re.search(pattern, line):
|
if re.search(pattern, line):
|
||||||
results.append(f"{file_path}:{i}: {_clip(line.strip())}")
|
results.append(f"{file_path}:{i}: {line.strip()}")
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
return "\n".join(results[:100]) if results else "No matches found"
|
return "\n".join(results[:100]) if results else "No matches found"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user