[Python] Langchain Agent: No Attribute Error : OpenAPIAgent

Discussão em 'Python' iniciado por Stack, Abril 9, 2025.

  1. Stack

    Stack Membro Participativo

    I'm building a OpenAPI Agent using langchain's OpenAPIAgent. When I try to create the agent with below code. It's throwin AttributeError. I am using simple petstore openapi specification to build this agent. Expectation would be based on user query it calls API and returns result.

    chat.py

    from langchain_ollama.llms import OllamaLLM
    from langchain_community.agent_toolkits.openapi.spec import reduce_openapi_spec
    from langchain_community.utilities.requests import RequestsWrapper
    import yaml
    import os
    from langchain_community.agent_toolkits.openapi import planner


    with open("apidocs/petstore.yaml") as file:
    raw_openapi_spec = yaml.load(file,Loader=yaml.FullLoader)

    openapi_spec = reduce_openapi_spec(raw_openapi_spec)

    requests_wrapper = RequestsWrapper(headers={"Accept": "application/json"})


    llm = OllamaLLM(model="llama3",temperature=0.0)

    agent = planner.create_openapi_agent(llm,
    openapi_spec,
    requests_wrapper,
    allow_dangerous_requests=True
    )

    user_query = ("Find all pets with status available")

    agent.invoke(user_query)


    Error

    Traceback (most recent call last):
    File "/Users/akhthaaralibadhusha/Documents/GitHub/Supplychain-Helper/apicall copy.py", line 19, in <module>
    agent = planner.create_openapi_agent(llm,
    openapi_spec,
    ...<2 lines>...

    )
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/langchain_community/agent_toolkits/openapi/planner.py", line 434, in create_openapi_agent
    _create_api_planner_tool(api_spec, llm),
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/langchain_community/agent_toolkits/openapi/planner.py", line 237, in _create_api_planner_tool
    f"{name} {description}" for name, description, _ in api_spec.endpoints
    ^^^^^^^^^^^^^^^^^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pydantic/main.py", line 994, in __getattr__
    raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}')
    AttributeError: 'OllamaLLM' object has no attribute 'endpoints'

    Continue reading...

Compartilhe esta Página