langchain==0.3.20
langchain-community==0.3.19
langchain-openai==0.3.8
openai==1.66.3
python-dotenv==1.0.1
您可以使用内存。例如,首先创建A
ConversaionBufferMemory
来存储遵守的结果:
from langchain.memory import ConversationBufferMemory
mmemory = ConversationBufferMemory(
memory_key="context", return_messages=True
)
@tool
def weather(city: str) -> str:
"""Gives the weather in a given city"""
weather_info = f"The weather in {city} is sunny."
memory.save_context({"context": weather_info}, {}) # Store weather in memory
return weather_info
chain = LLMChain(llm=llm_with_tools, prompt=prompt, memory=memory)
您可以从现在开始管理内存,以控制应传递给上下文的内容,并相应地传递给使用相同的链的所有链条。