Skip to content

fix: add file parameter alias for model compatibility#29

Merged
anhnh2002 merged 1 commit intoFSoft-AI4Code:mainfrom
don7panic:feat/glm-4.7
Jan 12, 2026
Merged

fix: add file parameter alias for model compatibility#29
anhnh2002 merged 1 commit intoFSoft-AI4Code:mainfrom
don7panic:feat/glm-4.7

Conversation

@don7panic
Copy link
Copy Markdown
Contributor

Hi Team,

When I used the glm-4.7 model API and executed the codewiki generate command locally, I encountered the following error. The problem was that GLM-4.7 was calling the str_replace_editor tool with file instead of path as the parameter name.

Summary

Add file parameter as an alias for path in the str_replace_editor tool for LLM model compatibility.

Problem

Some LLM models (e.g., GLM-4.7) may use file instead of path when calling the str_replace_editor tool, causing tool execution failures.

[19:45:56] ERROR    Error processing module ai-hedge-fund: Tool 'str_replace_editor' exceeded max retries count of 1                                                                
  [19:45:56] ERROR    Traceback: Traceback (most recent call last):                                                                                                                   
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_tool_manager.py", line 176, in _call_tool                                                     
  args_dict = validator.validate_json(                                                                                                                                                
  ^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                            
  pydantic_core._pydantic_core.ValidationError: 1 validation error for str_replace_editor                                                                                             
  path                                                                                                                                                                                
  Field required [type=missing, input_value={'command': 'create', 'fi..., 'working_dir': 'docs'}, input_type=dict]                                                                    
  For further information visit https://errors.pydantic.dev/2.12/v/missing                                                                                                            
                                                                                                                                                                                      
  The above exception was the direct cause of the following exception:                                                                                                                
                                                                                                                                                                                      
  Traceback (most recent call last):                                                                                                                                                  
  File "/Users/oasis/workspace/CodeWiki/codewiki/src/be/agent_orchestrator.py", line 130, in process_module                                                                           
  result = await agent.run(                                                                                                                                                           
  ^^^^^^^^^^^^^^^^                                                                                                                                                                    
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/agent/abstract.py", line 258, in run                                                           
  async with self.iter(                                                                                                                                                               
  ^^^^^^^^^^                                                                                                                                                                          
  File "/Users/oasis/.local/share/uv/python/cpython-3.12.10-macos-aarch64-none/lib/python3.12/contextlib.py", line 231, in __aexit__                                                  
  await self.gen.athrow(value)                                                                                                                                                        
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/agent/__init__.py", line 705, in iter                                                          
  async with graph.iter(                                                                                                                                                              
  ^^^^^^^^^^^                                                                                                                                                                         
  File "/Users/oasis/.local/share/uv/python/cpython-3.12.10-macos-aarch64-none/lib/python3.12/contextlib.py", line 231, in __aexit__                                                  
  await self.gen.athrow(value)                                                                                                                                                        
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_graph/beta/graph.py", line 270, in iter                                                           
  async with GraphRun[StateT, DepsT, OutputT](                                                                                                                                        
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                   
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_graph/beta/graph.py", line 423, in __aexit__                                                      
  await self._async_exit_stack.__aexit__(exc_type, exc_val, exc_tb)                                                                                                                   
  File "/Users/oasis/.local/share/uv/python/cpython-3.12.10-macos-aarch64-none/lib/python3.12/contextlib.py", line 754, in __aexit__                                                  
  raise exc_details[1]                                                                                                                                                                
  File "/Users/oasis/.local/share/uv/python/cpython-3.12.10-macos-aarch64-none/lib/python3.12/contextlib.py", line 735, in __aexit__                                                  
  cb_suppress = cb(*exc_details)                                                                                                                                                      
  ^^^^^^^^^^^^^^^^                                                                                                                                                                    
  File "/Users/oasis/.local/share/uv/python/cpython-3.12.10-macos-aarch64-none/lib/python3.12/contextlib.py", line 158, in __exit__                                                   
  self.gen.throw(value)                                                                                                                                                               
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_graph/beta/graph.py", line 981, in _unwrap_exception_groups                                       
  raise exception                                                                                                                                                                     
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_graph/beta/graph.py", line 750, in _run_tracked_task                                              
  result = await self._run_task(t_)                                                                                                                                                   
  ^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                            
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_graph/beta/graph.py", line 782, in _run_task                                                      
  output = await node.call(step_context)                                                                                                                                              
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                       
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_graph/beta/step.py", line 253, in _call_node                                                      
  return await node.run(GraphRunContext(state=ctx.state, deps=ctx.deps))                                                                                                              
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                     
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_agent_graph.py", line 589, in run                                                             
  async with self.stream(ctx):                                                                                                                                                        
  ^^^^^^^^^^^^^^^^                                                                                                                                                                    
  File "/Users/oasis/.local/share/uv/python/cpython-3.12.10-macos-aarch64-none/lib/python3.12/contextlib.py", line 217, in __aexit__                                                  
  await anext(self.gen)                                                                                                                                                               
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_agent_graph.py", line 603, in stream                                                          
  async for _event in stream:                                                                                                                                                         
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_agent_graph.py", line 729, in _run_stream                                                     
  async for event in self._events_iterator:                                                                                                                                           
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_agent_graph.py", line 690, in _run_stream                                                     
  async for event in self._handle_tool_calls(ctx, tool_calls):                                                                                                                        
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_agent_graph.py", line 745, in _handle_tool_calls                                              
  async for event in process_tool_calls(                                                                                                                                              
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_agent_graph.py", line 991, in process_tool_calls                                              
  async for event in _call_tools(                                                                                                                                                     
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_agent_graph.py", line 1129, in _call_tools                                                    
  if event := await handle_call_or_result(coro_or_task=task, index=index):                                                                                                            
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                         
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_agent_graph.py", line 1092, in handle_call_or_result                                          
  (await coro_or_task) if inspect.isawaitable(coro_or_task) else coro_or_task.result()                                                                                                
  ^^^^^^^^^^^^^^^^^^                                                                                                                                                                  
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_agent_graph.py", line 1166, in _call_tool                                                     
  tool_result = await tool_manager.handle_call(tool_call)                                                                                                                             
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                           
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_tool_manager.py", line 125, in handle_call                                                    
  return await self._call_function_tool(                                                                                                                                              
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                     
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_tool_manager.py", line 262, in _call_function_tool                                            
  tool_result = await self._call_tool(                                                                                                                                                
  ^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                              
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_tool_manager.py", line 190, in _call_tool                                                     
  raise UnexpectedModelBehavior(f'Tool {name!r} exceeded max retries count of {max_retries}') from e                                                                                  
  pydantic_ai.exceptions.UnexpectedModelBehavior: Tool 'str_replace_editor' exceeded max retries count of 1                                                                           
                                                                                                                                                                                      
  ✗ Documentation generation failed: Tool 'str_replace_editor' exceeded max retries count of 1                                                                                        
  ✗ Traceback: Traceback (most recent call last):                                                                                                                                     
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_tool_manager.py", line 176, in _call_tool                                                     
  args_dict = validator.validate_json(                                                                                                                                                
  ^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                            
  pydantic_core._pydantic_core.ValidationError: 1 validation error for str_replace_editor                                                                                             
  path                                                                                                                                                                                
  Field required [type=missing, input_value={'command': 'create', 'fi..., 'working_dir': 'docs'}, input_type=dict]                                                                    
  For further information visit https://errors.pydantic.dev/2.12/v/missing                                                                                                            
                                                                                                                                                                                      
  The above exception was the direct cause of the following exception:                                                                                                                
                                                                                                                                                                                      
  Traceback (most recent call last):                                                                                                                                                  
  File "/Users/oasis/workspace/CodeWiki/codewiki/cli/adapters/doc_generator.py", line 231, in _run_backend_generation                                                                 
  await doc_generator.generate_module_documentation(components, leaf_nodes)                                                                                                           
  File "/Users/oasis/workspace/CodeWiki/codewiki/src/be/documentation_generator.py", line 185, in generate_module_documentation                                                       
  final_module_tree = await self.agent_orchestrator.process_module(                                                                                                                   
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                       
  File "/Users/oasis/workspace/CodeWiki/codewiki/src/be/agent_orchestrator.py", line 130, in process_module                                                                           
  result = await agent.run(                                                                                                                                                           
  ^^^^^^^^^^^^^^^^                                                                                                                                                                    
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/agent/abstract.py", line 258, in run                                                           
  async with self.iter(                                                                                                                                                               
  ^^^^^^^^^^                                                                                                                                                                          
  File "/Users/oasis/.local/share/uv/python/cpython-3.12.10-macos-aarch64-none/lib/python3.12/contextlib.py", line 231, in __aexit__                                                  
  await self.gen.athrow(value)                                                                                                                                                        
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/agent/__init__.py", line 705, in iter                                                          
  async with graph.iter(                                                                                                                                                              
  ^^^^^^^^^^^                                                                                                                                                                         
  File "/Users/oasis/.local/share/uv/python/cpython-3.12.10-macos-aarch64-none/lib/python3.12/contextlib.py", line 231, in __aexit__                                                  
  await self.gen.athrow(value)                                                                                                                                                        
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_graph/beta/graph.py", line 270, in iter                                                           
  async with GraphRun[StateT, DepsT, OutputT](                                                                                                                                        
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                   
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_graph/beta/graph.py", line 423, in __aexit__                                                      
  await self._async_exit_stack.__aexit__(exc_type, exc_val, exc_tb)                                                                                                                   
  File "/Users/oasis/.local/share/uv/python/cpython-3.12.10-macos-aarch64-none/lib/python3.12/contextlib.py", line 754, in __aexit__                                                  
  raise exc_details[1]                                                                                                                                                                
  File "/Users/oasis/.local/share/uv/python/cpython-3.12.10-macos-aarch64-none/lib/python3.12/contextlib.py", line 735, in __aexit__                                                  
  cb_suppress = cb(*exc_details)                                                                                                                                                      
  ^^^^^^^^^^^^^^^^                                                                                                                                                                    
  File "/Users/oasis/.local/share/uv/python/cpython-3.12.10-macos-aarch64-none/lib/python3.12/contextlib.py", line 158, in __exit__                                                   
  self.gen.throw(value)                                                                                                                                                               
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_graph/beta/graph.py", line 981, in _unwrap_exception_groups                                       
  raise exception                                                                                                                                                                     
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_graph/beta/graph.py", line 750, in _run_tracked_task                                              
  result = await self._run_task(t_)                                                                                                                                                   
  ^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                            
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_graph/beta/graph.py", line 782, in _run_task                                                      
  output = await node.call(step_context)                                                                                                                                              
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                       
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_graph/beta/step.py", line 253, in _call_node                                                      
  return await node.run(GraphRunContext(state=ctx.state, deps=ctx.deps))                                                                                                              
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                     
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_agent_graph.py", line 589, in run                                                             
  async with self.stream(ctx):                                                                                                                                                        
  ^^^^^^^^^^^^^^^^                                                                                                                                                                    
  File "/Users/oasis/.local/share/uv/python/cpython-3.12.10-macos-aarch64-none/lib/python3.12/contextlib.py", line 217, in __aexit__                                                  
  await anext(self.gen)                                                                                                                                                               
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_agent_graph.py", line 603, in stream                                                          
  async for _event in stream:                                                                                                                                                         
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_agent_graph.py", line 729, in _run_stream                                                     
  async for event in self._events_iterator:                                                                                                                                           
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_agent_graph.py", line 690, in _run_stream                                                     
  async for event in self._handle_tool_calls(ctx, tool_calls):                                                                                                                        
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_agent_graph.py", line 745, in _handle_tool_calls                                              
  async for event in process_tool_calls(                                                                                                                                              
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_agent_graph.py", line 991, in process_tool_calls                                              
  async for event in _call_tools(                                                                                                                                                     
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_agent_graph.py", line 1129, in _call_tools                                                    
  if event := await handle_call_or_result(coro_or_task=task, index=index):                                                                                                            
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                         
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_agent_graph.py", line 1092, in handle_call_or_result                                          
  (await coro_or_task) if inspect.isawaitable(coro_or_task) else coro_or_task.result()                                                                                                
  ^^^^^^^^^^^^^^^^^^                                                                                                                                                                  
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_agent_graph.py", line 1166, in _call_tool                                                     
  tool_result = await tool_manager.handle_call(tool_call)                                                                                                                             
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                           
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_tool_manager.py", line 125, in handle_call                                                    
  return await self._call_function_tool(                                                                                                                                              
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                     
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_tool_manager.py", line 262, in _call_function_tool                                            
  tool_result = await self._call_tool(                                                                                                                                                
  ^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                              
  File "/Users/oasis/workspace/CodeWiki/.venv/lib/python3.12/site-packages/pydantic_ai/_tool_manager.py", line 190, in _call_tool                                                     
  raise UnexpectedModelBehavior(f'Tool {name!r} exceeded max retries count of {max_retries}') from e                                                                                  
  pydantic_ai.exceptions.UnexpectedModelBehavior: Tool 'str_replace_editor' exceeded max retries count of 1                                                                           
                                                                                                                                                                                      
  During handling of the above exception, another exception occurred:                                                                                                                 
                                                                                                                                                                                      
  Traceback (most recent call last):                                                                                                                                                  
  File "/Users/oasis/workspace/CodeWiki/codewiki/cli/commands/generate.py", line 213, in generate_command                                                                             
  job = generator.generate()                                                                                                                                                          
  ^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                
  File "/Users/oasis/workspace/CodeWiki/codewiki/cli/adapters/doc_generator.py", line 143, in generate                                                                                
  asyncio.run(self._run_backend_generation(backend_config))                                                                                                                           
  File "/Users/oasis/.local/share/uv/python/cpython-3.12.10-macos-aarch64-none/lib/python3.12/asyncio/runners.py", line 195, in run                                                   
  return runner.run(main)                                                                                                                                                             
  ^^^^^^^^^^^^^^^^                                                                                                                                                                    
  File "/Users/oasis/.local/share/uv/python/cpython-3.12.10-macos-aarch64-none/lib/python3.12/asyncio/runners.py", line 118, in run                                                   
  return self._loop.run_until_complete(task)                                                                                                                                          
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                 
  File "/Users/oasis/.local/share/uv/python/cpython-3.12.10-macos-aarch64-none/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete                                
  return future.result()                                                                                                                                                              
  ^^^^^^^^^^^^^^^                                                                                                                                                                     
  File "/Users/oasis/workspace/CodeWiki/codewiki/cli/adapters/doc_generator.py", line 245, in _run_backend_generation                                                                 
  raise APIError(f"Documentation generation failed: {e}")                                                                                                                             
  codewiki.cli.utils.errors.APIError: Documentation generation failed: Tool 'str_replace_editor' exceeded max retries count of 1

Changes

  • Made path parameter optional with default None
  • Added optional file parameter as an alias
  • Added validation to ensure either path or file is provided
  • If only file is provided, it's automatically mapped to path

Testing

  • Syntax check passed
  • Tested manually with GLM-4.7 model

@anhnh2002 anhnh2002 merged commit 75c11ba into FSoft-AI4Code:main Jan 12, 2026
@anhnh2002
Copy link
Copy Markdown
Collaborator

Appreciate!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants