Improve tool calling
This commit is contained in:
parent
47b07b18f6
commit
d556ce2ea9
@ -30,6 +30,14 @@ Kamu dapat bertindak sebagai coding agent yang membantu software engineering tas
|
||||
- Semua file operations relatif terhadap workspace directory
|
||||
- Selalu confirm sebelum menghapus atau overwrite file yang sudah ada
|
||||
|
||||
## Tool Usage
|
||||
|
||||
- Sebelum memanggil tool, jelaskan dulu secara singkat apa yang akan kamu lakukan dan kenapa.
|
||||
Contoh: "Saya akan membaca file config.py untuk melihat strukturnya."
|
||||
- Setelah menerima hasil tool, berikan analisis singkat tentang hasilnya dan langkah selanjutnya.
|
||||
Contoh: "File config.py berisi konfigurasi LLM provider. Saya perlu menambahkan..."
|
||||
- Hindari hanya menyebut nama tool tanpa konteks — selalu sertakan alasan atau tujuan.
|
||||
|
||||
## Git Policy
|
||||
|
||||
- Kamu boleh menjalankan `git status`, `git diff`, `git log` secara bebas untuk inspeksi.
|
||||
|
||||
@ -145,7 +145,11 @@ def _agent_loop(app):
|
||||
|
||||
_add_msg(app, "assistant", response.content, tool_calls=response.tool_calls)
|
||||
|
||||
# Log tool_calls dengan label AI
|
||||
# Log content AI dulu (penjelasan sebelum tools)
|
||||
if response.content and response.content.strip():
|
||||
log(app, "ai", response.content)
|
||||
|
||||
# Log dan execute tool_calls
|
||||
for tc in response.tool_calls:
|
||||
tname = tc["function"]["name"]
|
||||
targs = tc["function"]["arguments"]
|
||||
@ -156,11 +160,6 @@ 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"])
|
||||
|
||||
|
||||
# Log content AI setelah tools (jika ada)
|
||||
if response.content and response.content.strip():
|
||||
log(app, "ai", response.content)
|
||||
else:
|
||||
if response.content:
|
||||
_add_msg(app, "assistant", response.content)
|
||||
|
||||
@ -49,7 +49,7 @@ def run_agent_loop(session, llm_client, TOOLS, TOOL_HANDLERS, max_iterations, on
|
||||
print(f'[{_ts()}] Using tools: {", ".join(tnames)}', flush=True)
|
||||
|
||||
if on_tool_calls:
|
||||
on_tool_calls(tnames)
|
||||
on_tool_calls(response.content or "")
|
||||
|
||||
for tc in response.tool_calls:
|
||||
if tc['function']['name'] == 'end_session':
|
||||
|
||||
@ -238,11 +238,9 @@ class TelegramClient:
|
||||
delay = random.uniform(config.READ_DELAY_MIN, config.READ_DELAY_MAX)
|
||||
time.sleep(delay)
|
||||
|
||||
def on_tool_calls(tnames):
|
||||
info = f'Using: {", ".join(tnames)}'
|
||||
print(f'[{_ts()}] {info}', flush=True)
|
||||
if not is_roleplay:
|
||||
self._schedule_send(chat_id, info, reply_to_msg_id)
|
||||
def on_tool_calls(content):
|
||||
if content and content.strip():
|
||||
self._schedule_send(chat_id, content, reply_to_msg_id)
|
||||
|
||||
tool_reminder = None
|
||||
|
||||
|
||||
@ -339,9 +339,9 @@ class XMPPClient(ClientXMPP):
|
||||
my_name = personality.PERSONALITY.name
|
||||
quote = body
|
||||
|
||||
def on_tool_calls(tnames):
|
||||
if not is_roleplay:
|
||||
self._schedule_send(jid, f'> {quote}\nUsing: {", ".join(tnames)}', 'chat')
|
||||
def on_tool_calls(content):
|
||||
if content and content.strip():
|
||||
self._schedule_send(jid, content, 'chat')
|
||||
|
||||
tool_reminder = None
|
||||
|
||||
@ -426,9 +426,9 @@ class XMPPClient(ClientXMPP):
|
||||
|
||||
_is_roleplay = 'roleplayer' in self._skill
|
||||
|
||||
def on_tool_calls(tnames):
|
||||
if not _is_roleplay:
|
||||
self._schedule_send(room, f'> {quote}\nUsing: {", ".join(tnames)}', 'groupchat')
|
||||
def on_tool_calls(content):
|
||||
if content and content.strip():
|
||||
self._schedule_send(room, content, 'groupchat')
|
||||
|
||||
tool_reminder = None
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user