Fix: corrected a code of the necessity of introducing a memory system… #217
+22
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
我修改了第八章 记忆与检索.md ,用原本的HelloAgentsLLM,得到的结果才是0记忆功能的,为记忆功能必要性提供支撑。
源代码执行结果:
你好,张三!很高兴知道你正在学习Python。如果你已经掌握了基础语法,接下来可以考虑学习一些更高级的主题,比如:
xxxxxxx
你有什么特定的方向或问题想要探讨吗?
当然记得,张三!你提到你已经掌握了Python的基础语法。xxxxxxx
因为执行的智能体为SimpleAgent,run方法中会添加历史信息(记忆功能):
# 添加历史消息
for msg in self._history:
messages.append({"role": msg.role, "content": msg.content})
我修改后的代码:
第七章的Agent使用方式
from dotenv import load_dotenv
from hello_agents import HelloAgentsLLM
load_dotenv()
创建LLM实例
llm = HelloAgentsLLM()
第一次对话
messages1 = [
{"role": "system", "content": "你是一个学习助手"},
{"role": "user", "content": "我叫张三,正在学习Python,目前掌握了基础语法"}
]
print("第一次对话:")
response1 = "".join(llm.think(messages1))
print(f"完整回复: {response1}")
第二次对话
messages2 = [
{"role": "user", "content": "你还记得我的学习进度吗?"}
]
print("\n第二次对话:")
response2 = "".join(llm.think(messages2))
print(f"完整回复: {response2}")