LangChain await bug with SQLAgent
Bug Description
LangFlow version: 1.0.18 Problem: Same issue as mentioned in the fix from PR #3775.
Details:
- Tested with a simple SQLAgent flow.
- Findings: a. The flow works with Ollama as the model component. b. The same error occurs when OpenAI is used as the model component for the SQLAgent.
Reproduction
You may refer to the flow file as reference. SQLAgent Flow.json
Expected behavior
An error occurs on SQLAgent component. Error message from notification: "Error building Component SQLAgent: object LangfuseResponseGeneratorSync can't be used in 'await' expression"
Who can help?
No response
Operating System
Windows 11
Langflow Version
1.0.18
Python Version
3.12
Screenshot
No response
Flow File
No response
Hey there, @ch4mploo! I'm Dosu, a bot here to help you with bug resolutions, questions, and contributions. I'm here to assist you while we wait for a human maintainer.
To resolve the "Error building Component SQLAgent: object LangfuseResponseGeneratorSync can't be used in 'await' expression" issue when using OpenAI as the model component in LangFlow version 1.0.18, ensure that the LangfuseResponseGeneratorSync object is not being used in an await expression. This error typically occurs when a synchronous object is mistakenly awaited.
Here is a general approach to resolve such issues:
- Identify the Awaited Object: Find where
LangfuseResponseGeneratorSyncis being used and ensure it is not awaited. - Check Asynchronous Functions: Ensure that all asynchronous functions are defined with
async defand are awaited properly. - Review the Call Stack: Trace back the call stack to see where the
awaitexpression is being used incorrectly.
Example Correction
Incorrect Usage
# Hypothetical incorrect usage
response_generator = LangfuseResponseGeneratorSync()
result = await response_generator.generate_response() # Incorrect: Awaiting a sync method
Correct Usage
# Correct usage
response_generator = LangfuseResponseGeneratorSync()
result = response_generator.generate_response() # Correct: No await for sync method
If LangfuseResponseGeneratorSync has an asynchronous counterpart, use that instead:
# If there is an async version
response_generator = LangfuseResponseGeneratorAsync()
result = await response_generator.generate_response() # Correct: Awaiting an async method
Additionally, you can refer to the src/backend/base/langflow/api/v1/chat.py file for examples of how asynchronous operations are handled in LangFlow. For instance, the build_vertex function demonstrates proper usage of asynchronous calls:
async def build_vertex(
flow_id: uuid.UUID,
vertex_id: str,
background_tasks: BackgroundTasks,
inputs: Annotated[InputValueRequest | None, Body(embed=True)] = None,
files: list[str] | None = None,
chat_service: "ChatService" = Depends(get_chat_service),
current_user=Depends(get_current_active_user),
telemetry_service: "TelemetryService" = Depends(get_telemetry_service),
):
# Function implementation
try:
vertex_build_result = await graph.build_vertex(
vertex_id=vertex_id,
user_id=current_user.id,
inputs_dict=inputs.model_dump() if inputs else {},
files=files,
get_cache=chat_service.get_cache,
set_cache=chat_service.set_cache,
)
# Further processing
except Exception as exc:
# Error handling
By following these guidelines and reviewing the provided examples, you should be able to resolve the issue effectively [1][2].
To continue talking to Dosu, mention @dosu.
I think I found the solution.
Based on PR #3775, it seems that the code change in line 147 of src/backend/base/langflow/base/agents/agent.py is applied to the class LCToolsAgentComponent to modify the run_agent method.
However, the same method for its parent class, LCAgentComponent, did not receive similar modification, which I assumed it should since it has its own run_agent method as well. So I've applied a similar change you did for line 147 to line 101.
Modification of line 101:
result = agent.invoke(
After the modification, the SQLAgent component has run without error.
Hi @ch4mploo,
Thanks for your reply and suggestion. It fixed the component build. You can follow the PR: #3789 for any updates.
Answer: The biggest salary is 129901.12, earned by FirstName24 LastName62.
maybe related to https://github.com/langflow-ai/langflow/issues/3840