Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Agent的概念、原理与构建模式/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def render_system_prompt(self, system_prompt_template: str) -> str:
return Template(system_prompt_template).substitute(
operating_system=self.get_operating_system_name(),
tool_list=tool_list,
file_list=file_list
file_list=file_list,
project_directory=self.project_directory,
)

@staticmethod
Expand Down Expand Up @@ -207,7 +208,12 @@ def run_terminal_command(command):
"""用于执行终端命令"""
import subprocess
run_result = subprocess.run(command, shell=True, capture_output=True, text=True)
return "执行成功" if run_result.returncode == 0 else run_result.stderr
if run_result.returncode != 0:
return run_result.stderr
msg = ["执行成功"]
if run_result:
msg.append(run_result.stdout)
return ": ".join(msg)

@click.command()
@click.argument('project_directory',
Expand Down
7 changes: 7 additions & 0 deletions Agent的概念、原理与构建模式/prompt_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
- 输出 <action> 后立即停止生成,等待真实的 <observation>,擅自生成 <observation> 将导致错误
- 如果 <action> 中的某个工具参数有多行的话,请使用 \n 来表示,如:<action>write_to_file("/tmp/test.txt", "a\nb\nc")</action>
- 工具参数中的文件路径请使用绝对路径,不要只给出一个文件名。比如要写 write_to_file("/tmp/test.txt", "内容"),而不是 write_to_file("test.txt", "内容")
- <observation> 中的内容可以是“成功执行“,代表工具执行成功。后面也可能跟有工具返回的数据
- 所有新创建的文件都应保存在项目目录下


本次任务的项目目录是:
${project_directory}


Expand Down