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

GraphQL tool return TransportAlreadyConnected exception when invoked more than once #30517

Open
5 tasks done
maver1ck opened this issue Mar 27, 2025 · 1 comment
Open
5 tasks done
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@maver1ck
Copy link
Contributor

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

I'm using following code to create agent that will talk to Datahub via GraphQL

def create_discovery_agent(datahub_endpoint: str):
    """Create an agent for discovering data in DataHub."""
    
    # Initialize the GraphQL tool with DataHub endpoint
    graphql_tool = BaseGraphQLTool(
        graphql_wrapper=GraphQLAPIWrapper(graphql_endpoint=datahub_endpoint, custom_headers={"Authorization": f"Bearer {os.environ.get('DATAHUB_TOKEN')}"}),
        name="datahub_graphql",
        description="""
        Use this tool to search and discover datasets in DataHub using GraphQL queries.
        To search for datasets, use a query in this format:
        
        query {
            search(input: {
                type: DATASET
                query: "your_search_term"
                start: 0
                count: 10
                orFilters: [
                    {
                        and: [
                            {
                                field: "origin"
                                values: ["PROD"]
                            }
                        ]
                    }
                ]
            }) {
                start
                count
                total
                searchResults {
                    entity {
                        urn
                        type
                        ... on Dataset {
                            name
                            description
                            platform {
                                name
                            }
                        }
                    }
                    matchedFields {
                        name
                        value
                    }
                }
            }
        }

        Use this query and only replace "your_search_term" with keywords to search for.
        The tool will return dataset information including URN, name, description, and platform details.
        Make sure to escape any quotes in your search term.
        """
    )

    tools = [graphql_tool]
    

    # Create the discovery agent using ReAct template
    discovery_agent = create_react_agent(
        model=model,
        tools=tools,
        name="data_discovery_expert",
        prompt="You are a data discovery expert. Always use one tool at a time. Your goal is to find relevant datasets in DataHub.",
    ).with_config(tags=["skip_stream"])

Error Message and Stack Trace (if applicable)

"Traceback (most recent call last):\n  File \"/Users/maverick/.virtualenvs/agent-service-toolkit-uinp/lib/python3.12/site-packages/langchain_core/tools/base.py\", line 846, in arun\n    response = await asyncio.create_task(coro, context=context)  # type: ignore\n               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/maverick/.virtualenvs/agent-service-toolkit-uinp/lib/python3.12/site-packages/langchain_core/tools/base.py\", line 635, in _arun\n    return await run_in_executor(None, self._run, *args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/maverick/.virtualenvs/agent-service-toolkit-uinp/lib/python3.12/site-packages/langchain_core/runnables/config.py\", line 622, in run_in_executor\n    return await asyncio.get_running_loop().run_in_executor(\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/opt/homebrew/Cellar/[email protected]/3.12.9/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/thread.py\", line 59, in run\n    result = self.fn(*self.args, **self.kwargs)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/maverick/.virtualenvs/agent-service-toolkit-uinp/lib/python3.12/site-packages/langchain_core/runnables/config.py\", line 613, in wrapper\n    return func(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/maverick/.virtualenvs/agent-service-toolkit-uinp/lib/python3.12/site-packages/langchain_community/tools/graphql/tool.py\", line 35, in _run\n    result = self.graphql_wrapper.run(tool_input)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/maverick/.virtualenvs/agent-service-toolkit-uinp/lib/python3.12/site-packages/langchain_community/utilities/graphql.py\", line 51, in run\n    result = self._execute_query(query)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/maverick/.virtualenvs/agent-service-toolkit-uinp/lib/python3.12/site-packages/langchain_community/utilities/graphql.py\", line 57, in _execute_query\n    result = self.gql_client.execute(document_node)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/maverick/.virtualenvs/agent-service-toolkit-uinp/lib/python3.12/site-packages/gql/client.py\", line 483, in execute\n    return self.execute_sync(\n           ^^^^^^^^^^^^^^^^^^\n  File \"/Users/maverick/.virtualenvs/agent-service-toolkit-uinp/lib/python3.12/site-packages/gql/client.py\", line 246, in execute_sync\n    with self as session:\n         ^^^^\n  File \"/Users/maverick/.virtualenvs/agent-service-toolkit-uinp/lib/python3.12/site-packages/gql/client.py\", line 859, in __enter__\n    return self.connect_sync()\n           ^^^^^^^^^^^^^^^^^^^\n  File \"/Users/maverick/.virtualenvs/agent-service-toolkit-uinp/lib/python3.12/site-packages/gql/client.py\", line 835, in connect_sync\n    self.session.connect()\n  File \"/Users/maverick/.virtualenvs/agent-service-toolkit-uinp/lib/python3.12/site-packages/gql/client.py\", line 1267, in connect\n    self.transport.connect()\n  File \"/Users/maverick/.virtualenvs/agent-service-toolkit-uinp/lib/python3.12/site-packages/gql/transport/requests.py\", line 117, in connect\n    raise TransportAlreadyConnected(\"Transport is already connected\")\ngql.transport.exceptions.TransportAlreadyConnected: Transport is already connected"

Description

