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

When running OpenAI Assistant with tools: AttributeError: 'RequiredActionFunctionToolCall' object has no attribute 'tool' #29224

Open
5 tasks done
dn-scribe opened this issue Jan 15, 2025 · 1 comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature investigate Flagged for investigation.

Comments

@dn-scribe
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

When running an AgentExecutor with an assistant, some some return value is not handled by the agent code.

Here is the code of a Chat agent (runs) and an Assitant:

from langchain.agents.openai_assistant import OpenAIAssistantRunnable
from langchain.agents import Tool
from langchain.tools import StructuredTool, Tool
from langchain.agents import AgentExecutor,create_openai_tools_agent
import os

def gnix(*args, **kwargs):
    return f"The gnix is xing.\nReceived args: {args};\nreceived kwargs: {kwargs}"

# from pydantic import BaseModel, Field
# class NoArgs(BaseModel):
#     pass

# def gnix_noargs(_: NoArgs) -> str:
#     return "The gnix is xing."

tool = Tool.from_function(
        func=gnix,
        name="get_gnix",
        description="get the gnix. This function recieves no input and returns the gnix value.",
        # callbacks=[]
    )

tools = [tool]

message = "what tools do you have? can you get me the gnix?"
api_key = os.getenv("OPENAI_API_KEY")



from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder

prompt = ChatPromptTemplate.from_messages(
    [
        ("system", "You are a helpful assistant"),
        MessagesPlaceholder("chat_history", optional=True),
        ("human", "{input}"),
        MessagesPlaceholder("agent_scratchpad"),
    ]
)

model = ChatOpenAI()

agent = create_openai_tools_agent(model, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools)

output = agent_executor.invoke({"input": "how is the gnix?"})

print(output["output"])



assistant = OpenAIAssistantRunnable.create_assistant( name="tmp",model="gpt-3.5-turbo", 
                        instructions="You are a helpful helper that can use tools.", tools=tools)



agent_executor = AgentExecutor(agent=assistant, tools=tools)
output = agent_executor.invoke({"content": message})
print(output["output"])

Error Message and Stack Trace (if applicable)

python assistant_test.py

The Chat output

The gnix is xing!

The assistant output

Traceback (most recent call last):
File "/Users/danielnebenzahl/code/tmp/langchain/assistant_test.py", line 61, in
output = agent_executor.invoke({"content": message})
File "/Users/danielnebenzahl/.pyenv/versions/langchain/lib/python3.10/site-packages/langchain/chains/base.py", line 170, in invoke
raise e
File "/Users/danielnebenzahl/.pyenv/versions/langchain/lib/python3.10/site-packages/langchain/chains/base.py", line 160, in invoke
self._call(inputs, run_manager=run_manager)
File "/Users/danielnebenzahl/.pyenv/versions/langchain/lib/python3.10/site-packages/langchain/agents/agent.py", line 1624, in _call
next_step_output = self._take_next_step(
File "/Users/danielnebenzahl/.pyenv/versions/langchain/lib/python3.10/site-packages/langchain/agents/agent.py", line 1330, in _take_next_step
[
File "/Users/danielnebenzahl/.pyenv/versions/langchain/lib/python3.10/site-packages/langchain/agents/agent.py", line 1330, in
[
File "/Users/danielnebenzahl/.pyenv/versions/langchain/lib/python3.10/site-packages/langchain/agents/agent.py", line 1415, in _iter_next_step
yield self._perform_agent_action(
File "/Users/danielnebenzahl/.pyenv/versions/langchain/lib/python3.10/site-packages/langchain/agents/agent.py", line 1429, in _perform_agent_action
if agent_action.tool in name_to_tool_map:
File "/Users/danielnebenzahl/.pyenv/versions/langchain/lib/python3.10/site-packages/pydantic/main.py", line 891, in getattr
raise AttributeError(f'{type(self).name!r} object has no attribute {item!r}')
AttributeError: 'RequiredActionFunctionToolCall' object has no attribute 'tool'

Description

I expect AgentExecutor to work with assistants that use tools.

System Info

python -m langchain_core.sys_info

System Information

OS: Darwin
OS Version: Darwin Kernel Version 23.6.0: Thu Sep 12 23:35:29 PDT 2024; root:xnu-10063.141.1.701.1~1/RELEASE_ARM64_T6000
Python Version: 3.10.10 (main, May 16 2023, 17:41:32) [Clang 14.0.3 (clang-1403.0.22.14.1)]

Package Information

langchain_core: 0.3.29
langchain: 0.3.14
langsmith: 0.2.10
langchain_openai: 0.3.0
langchain_text_splitters: 0.3.5

Optional packages not installed

langserve

Other Dependencies

aiohttp: 3.11.11
async-timeout: 4.0.3
httpx: 0.28.1
jsonpatch: 1.33
langsmith-pyo3: Installed. No version info available.
numpy: 1.26.4
openai: 1.59.7
orjson: 3.10.14
packaging: 24.2
pydantic: 2.10.5
PyYAML: 6.0.2
requests: 2.32.3
requests-toolbelt: 1.0.0
SQLAlchemy: 2.0.37
tenacity: 9.0.0
tiktoken: 0.8.0
typing-extensions: 4.12.2
zstandard: Installed. No version info available.

@langcarl langcarl bot added the investigate Flagged for investigation. label Jan 15, 2025
@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Jan 15, 2025
@dn-scribe
Copy link
Author

I further researched the issue, the following does work:
assistant = OpenAIAssistantRunnable(client=client, assistant_id=assistant_id,tools=self.tools, as_agent=True)

When using the as_agent parameter the RequiredActionFunctionToolCall is not returned.

You man reconsider if this is a bug. As a minimum, I'd recommend adding this use case to the documentation.

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 investigate Flagged for investigation.
Projects
None yet
Development

No branches or pull requests

1 participant