Replies: 2 comments 2 replies
-
The error "Must write to at least one of ['messages']" occurs because the Here's how you can modify your code to use the
Here is an example of how you might implement and use the def add_message(self, message: BaseMessage) -> None:
"""Append the message to the record in DynamoDB"""
try:
from botocore.exceptions import ClientError
except ImportError as e:
raise ImportError(
"Unable to import botocore, please install with `pip install botocore`."
) from e
messages = messages_to_dict(self.messages)
_message = message_to_dict(message)
messages.append(_message)
if self.history_size:
messages = messages[-self.history_size:]
try:
if self.ttl:
import time
expireAt = int(time.time()) + self.ttl
self.table.put_item(
Item={**self.key, "History": messages, self.ttl_key_name: expireAt}
)
else:
self.table.put_item(Item={**self.key, "History": messages})
except ClientError as err:
logger.error(err)
# Example usage
self.add_message(new_message) Ensure that you are using the |
Beta Was this translation helpful? Give feedback.
-
Hello @dosu,
Please review my code. I am not using anything from Messages. I am creating
a create_react_agent and calling it through AgentExecutor, as per your
example.
Here is your code:
```python
# Create the agent
agent = create_react_agent(model, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools)
# Invoke the agent with the required variables
result = await agent_executor.ainvoke({
"input": "hi",
"agent_scratchpad": "", # Initial empty scratchpad
"tools": "tool descriptions here",
"tool_names": "tool1, tool2"
}, config={"configurable": {"thread_id": "1"}}, debug=True)
print(result)
```
Thank you.
Em qua., 3 de jul. de 2024 às 15:37, dosubot[bot] ***@***.***>
escreveu:
… The error "Must write to at least one of ['messages']" occurs because the
messages property is not being set correctly. In your code, you should
use the add_message method to add messages to the chat session instead of
directly assigning to the messages property.
Here's how you can modify your code to use the add_message method:
1.
Ensure that you have a method to add messages to the chat session.
This method should append the message to the existing messages and handle
any necessary updates.
2.
Use this method to add messages to your chat session.
Here is an example of how you might implement and use the add_message
method:
def add_message(self, message: BaseMessage) -> None:
"""Append the message to the record in DynamoDB"""
try:
from botocore.exceptions import ClientError
except ImportError as e:
raise ImportError(
"Unable to import botocore, please install with `pip install botocore`."
) from e
messages = messages_to_dict(self.messages)
_message = message_to_dict(message)
messages.append(_message)
if self.history_size:
messages = messages[-self.history_size:]
try:
if self.ttl:
import time
expireAt = int(time.time()) + self.ttl
self.table.put_item(
Item={**self.key, "History": messages, self.ttl_key_name: expireAt}
)
else:
self.table.put_item(Item={**self.key, "History": messages})
except ClientError as err:
logger.error(err)
# Example usageself.add_message(new_message)
Ensure that you are using the add_message method to add messages to the
chat session in DynamoDB. Direct assignment to the messages property is
not allowed, as indicated by the NotImplementedError in the setter method
[1]
<https://github.com/langchain-ai/langchain/blob/master/libs/community/langchain_community/chat_message_histories/dynamodb.py>
[2]
<https://github.com/langchain-ai/langchain/blob/master/libs/community/langchain_community/chat_message_histories/neo4j.py>
[3]
<https://github.com/langchain-ai/langchain/blob/master/libs/community/langchain_community/chat_message_histories/elasticsearch.py>
.
*To continue talking to Dosu <https://dosu.dev>, mention @dosu
<https://github.com/dosu>.*
—
Reply to this email directly, view it on GitHub
<#23834 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGFVVW6IB7OQGPCYC3TPRTZKRAG5AVCNFSM6AAAAABKKDUXHOVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TSNJRGQ3DE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
Hi @dosu,
Could you help me what is this error:
prompt_template = dedent(
"""
[prompt_base_conhecimento]
prompt_obj = ChatPromptTemplate.from_messages(
[
( "system", prompt_template),
( "human", "{input}"),
]
)
contexto = {
"input": self.query,
"idioma": self.idioma,
"dia_da_semana": datetime.now().strftime("%A"),
"data_hoje": datetime.now().strftime("%Y-%m-%d"),
"email_cliente": self.email_usuario,
"nome_cliente": self.nome_usuario,
"email_usuario": self.email_usuario,
"nome_usuario": self.nome_usuario,
#"chat_history": "vazio",
#"agent_scratchpad": "vazio",
}
agent = create_react_agent(model=llm_with_tools, tools=tools, messages_modifier=prompt_obj, debug=True)
#memory = await chat.get_memory(None, None, input_key="input", output_key="output")
agent_executor = AgentExecutor(agent, tools=tools,
#memory=memory,
max_iterations=35,
max_execution_time=90,
#early_stopping_method='generate',
early_stopping_method='force',
verbose=True,
handle_parsing_errors=True,
return_intermediate_steps=False,
callbacks=chat.callbacks
).with_config({"run_name": "Agent"})
config={"configurable": {"thread_id": "1"}}
resultado = await agent_executor.ainvoke(contexto, config=config, return_only_outputs=True)
ERROR:
[0:tasks] Starting step 0 with 1 task:
'data_hoje': '2024-07-03',
'dia_da_semana': 'quarta',
'email_cliente': '[email protected]',
'email_usuario': '[email protected]',
'idioma': 'Português.',
'input': '$$qual o tom da conversa?$$',
'intermediate_steps': [],
'nome_cliente': 'João Sem Nome',
'nome_usuario': 'João Sem Nome'}
Não consegui responder à sua pergunta por problemas internos ou de conexão. Por favor, tente novamente
Erro (websocket_endpoint): Must write to at least one of ['messages']
System Info
langchain==0.2.6
langchain-community==0.2.6
langchain-core==0.2.10
langchain-experimental==0.0.62
langchain-openai==0.1.13
langchain-qdrant==0.1.0
langchain-text-splitters==0.2.1
Beta Was this translation helpful? Give feedback.
All reactions