@@ -108,6 +108,7 @@ async def run(self, prompt: str, subtask_title: str) -> CoderToWriter:
108108
109109 # 如果是第一次运行,则添加系统提示
110110 if self .is_first_run :
111+ logger .info ("首次运行,添加系统提示和数据集文件信息" )
111112 self .is_first_run = False
112113 self .append_chat_history ({"role" : "system" , "content" : self .system_prompt })
113114 # 当前数据集文件
@@ -118,22 +119,26 @@ async def run(self, prompt: str, subtask_title: str) -> CoderToWriter:
118119 }
119120 )
120121
122+ # 添加 sub_task
123+ logger .info (f"添加子任务提示: { prompt } " )
121124 self .append_chat_history ({"role" : "user" , "content" : prompt })
122125
123126 retry_count = 0
124127 last_error_message = ""
125128 task_completed = False
126129
127130 if self .current_chat_turns >= self .max_chat_turns :
131+ logger .error (f"超过最大聊天次数: { self .max_chat_turns } " )
128132 await redis_manager .publish_message (
129133 self .task_id ,
130- SystemMessage (content = "超过最大思考次数 " , type = "error" ),
134+ SystemMessage (content = "超过最大聊天次数 " , type = "error" ),
131135 )
132136 raise Exception (
133137 f"Reached maximum number of chat turns ({ self .max_chat_turns } ). Task incomplete."
134138 )
135139
136140 if retry_count >= self .max_retries :
141+ logger .error (f"超过最大尝试次数: { self .max_retries } " )
137142 await redis_manager .publish_message (
138143 self .task_id ,
139144 SystemMessage (content = "超过最大尝试次数" , type = "error" ),
@@ -149,21 +154,25 @@ async def run(self, prompt: str, subtask_title: str) -> CoderToWriter:
149154 and self .current_chat_turns < self .max_chat_turns
150155 ):
151156 self .current_chat_turns += 1
157+ logger .info (f"当前对话轮次: { self .current_chat_turns } " )
152158 response = await self .model .chat (
153159 history = self .chat_history ,
154160 tools = tools ,
155161 tool_choice = "auto" ,
156162 agent_name = self .__class__ .__name__ ,
157163 )
158164
165+ # 如果有工具调用
159166 if (
160167 hasattr (response .choices [0 ].message , "tool_calls" )
161168 and response .choices [0 ].message .tool_calls
162169 ):
170+ logger .info ("检测到工具调用" )
163171 tool_call = response .choices [0 ].message .tool_calls [0 ]
164172 tool_id = tool_call .id
165173 # TODO: json JSON解析时遇到了无效的转义字符
166174 if tool_call .function .name == "execute_code" :
175+ logger .info (f"调用工具: { tool_call .function .name } " )
167176 await redis_manager .publish_message (
168177 self .task_id ,
169178 SystemMessage (
@@ -191,7 +200,7 @@ async def run(self, prompt: str, subtask_title: str) -> CoderToWriter:
191200 )
192201
193202 # 执行工具调用
194- logger .warning ("执行工具调用" )
203+ logger .info ("执行工具调用" )
195204 (
196205 text_to_gpt ,
197206 error_occurred ,
@@ -208,11 +217,11 @@ async def run(self, prompt: str, subtask_title: str) -> CoderToWriter:
208217 "tool_call_id" : tool_id ,
209218 }
210219 )
211-
220+ # 代码执行错误
212221 if error_occurred :
213- logger .warning ("代码执行错误" )
214-
222+ logger .warning (f"代码执行错误: { error_message } " )
215223 retry_count += 1
224+ logger .info (f"当前尝试次:{ retry_count } / { self .max_retries } " )
216225 last_error_message = error_message
217226 reflection_prompt = get_reflection_prompt (error_message , code )
218227
@@ -224,12 +233,16 @@ async def run(self, prompt: str, subtask_title: str) -> CoderToWriter:
224233 self .append_chat_history (
225234 {"role" : "user" , "content" : reflection_prompt }
226235 )
236+ # 如果代码出错,返回重新开始
227237 continue
228238
229239 # 检查任务完成情况时也计入对话轮次
230240 self .current_chat_turns += 1
241+ logger .info (
242+ f"当前对话轮次: { self .current_chat_turns } / { self .max_chat_turns } "
243+ )
231244 # 使用所有执行结果生成检查提示
232- logger .warning ("判断是否完成" )
245+ logger .info ("判断是否完成" )
233246
234247 completion_check_prompt = get_completion_check_prompt (
235248 prompt , text_to_gpt
@@ -252,14 +265,18 @@ async def run(self, prompt: str, subtask_title: str) -> CoderToWriter:
252265 hasattr (completion_response .choices [0 ].message , "tool_calls" )
253266 and completion_response .choices [0 ].message .tool_calls
254267 ):
255- logger .warning ("没有调用工具,代表已经完成了 " )
268+ logger .info ("没有调用工具,代表任务已完成 " )
256269 task_completed = True
257270 return completion_response .choices [0 ].message .content
271+ else :
272+ logger .info ("没有工具,代表任务完成" )
258273
259274 if retry_count >= self .max_retries :
275+ logger .error (f"超过最大尝试次数: { self .max_retries } " )
260276 return f"Failed to complete task after { self .max_retries } attempts. Last error: { last_error_message } "
261277
262278 if self .current_chat_turns >= self .max_chat_turns :
279+ logger .error (f"超过最大对话轮次: { self .max_chat_turns } " )
263280 return f"Reached maximum number of chat turns ({ self .max_chat_turns } ). Task incomplete."
264281
265282 logger .info (f"{ self .__class__ .__name__ } :完成:执行子任务: { subtask_title } " )
@@ -270,6 +287,7 @@ async def run(self, prompt: str, subtask_title: str) -> CoderToWriter:
270287# 长文本
271288# TODO: 并行 parallel
272289# TODO: 获取当前文件下的文件
290+ # TODO: 引用cites tool
273291class WriterAgent (Agent ): # 同样继承自Agent类
274292 def __init__ (
275293 self ,
0 commit comments