Replies: 2 comments 2 replies
-
To resolve the Here's an example of how you might use asynchronous context management correctly with LangChain agents: import asyncio
from langchain.agents import AgentExecutor
async def main():
# Initialize your agent executor
agent_executor = AgentExecutor(
agent=self.agent_runnable,
tools=self.tools,
memory=memory,
max_iterations=35,
max_execution_time=90,
early_stopping_method='force',
verbose=app_keys.DEBUG(2),
handle_parsing_errors=True,
return_intermediate_steps=return_intermediate_steps,
callbacks=chat.callbacks
).with_config({"run_name": "Agent"})
# Use asynchronous context management
async with agent_executor as executor:
# Perform actions with the executor
result = await executor.ainvoke(self.context, return_only_outputs=True)
print(result)
# Run the main function
asyncio.run(main()) Ensure that any class or function you are using that requires asynchronous context management is properly awaited and used within an |
Beta Was this translation helpful? Give feedback.
-
First of all, I made it clear that my application was working without
errors before updating LangChain. After the update, this error appeared.
And as soon as I revert to the previous version, the error disappears
again. Therefore, I do not understand your recommendations.
Em ter., 2 de jul. de 2024, 09:56, dosubot[bot] ***@***.***>
escreveu:
… To resolve the __aenter__ error after upgrading the LangChain-related
packages, you need to ensure that you are using the correct asynchronous
context management methods provided by the updated LangChain library. The
__aenter__ method is part of the asynchronous context management
protocol, and its absence or misconfiguration can lead to such errors.
Here's an example of how you might use asynchronous context management
correctly with LangChain agents:
import asynciofrom langchain.agents import AgentExecutor
async def main():
# Initialize your agent executor
agent_executor = AgentExecutor(
agent=self.agent_runnable,
tools=self.tools,
memory=memory,
max_iterations=35,
max_execution_time=90,
early_stopping_method='force',
verbose=app_keys.DEBUG(2),
handle_parsing_errors=True,
return_intermediate_steps=return_intermediate_steps,
callbacks=chat.callbacks
).with_config({"run_name": "Agent"})
# Use asynchronous context management
async with agent_executor as executor:
# Perform actions with the executor
result = await executor.ainvoke(self.context, return_only_outputs=True)
print(result)
# Run the main functionasyncio.run(main())
Ensure that any class or function you are using that requires asynchronous
context management is properly awaited and used within an async with
block. This should help resolve the __aenter__ error [1]
<https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/agents/__init__.py>
.
*To continue talking to Dosu <https://dosu.dev>, mention @dosu
<https://github.com/dosu>.*
—
Reply to this email directly, view it on GitHub
<#23762 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGFVVUTZZ3BLIISNBKPEGDZKKPQDAVCNFSM6AAAAABKHOHZGWVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TSMZWGU4DE>
.
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
Dear friends, I need help!
Context: I have a production multi-agent application that stopped working at some point after these versions:
langchain==0.2.1
langchain-community==0.2.1
langchain-experimental==0.0.59
langchain-openai==0.1.7
langchain-qdrant==0.1.0
langgraph==0.0.55
Only after the update did it start presenting the error: "aenter"
The error message is simply: "aenter"
Relevant points from my source code:
To try to solve the problem I have already tried with these 3 methods below, but it did not work:
agent_runnable= create_openai_tools_agent(llm=self.llm_with_tools, tools=self.tools, prompt=prompt_obj)
or
agent_runnable= create_tool_calling_agent(llm=self.llm_with_tools, tools=self.tools, prompt=prompt_obj)
or
agent_runnable= create_openai_functions_agent(llm=self.llm_with_tools, tools=self.tools, prompt=prompt_obj)
...
agent_executor = AgentExecutor(agent=self.agent_runnable,
tools=self.tools,
memory=memory,
max_iterations=35,
max_execution_time=90,
#early_stopping_method='generate',
early_stopping_method='force',
verbose=app_keys.DEBUG(2),
handle_parsing_errors=True,
#handle_parsing_errors=False,
return_intermediate_steps=return_intermediate_steps,
callbacks=chat.callbacks
).with_config({"run_name": "Agent"})
...
**result = await self.agent_executor.ainvoke(self.context, return_only_outputs=True)
This is where the error happens: "aenter"**
The error message is simply: "aenter"
I emphasize that the application worked without problems for a long time before version upgrade.
Can someone please help me?
Thank you!
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