Cleanup function
This commit is contained in:
parent
fb52623d3e
commit
28bd27f79c
@ -4,32 +4,25 @@ from datetime import datetime
|
|||||||
def _ts():
|
def _ts():
|
||||||
return datetime.now().strftime('%H:%M:%S')
|
return datetime.now().strftime('%H:%M:%S')
|
||||||
|
|
||||||
def execute_tool(tool_call, TOOL_HANDLERS, app=None):
|
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:
|
||||||
result = f'Tool {tname} not found'
|
return f'Tool {tname} not found'
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
if tname == 'search_code':
|
if tname == 'search_code':
|
||||||
result = 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':
|
||||||
result = handler(args=targs['args'])
|
return handler(args=targs['args'])
|
||||||
else:
|
else:
|
||||||
result = handler(**targs)
|
return handler(**targs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
result = f'Error executing tool: {str(e)}'
|
return f'Error executing tool: {str(e)}'
|
||||||
|
|
||||||
if app:
|
|
||||||
from tui.agent import _add_msg
|
|
||||||
_add_msg(app, "tool", str(result), tool_call_id=tool_call["id"])
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def run_agent_loop(session, llm_client, TOOLS, TOOL_HANDLERS, max_iterations, on_tool_calls=None):
|
def run_agent_loop(session, llm_client, TOOLS, TOOL_HANDLERS, max_iterations, on_tool_calls=None):
|
||||||
for step in range(max_iterations):
|
for step in range(max_iterations):
|
||||||
|
|||||||
@ -151,7 +151,8 @@ def _agent_loop(app):
|
|||||||
"arguments": targs,
|
"arguments": targs,
|
||||||
}))
|
}))
|
||||||
app.scroll = 999999
|
app.scroll = 999999
|
||||||
agent_loop.execute_tool(tc, app.TOOL_HANDLERS, app=app)
|
result = agent_loop.execute_tool(tc, app.TOOL_HANDLERS)
|
||||||
|
_add_msg(app, "tool", str(result), tool_call_id=tc["id"])
|
||||||
|
|
||||||
|
|
||||||
# Log content AI setelah tools (jika ada)
|
# Log content AI setelah tools (jika ada)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user