I'm using mentioned combination of tool and agent.
As a result of a query I got multiple tool calls from one query (screen attached)
First GraphQL query is passing, consecutive ones are failing with exception.

Image

Image

System Info


System Information
------------------
> OS:  Darwin
> OS Version:  Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:16 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6000
> Python Version:  3.12.9 (main, Feb  4 2025, 14:38:38) [Clang 16.0.0 (clang-1600.0.26.6)]

Package Information
-------------------
> langchain_core: 0.3.49
> langchain: 0.3.19
> langchain_community: 0.3.20
> langsmith: 0.1.147
> langchain_anthropic: 0.3.10
> langchain_aws: 0.2.17
> langchain_google_genai: 2.0.11
> langchain_groq: 0.2.5
> langchain_ollama: 0.2.3
> langchain_openai: 0.2.14
> langchain_text_splitters: 0.3.7
> langgraph_sdk: 0.1.59
> langgraph_supervisor: 0.0.13

Optional packages not installed
-------------------------------
> langserve

Other Dependencies
------------------
> aiohttp<4.0.0,>=3.8.3: Installed. No version info available.
> anthropic<1,>=0.49.0: Installed. No version info available.
> async-timeout<5.0.0,>=4.0.0;: Installed. No version info available.
> boto3: 1.37.21
> dataclasses-json<0.7,>=0.5.7: Installed. No version info available.
> filetype: 1.2.0
> google-ai-generativelanguage: 0.6.17
> groq<1,>=0.4.1: Installed. No version info available.
> httpx: 0.27.2
> httpx-sse<1.0.0,>=0.4.0: Installed. No version info available.
> jsonpatch<2.0,>=1.33: Installed. No version info available.
> langchain-anthropic;: Installed. No version info available.
> langchain-aws;: Installed. No version info available.
> langchain-cohere;: Installed. No version info available.
> langchain-community;: Installed. No version info available.
> langchain-core<1.0.0,>=0.3.35: Installed. No version info available.
> langchain-core<1.0.0,>=0.3.42: Installed. No version info available.
> langchain-core<1.0.0,>=0.3.45: Installed. No version info available.
> langchain-deepseek;: Installed. No version info available.
> langchain-fireworks;: Installed. No version info available.
> langchain-google-genai;: Installed. No version info available.
> langchain-google-vertexai;: Installed. No version info available.
> langchain-groq;: Installed. No version info available.
> langchain-huggingface;: Installed. No version info available.
> langchain-mistralai;: Installed. No version info available.
> langchain-ollama;: Installed. No version info available.
> langchain-openai;: Installed. No version info available.
> langchain-text-splitters<1.0.0,>=0.3.6: Installed. No version info available.
> langchain-together;: Installed. No version info available.
> langchain-xai;: Installed. No version info available.
> langchain<1.0.0,>=0.3.21: Installed. No version info available.
> langgraph-prebuilt<0.2.0,>=0.1.7: Installed. No version info available.
> langgraph<0.4.0,>=0.3.5: Installed. No version info available.
> langsmith-pyo3: Installed. No version info available.
> langsmith<0.4,>=0.1.125: Installed. No version info available.
> langsmith<0.4,>=0.1.17: Installed. No version info available.
> numpy: 1.26.4
> numpy<2,>=1.26.4;: Installed. No version info available.
> numpy<3,>=1.26.2: Installed. No version info available.
> numpy<3,>=1.26.2;: Installed. No version info available.
> ollama: 0.4.7
> openai: 1.68.2
> orjson: 3.10.16
> packaging<25,>=23.2: Installed. No version info available.
> pydantic: 2.10.6
> pydantic-settings<3.0.0,>=2.4.0: Installed. No version info available.
> pydantic<3.0.0,>=2.5.2;: Installed. No version info available.
> pydantic<3.0.0,>=2.7.4: Installed. No version info available.
> pydantic<3.0.0,>=2.7.4;: Installed. No version info available.
> PyYAML>=5.3: Installed. No version info available.
> requests: 2.32.3
> requests-toolbelt: 1.0.0
> requests<3,>=2: Installed. No version info available.
> SQLAlchemy<3,>=1.4: Installed. No version info available.
> tenacity!=8.4.0,<10,>=8.1.0: Installed. No version info available.
> tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available.
> tiktoken: 0.9.0
> typing-extensions>=4.7: Installed. No version info available.
@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Mar 27, 2025
@saumanraaj
Copy link

Hey! I tried reproducing this with the same gql==3.5.2 and langchain==0.3.21 setup.
I used the basic test below (no agent, just direct tool usage)

Code:
from langchain_community.utilities.graphql import GraphQLAPIWrapper
from langchain_community.tools.graphql.tool import BaseGraphQLTool
wrapper = GraphQLAPIWrapper(graphql_endpoint="https://countries.trevorblades.com/")
tool = BaseGraphQLTool(graphql_wrapper=wrapper)
query = "{ countries { name } }"
print(tool.run(query)) # First call
print(tool.run(query)) # Second call

Both calls returned the full country list without triggering TransportAlreadyConnected.
This may only affect agent-based workflows (like create_react_agent), sync/concurrent usage, and persistent sessions in agent loops.
Let me know if you'd like me to test it with an async agent setup. Happy to help debug further!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants