From a53e927ba592e0a3d750f996327ce2a1e1cf44f4 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Thu, 12 Nov 2026 12:01:42 +0100 Subject: [PATCH] fix(agent): Improve tool rejection instructions fixes #293 Signed-off-by: Marcel Klehr --- ex_app/lib/agent.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ex_app/lib/agent.py b/ex_app/lib/agent.py index 80141d1..99bc867 100644 --- a/ex_app/lib/agent.py +++ b/ex_app/lib/agent.py @@ -253,11 +253,15 @@ async def call_model( ## if the next step is a tool call if state_snapshot.next == (CONFIRM_TOOLS_NODE, ): if task['input']['confirmation'] == 0: + if task['input']['input'] != '': + rejection_message = f"The user denied the tool call. The user said: '{task['input']['input']}'. Continue assisting and adapt the tool call to follow the user's instructions." + else: + rejection_message = "The user denied the tool call. Continue assisting but do not use the tool call for now." new_input = { "messages": [ ToolMessage( tool_call_id=tool_call["id"], - content=f"API call denied by user. Reasoning: '{task['input']['input']}'. Continue assisting, accounting for the user's input. If the user gave additional instructrions, adapt the tool call.", + content=rejection_message, ) for tool_call in state_snapshot.values['messages'][-1].tool_calls ]