Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LangChain await bug with SQLAgent #3778

Closed
ch4mploo opened this issue Sep 12, 2024 · 4 comments
Closed

LangChain await bug with SQLAgent #3778

ch4mploo opened this issue Sep 12, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@ch4mploo
Copy link

Bug Description

LangFlow version: 1.0.18
Problem: Same issue as mentioned in the fix from PR #3775.

Details:

  1. Tested with a simple SQLAgent flow.
  2. 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

@ch4mploo ch4mploo added the bug Something isn't working label Sep 12, 2024
Copy link

dosubot bot commented Sep 12, 2024

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:

  1. Identify the Awaited Object: Find where LangfuseResponseGeneratorSync is being used and ensure it is not awaited.
  2. Check Asynchronous Functions: Ensure that all asynchronous functions are defined with async def and are awaited properly.
  3. Review the Call Stack: Trace back the call stack to see where the await expression 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.

@ch4mploo
Copy link
Author

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.

@Cristhianzl
Copy link
Member

Hi @ch4mploo,

Thanks for your reply and suggestion.
It fixed the component build.
You can follow the PR: #3789 for any updates.

image

Answer: The biggest salary is 129901.12, earned by FirstName24 LastName62.

@sa411022
Copy link
Contributor

maybe related to #3840

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants