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

AzureMLChatOnlineEndpoint not compatible with create_react_agent (NotImplementedError for bind_tool method) #28129

Open
5 tasks done
informatica92 opened this issue Nov 15, 2024 · 0 comments
Labels
Ɑ: core Related to langchain-core

Comments

@informatica92
Copy link

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

import os
from langchain_community.chat_models.azureml_endpoint import AzureMLChatOnlineEndpoint,  AzureMLEndpointApiType, CustomOpenAIChatContentFormatter
from langchain_community.utilities import SQLDatabase
from langchain_community.agent_toolkits.sql.toolkit import SQLDatabaseToolkit
from langchain import hub
from langgraph.prebuilt import create_react_agent

if __name__ == "__main__":
    db = SQLDatabase.from_uri("sqlite:///Chinook.db")

    url = os.environ.get("AZUREML_ENDPOINT_URL")
    key = os.environ.get("AZUREML_ENDPOINT_KEY")
    timeout = 60 * 5  # default = 60 * 5 = 5 minutes

    llm = AzureMLChatOnlineEndpoint(
        endpoint_url=url,
        endpoint_api_type=AzureMLEndpointApiType.serverless,
        endpoint_api_key=key,
        content_formatter=CustomOpenAIChatContentFormatter(),
        timeout=timeout  # default = 60 * 5 = 5 minutes
    )

    toolkit = SQLDatabaseToolkit(db=db, llm=llm)

    prompt_template = hub.pull("langchain-ai/sql-agent-system-prompt")

    system_message = prompt_template.format(dialect="SQLite", top_k=5)

    agent_executor = create_react_agent(llm, toolkit.get_tools(), state_modifier=system_message)

    example_query = "Which country's customers spent the most?"

    events = agent_executor.stream(
        {"messages": [("user", example_query)]},
        stream_mode="values",
    )
    for event in events:
        event["messages"][-1].pretty_print()

Error Message and Stack Trace (if applicable)

"C:\Users\...\git\Text2SQL\Text2SQL - ENV\Scripts\python.exe" C:\Users\...\git\Text2SQL\text2sql\main_agent_llama.py 
C:\Users\...\git\Text2SQL\Text2SQL - ENV\Lib\site-packages\langsmith\client.py:221: LangSmithMissingAPIKeyWarning: API key must be provided when using hosted LangSmith API
  warnings.warn(
Traceback (most recent call last):
  File "C:\Users\...\git\Text2SQL\text2sql\main_agent_llama.py", line 571, in <module>
    agent_executor = create_react_agent(llm, toolkit.get_tools(), state_modifier=system_message)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\...\git\Text2SQL\Text2SQL - ENV\Lib\site-packages\langgraph\_api\deprecation.py", line 80, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\...\git\Text2SQL\Text2SQL - ENV\Lib\site-packages\langgraph\prebuilt\chat_agent_executor.py", line 512, in create_react_agent
    model = cast(BaseChatModel, model).bind_tools(tool_classes)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\...\git\Text2SQL\Text2SQL - ENV\Lib\site-packages\langchain_core\language_models\chat_models.py", line 1115, in bind_tools
    raise NotImplementedError
NotImplementedError

Description

I'm trying to implement a future-ready SQL Agent with an open weights model (Meta LLama) hosted into an Azure AI infrastructure.
My code is pretty simple and it's just one of the various how-to guides in which I switched from the original OpenAI model to a AzureMLChatOnlineEndpoint.

But the execution interrupts pretty soon since the flow relies on the BaseModel bind_tool implementation that just throw a "NotImplementedError".

Is there ant chance to make AzureMLChatOnlineEndpoint compatible with this method?
Consider that the direction in which LangChain is moving is LangGraph so makes no sense now to create an agent using create_sql_agent from from langchain_community.agent_toolkits

System Info

System Information

OS: Windows
OS Version: 10.0.22631
Python Version: 3.11.7 | packaged by Anaconda, Inc. | (main, Dec 15 2023, 18:05:47) [MSC v.1916 64 bit (AMD64)]

Package Information

langchain_core: 0.3.15
langchain: 0.3.6
langchain_community: 0.3.4
langsmith: 0.1.138
langchain_groq: 0.2.1
langchain_openai: 0.2.4
langchain_text_splitters: 0.3.1
langgraph: 0.2.41

Optional packages not installed

langserve

Other Dependencies

aiohttp: 3.10.10
async-timeout: Installed. No version info available.
dataclasses-json: 0.6.7
groq: 0.11.0
httpx: 0.27.2
httpx-sse: 0.4.0
jsonpatch: 1.33
langgraph-checkpoint: 2.0.2
langgraph-sdk: 0.1.35
numpy: 1.26.4
openai: 1.53.0
orjson: 3.10.10
packaging: 24.1
pydantic: 2.9.2
pydantic-settings: 2.6.0
PyYAML: 6.0.2
requests: 2.32.3
requests-toolbelt: 1.0.0
SQLAlchemy: 2.0.36
tenacity: 8.5.0
tiktoken: 0.8.0
typing-extensions: 4.12.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ɑ: core Related to langchain-core
Projects
None yet
Development

No branches or pull requests

1 participant