Skip to content

Commit 5576758

Browse files
authored
Merge pull request #6 from jihe520/dev
change prompt
2 parents 02ddc99 + 3729382 commit 5576758

File tree

6 files changed

+45
-17
lines changed

6 files changed

+45
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Thanks to the following projects:
140140
- [TaskWeaver](https://github.com/microsoft/TaskWeaver)
141141
- [Code-Interpreter](https://github.com/MrGreyfun/Local-Code-Interpreter/tree/main)
142142
- [Latex](https://github.com/Veni222987/MathModelingLatexTemplate/tree/main)
143-
143+
- [Agent Laboratory](https://github.com/SamuelSchmidgall/AgentLaboratory)
144144

145145
## 其他
146146

README_EN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ Thanks to the following projects:
138138
- [TaskWeaver](https://github.com/microsoft/TaskWeaver)
139139
- [Code-Interpreter](https://github.com/MrGreyfun/Local-Code-Interpreter/tree/main)
140140
- [Latex](https://github.com/Veni222987/MathModelingLatexTemplate/tree/main)
141+
- [Agent Laboratory](https://github.com/SamuelSchmidgall/AgentLaboratory)
141142

142143
## Others
143144

backend/app/core/agents.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
273291
class WriterAgent(Agent): # 同样继承自Agent类
274292
def __init__(
275293
self,

backend/app/core/functions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@
2020
},
2121
},
2222
]
23+
24+
# TODO: pip install python
25+
26+
# TODO: read files
27+
28+
# TODO: get_cites

backend/app/core/prompts.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@
5353
12. 在生成代码时,对于包含单引号的字符串,请使用双引号包裹,避免使用转义字符
5454
13. **你尽量在较少的对话轮次内完成任务。减少反复思考的次数**
5555
14. 在求解问题和建立模型过程中,适当的进行可视化
56-
15. 不要询问用户任何有关内容,按照你的项目完成。
56+
5757
5858
Important:
5959
1. Files are already in the current directory
6060
2. No need to check file existence
6161
3. No need to ask user about files
6262
4. Just proceed with data processing directly
63+
5. Don't ask user any thing about how to do and next to do,just do it by yourself
6364
64-
Note: If the user uploads a file, you will receive a system message "User uploaded a file: filename". Use the filename as the path in the code.
6565
"""
6666
# 15. 在画图时候,matplotlib 需要正确显示中文,避免乱码问题
6767

@@ -110,12 +110,12 @@ def get_reflection_prompt(error_message, code) -> str:
110110
4. File path issues
111111
5. Any other potential issues
112112
6. 如果一个任务反复无法完成,尝试切换路径、简化路径,千万别陷入反复重试,导致死循环。
113-
7. 不要询问用户任何有关内容,按照你的项目完成。
113+
7. Don't ask user any thing about how to do and next to do,just do it by yourself.
114114
115115
Previous code:
116116
{code}
117117
118-
Please provide an explanation of what went wrong and the corrected code.
118+
Please provide an explanation of what went wrong and Remenber call the function tools to retry
119119
"""
120120

121121

@@ -134,8 +134,9 @@ def get_completion_check_prompt(prompt, text_to_gpt) -> str:
134134
3. Are there any remaining steps needed?
135135
4. Is the output satisfactory and complete?
136136
5. 如果一个任务反复无法完成,尝试切换路径、简化路径或直接跳过,千万别陷入反复重试,导致死循环。
137-
6. 尽量在较少的对话轮次内完成任务,task_completed = True
138-
If the task is not complete, please explain what remains to be done and continue with the next steps.
139-
If the task is complete, please provide a summary of what was accomplished about your create image name.
140-
7. 不要询问用户任何有关内容,按照你的项目完成。
137+
6. 尽量在较少的对话轮次内完成任务
138+
7. If the task is complete, please provide a short summary of what was accomplished and don't call function tool.
139+
8. If the task is not complete, please rethink how to do and call function tool
140+
9. Don't ask user any thing about how to do and next to do,just do it by yourself
141+
141142
"""

backend/app/utils/redis_manager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ async def publish_message(self, task_id: str, message: Message):
6666
try:
6767
message_json = message.model_dump_json()
6868
await client.publish(channel, message_json)
69-
logger.debug(f"消息已发布到频道 {channel}: {message_json}")
69+
logger.debug(
70+
f"消息已发布到频道 {channel}:mes_type:{message.msg_type}:msg_content:{message.content}"
71+
)
7072
# 保存消息到文件
7173
await self._save_message_to_file(task_id, message)
7274
except Exception as e:

0 commit comments

Comments
 (0)