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: 9 additions & 1 deletion code/chapter4/ReAct.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import re
from datetime import datetime
from llm_client import HelloAgentsLLM
from tools import ToolExecutor, search

# (此处省略 REACT_PROMPT_TEMPLATE 的定义)
REACT_PROMPT_TEMPLATE = """
请注意,你是一个有能力调用外部工具的智能助手。
当前时间:{current_date}

可用工具如下:
{tools}
Expand Down Expand Up @@ -40,7 +42,13 @@ def run(self, question: str):

tools_desc = self.tool_executor.getAvailableTools()
history_str = "\n".join(self.history)
prompt = REACT_PROMPT_TEMPLATE.format(tools=tools_desc, question=question, history=history_str)
current_date = datetime.now().strftime("%Y年%m月%d日")
prompt = REACT_PROMPT_TEMPLATE.format(
current_date=current_date,
tools=tools_desc,
question=question,
history=history_str
)

messages = [{"role": "user", "content": prompt}]
response_text = self.llm_client.think(messages=messages)
Expand Down
3 changes: 3 additions & 0 deletions docs/chapter4/Chapter4-Building-Classic-Agent-Paradigms.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ The prompt is the cornerstone of the entire ReAct mechanism, providing operation
# ReAct Prompt Template
REACT_PROMPT_TEMPLATE = """
Please note that you are an intelligent assistant capable of calling external tools.
current_date: {current_date}

Available tools are as follows:
{tools}
Expand Down Expand Up @@ -409,7 +410,9 @@ class ReActAgent:
# 1. Format prompt
tools_desc = self.tool_executor.getAvailableTools()
history_str = "\n".join(self.history)
current_date = datetime.now().strftime("%Y-%m-%d")
prompt = REACT_PROMPT_TEMPLATE.format(
current_date=current_date,
tools=tools_desc,
question=question,
history=history_str
Expand Down
3 changes: 3 additions & 0 deletions docs/chapter4/第四章 智能体经典范式构建.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ DRIVE AGX. 强大的车载计算能力,适用于AI 驱动的智能汽车系统
# ReAct 提示词模板
REACT_PROMPT_TEMPLATE = """
请注意,你是一个有能力调用外部工具的智能助手。
当前时间:{current_date}

可用工具如下:
{tools}
Expand Down Expand Up @@ -409,7 +410,9 @@ class ReActAgent:
# 1. 格式化提示词
tools_desc = self.tool_executor.getAvailableTools()
history_str = "\n".join(self.history)
current_date = datetime.now().strftime("%Y年%m月%d日")
prompt = REACT_PROMPT_TEMPLATE.format(
current_date=current_date,
tools=tools_desc,
question=question,
history=history_str
Expand Down