Skip to content

Commit 9d74c39

Browse files
committed
✨ enhanced intelligence
1 parent 9aa21fe commit 9d74c39

File tree

4 files changed

+66
-13
lines changed

4 files changed

+66
-13
lines changed

src/agent.py

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,12 @@ def format_file_context(file_contents: List[Dict[str, str]]) -> str:
180180

181181
# Patterns to detect tool calls in text responses
182182
TOOL_CALL_PATTERNS = [
183-
# Pattern: <function/name>{"arg": "value"}</function
184-
r'<function/(\w+)>\s*(\{[^}]*\})\s*</function',
185-
# Pattern: <function name="name">{"arg": "value"}</function>
186-
r'<function\s+name="(\w+)">\s*(\{[^}]*\})\s*</function>',
187-
# Pattern: ```json\n{"name": "func", "arguments": {...}}```
188-
r'```json\s*\{\s*"name"\s*:\s*"(\w+)"\s*,\s*"arguments"\s*:\s*(\{[^}]*\})\s*\}\s*```',
183+
# Pattern: <function/name>{"arg": "value"}</function (also handles <functions/name>)
184+
r'<functions?/([\w/]+)>\s*(\{[^}]*\})\s*</function',
185+
# Pattern: <function name="name">{"arg": "value"}</function> (also handles prefixed names)
186+
r'<function\s+name="([\w./]+)">\s*(\{[^}]*\})\s*</function>',
187+
# Pattern: ```json\n{"name": "func", "arguments": {...}}``` (also handles prefixed names)
188+
r'```json\s*\{\s*"name"\s*:\s*"([\w./]+)"\s*,\s*"arguments"\s*:\s*(\{[^}]*\})\s*\}\s*```',
189189
]
190190

191191
# ═══════════════════════════════════════════════════════════════════════════════
@@ -405,18 +405,54 @@ def _save_conversation(self):
405405
"""Save the current conversation state"""
406406
history_manager.update_conversation(self.messages)
407407

408+
def _normalize_tool_name(self, name: str) -> str:
409+
"""
410+
Normalize a tool name by stripping common prefixes.
411+
Some models add prefixes like 'functions/' or 'tools.' to tool names.
412+
"""
413+
prefixes_to_strip = [
414+
"repo_browser.", "repo_browser/",
415+
"functions.", "functions/",
416+
"tools.", "tools/",
417+
"file_ops.", "file_ops/",
418+
"system.", "system/"
419+
]
420+
for prefix in prefixes_to_strip:
421+
if name.startswith(prefix):
422+
return name[len(prefix):]
423+
return name
424+
408425
def _filter_valid_tool_calls(self, tool_calls: List[Any]) -> List[Any]:
409426
"""
410427
Filter out tool calls for unknown/invalid tools.
411428
Some models (especially Llama) may hallucinate tool names like 'commentary'.
429+
Also normalizes tool names by stripping common prefixes (functions/, tools., etc.)
412430
"""
413431
valid_calls = []
432+
invalid_tools = []
433+
414434
for tc in tool_calls:
415435
tool_name = tc.name if hasattr(tc, 'name') else tc.get('name', '')
416-
if tool_name in TOOLS:
436+
# Normalize the tool name by stripping prefixes
437+
normalized_name = self._normalize_tool_name(tool_name)
438+
439+
if normalized_name in TOOLS:
440+
# Update the tool call with the normalized name
441+
if hasattr(tc, 'name'):
442+
tc.name = normalized_name
443+
elif isinstance(tc, dict):
444+
tc['name'] = normalized_name
417445
valid_calls.append(tc)
418446
else:
447+
invalid_tools.append(tool_name)
419448
log_debug(f"Ignoring unknown tool call: {tool_name}")
449+
450+
# If invalid tools were detected, show warning
451+
if invalid_tools:
452+
display_warning(f"Ignored invalid tool(s): {', '.join(invalid_tools)}")
453+
available = list(TOOLS.keys())[:15] # Show first 15 tools
454+
log_debug(f"Available tools: {available}")
455+
420456
return valid_calls
421457

422458
def _parse_tool_calls_from_text(self, text: str) -> List[ToolCall]:
@@ -433,15 +469,16 @@ def _parse_tool_calls_from_text(self, text: str) -> List[ToolCall]:
433469
func_name = match[0]
434470
args_str = match[1]
435471

436-
# Validate that it's a known tool
437-
if func_name in TOOLS:
472+
# Normalize and validate that it's a known tool
473+
normalized_name = self._normalize_tool_name(func_name)
474+
if normalized_name in TOOLS:
438475
call_id += 1
439476
tool_calls.append(ToolCall(
440477
id=f"text_call_{call_id}",
441-
name=func_name,
478+
name=normalized_name,
442479
arguments=args_str
443480
))
444-
log_debug(f"Parsed tool call from text: {func_name}")
481+
log_debug(f"Parsed tool call from text: {normalized_name}")
445482

446483
return tool_calls
447484

src/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,13 @@ def items(self):
378378
## TASK DIVISION (spawn_agents)
379379
For 3+ independent subtasks, use spawn_agents to parallelize work.
380380
381+
## TOOL USAGE - CRITICAL
382+
- ONLY use tools that are explicitly provided to you
383+
- NEVER invent or guess tool names - use EXACT names from the tool list
384+
- Available tools: list_files_in_dir, read_file, create_file, create_folder, run_command, move_path, delete_path, glob_search, grep_search, find_and_replace, web_search, fetch_url, search_and_summarize, spawn_agents, check_agent_tasks
385+
- If you need functionality not available, use run_command with appropriate shell commands
386+
- DO NOT add prefixes like "functions/", "tools.", or "system." to tool names
387+
381388
## RESPONSES
382389
- Be concise: "Created file.py" - done
383390
- Don't repeat file contents unless asked

src/tools.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,8 +1014,17 @@ def execute_tool(name: str, args: Dict[str, Any]) -> str:
10141014
"""Execute a tool by name with given arguments"""
10151015
# Strip common prefixes that some models add incorrectly
10161016
# e.g., "repo_browser.list_files_in_dir" -> "list_files_in_dir"
1017+
# e.g., "functions/create_file" -> "create_file"
10171018
original_name = name
1018-
prefixes_to_strip = ["repo_browser.", "functions.", "tools.", "file_ops.", "system."]
1019+
1020+
# Handle both dot (.) and slash (/) separators
1021+
prefixes_to_strip = [
1022+
"repo_browser.", "repo_browser/",
1023+
"functions.", "functions/",
1024+
"tools.", "tools/",
1025+
"file_ops.", "file_ops/",
1026+
"system.", "system/"
1027+
]
10191028
for prefix in prefixes_to_strip:
10201029
if name.startswith(prefix):
10211030
name = name[len(prefix):]

static-api/version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "0.0.0.40"
2+
"version": "0.0.0.41"
33
}

0 commit comments

Comments
 (0)