Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions channels/webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"upload",
"theming",
"modal_settings",
"new_menu_options",
"storage_editor",
"responsive",
"init"
Expand Down
22 changes: 22 additions & 0 deletions channels/webui/static/js/new_menu_options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// =============================================================================
// Agent Menu Options
// =============================================================================

// Defines metadata for agent-related configuration options.
// Loaded after modal_settings.js to extend FIELD_DESCRIPTIONS.
const AGENT_MENU_OPTIONS = [
{
key: 'model.agent_replan_on_error',
label: 'Replan on error',
description: 'When enabled, the agent will restart its planning loop when a tool call returns an error, prompting it to try a different strategy instead of continuing with a failed result.',
type: 'boolean',
default: false
}
];

// Extend field descriptions for agent options so they appear in the settings UI
for (const option of AGENT_MENU_OPTIONS) {
if (option.description) {
FIELD_DESCRIPTIONS[option.key] = option.description;
}
}
3 changes: 2 additions & 1 deletion core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"model": {
"name": "MODEL_HERE",
"temperature": 0.2,
"use_tools": True
"use_tools": True,
"agent_replan_on_error": False
},
"channels": {
"enabled": ["cli", "webui"],
Expand Down
21 changes: 17 additions & 4 deletions core/toolcalls.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ async def process(self, tool_calls, initial_content=""):
await self.channel.context.chat.add(assistant_message)

# Execute each tool and add their responses
had_tool_error = False

for tool_call_dict in repaired_tool_calls:
tool_name = tool_call_dict['function']['name']
tool_args = json_repair.loads(tool_call_dict['function']['arguments'])
Expand Down Expand Up @@ -97,6 +99,7 @@ async def process(self, tool_calls, initial_content=""):
}
except Exception as e:
core.log("toolcall", f"error: {str(e)}")
had_tool_error = True
tool_response = {
"role": "tool",
"tool_call_id": tool_call_dict['id'],
Expand All @@ -116,13 +119,23 @@ async def process(self, tool_calls, initial_content=""):

# Build context and stream response
context = await self.channel.context.get(system_prompt=False)

replan_on_error = core.config.get("model", {}).get("agent_replan_on_error", False)
if had_tool_error and replan_on_error:
system_content = (
"One or more tool calls returned an error. "
"Please replan your approach and try a different strategy to achieve the goal."
)
else:
system_content = (
"If the tool response provides sufficient answers, "
"explain the results to the user. If not, call another tool."
)

prompt = [
{
"role": "system",
"content": (
"If the tool response provides sufficient answers, "
"explain the results to the user. If not, call another tool."
)
"content": system_content
}
] + context

Expand Down