使用SDK时,修改代码用的是replace工具吗?replace工具失败率太高了

其中报错的一次,我一共修改了两个文件,一共出现了9次工具调用失败,最后是创建了一个python脚本写入成功了。为什么没有使用edit这个工具?

SDK客户端的配置:
IFlowOptions(

cwd=self.project_path,

session_id=self.session_id,

timeout=600.0

)

icon=Icon(type=‘emoji’, value=‘:wrench:’), status=<ToolCallStatus.IN_PROGRESS: ‘in_progress’>, tool_name=‘replace’, content=None, locations=None, confirmation=None, agent_id=None, agent_info=None, args={‘file_path’: ‘/home/demand/lpm-coder-demo/litepass/src/lpm/luban/k8s_rc.go’, ‘instruction’: ‘在RewriteRule结构体中增加WorkMode字段,位置在SingleMode字段之后,Replicas字段之前’, ‘old_string’: ‘// 定义NFC蓝图中的replicasRewrite字段\ntype RewriteRule struct {\n\tBoardName string `json:“boardName”`\n\tNftypeList []uint32 `json:“nftypeList”`\n\tBoardNum uint32 `json:“boardNum”`\n\tCpuNum CpuNumRule `json:“cpuNum”`\n\tSingleMode uint32 `json:“singleMode”`\n\tReplicas *int32 `json:“replicas”`\n\tReplicasMin int `json:“replicasMin”`\n\tReplicasMax int `json:“replicasMax”`\n}’, ‘new_string’: ‘// 定义NFC蓝图中的replicasRewrite字段\ntype RewriteRule struct {\n\tBoardName string `json:“boardName”`\n\tNftypeList []uint32 `json:“nftypeList”`\n\tBoardNum uint32 `json:“boardNum”`\n\tCpuNum CpuNumRule `json:“cpuNum”`\n\tSingleMode uint32 `json:“singleMode”`\n\tWorkMode string `json:“workMode”`\n\tReplicas *int32 `json:“replicas”`\n\tReplicasMin int `json:“replicasMin”`\n\tReplicasMax int `json:“replicasMax”`\n}’})

message:ErrorMessage(type=‘error’, code=-1, message=‘Unknown error’, details=None)

下面是一些统计数据:

我也碰到了这个问题, CLI一般不会失败, SDK用relpace失败次数很多, 就会创建python脚本来改代码,效率低下。

我的主要是因为编码问题。

iflow的报错: 我看到文件有Windows风格的换行符(^M)。让我使用write_file来重写整个函数:我看到文件内容有编码问题。让我直接用sed命令来替换这个函数:现在让我使用Python脚本来替换文件中的函数

pythonsdk的版本以及iflowcli的版本发一下吧

pythonsdk和iflowcli的版本发一下吧

IFlowOptions加一个参数file_access=True 试一下

SDK版本:iflow-cli-sdk 0.2.0
CLI版本:iflow-cli 0.4.15

增加之后还是不行

message:ToolResultMessage(type=‘tool_call’, id=‘call_0904ed05cf2f4ba996289ae9’, status=<ToolCallStatus.COMPLETED: ‘completed’>, tool_name=‘read_file’, content=ToolCallContent(type=‘markdown’, markdown=‘从 lpm/luban/k8s_rc.go 读取第 46-60 行,共 1264 行’, path=None, old_text=None, new_text=None, fileDiff=None), locations=None, confirmation=None, agent_id=None, agent_info=None, args={‘absolute_path’: ‘/home/demand/lpm-coder-demo/litepass/src/lpm/luban/k8s_rc.go’, ‘limit’: 15, ‘offset’: 45})
message:ToolCallMessage(type=‘tool_call’, id=‘call_cbe8fb78fabc4ddf8bd2bb82’, label=‘lpm/luban/k8s_rc.go: // 定义NFC蓝图中的replicasRewrite字段… => // 定义NFC蓝图中的replicasRewrite字段…’, icon=Icon(type=‘emoji’, value=‘:wrench:’), status=<ToolCallStatus.IN_PROGRESS: ‘in_progress’>, tool_name=‘replace’, content=None, locations=None, confirmation=None, agent_id=None, agent_info=None, args={‘file_path’: ‘/home/demand/lpm-coder-demo/litepass/src/lpm/luban/k8s_rc.go’, ‘instruction’: ‘在RewriteRule结构体中增加WorkMode字段,用于支持工作模式匹配规则’, ‘old_string’: ‘// 定义NFC蓝图中的replicasRewrite字段\ntype RewriteRule struct {\n\tBoardName string json:"boardName"\n\tNftypeList uint32 json:"nftypeList"\n\tBoardNum uint32 json:"boardNum"\n\tCpuNum CpuNumRule json:"cpuNum"\n\tSingleMode uint32 json:"singleMode"\n\tReplicas *int32 json:"replicas"\n\tReplicasMin int json:"replicasMin"\n\tReplicasMax int json:"replicasMax"\n}\n\ntype ReplicasRewrite struct {\n\tRewriteRules RewriteRule json:"replicasRewrite"\n}’, ‘new_string’: ‘// 定义NFC蓝图中的replicasRewrite字段\ntype RewriteRule struct {\n\tBoardName string json:"boardName"\n\tNftypeList uint32 json:"nftypeList"\n\tBoardNum uint32 json:"boardNum"\n\tCpuNum CpuNumRule json:"cpuNum"\n\tSingleMode uint32 json:"singleMode"\n\tWorkMode string json:"workMode"\n\tReplicas *int32 json:"replicas"\n\tReplicasMin int json:"replicasMin"\n\tReplicasMax int json:"replicasMax"\n}\n\ntype ReplicasRewrite struct {\n\tRewriteRules RewriteRule json:"replicasRewrite"\n}’})
message:ErrorMessage(type=‘error’, code=-1, message=‘Unknown error’, details=None)
message:ToolResultMessage(type=‘tool_call’, id=‘call_cbe8fb78fabc4ddf8bd2bb82’, status=<ToolCallStatus.FAILED: ‘failed’>, tool_name=‘replace’, content=ToolCallContent(type=‘markdown’, markdown=‘[object Object]’, path=None, old_text=None, new_text=None, fileDiff=None), locations=None, confirmation=None, agent_id=None, agent_info=None, args=None)
message:AssistantMessage(type=‘assistant’, chunk=AssistantMessageChunk(text=‘让我尝试使用不同的方法,直接读取完整文件并重新写入:’, thought=None), agent_id=None, agent_info=None)
message:ToolCallMessage(type=‘tool_call’, id=‘call_e098f1e770724ec08ec616f0’, label=‘lpm/luban/k8s_rc.go’, icon=Icon(type=‘emoji’, value=‘:wrench:’), status=<ToolCallStatus.IN_PROGRESS: ‘in_progress’>, tool_name=‘read_file’, content=None, locations=None, confirmation=None, agent_id=None, agent_info=None, args={‘absolute_path’: ‘/home/demand/lpm-coder-demo/litepass/src/lpm/luban/k8s_rc.go’, ‘limit’: 100, ‘offset’: 1})
message:ToolResultMessage(type=‘tool_call’, id=‘call_e098f1e770724ec08ec616f0’, status=<ToolCallStatus.COMPLETED: ‘completed’>, tool_name=‘read_file’, content=ToolCallContent(type=‘markdown’, markdown=‘从 lpm/luban/k8s_rc.go 读取第 2-101 行,共 1264 行’, path=None, old_text=None, new_text=None, fileDiff=None), locations=None, confirmation=None, agent_id=None, agent_info=None, args={‘absolute_path’: ‘/home/demand/lpm-coder-demo/litepass/src/lpm/luban/k8s_rc.go’, ‘limit’: 100, ‘offset’: 1})
message:AssistantMessage(type=‘assistant’, chunk=AssistantMessageChunk(text=‘让我使用run_shell_command来执行sed命令进行修改:’, thought=None), agent_id=None, agent_info=None)

执行替换的工作目录是项目的工作目录还是其他的目录呢

是通过 cwd=self.project_path, 指定的项目目录的子文件

SDK程序是在另外一个目录下执行的

日志中这个路径是对的,我传入的路劲是/home/demand/lpm-coder-demo/litepass/src

options = IFlowOptions(
cwd=“/path/to/project”,
file_access=True,
file_allowed_dirs=[“/path/to/project”] # 明确指定
)

file_allowed_dirs=[“/path/to/project”] 加了这个后好了,多谢,点赞

1 个赞