Skip to content
Open
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
30 changes: 22 additions & 8 deletions docs/chapter8/第八章 记忆与检索.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,31 @@

```python
# 第七章的Agent使用方式
from hello_agents import SimpleAgent, HelloAgentsLLM
from dotenv import load_dotenv
from hello_agents import HelloAgentsLLM
load_dotenv()

agent = SimpleAgent(name="学习助手", llm=HelloAgentsLLM())
# 创建LLM实例
llm = HelloAgentsLLM()

# 第一次对话
response1 = agent.run("我叫张三,正在学习Python,目前掌握了基础语法")
print(response1) # "很好!Python基础语法是编程的重要基础..."

# 第二次对话(新的会话)
response2 = agent.run("你还记得我的学习进度吗?")
print(response2) # "抱歉,我不知道您的学习进度..."
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}")
```

要解决这个问题,我们的框架需要引入记忆系统。
Expand Down