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

fix crash when using create_xml_agent with parameterless function as … #26002

Merged
merged 6 commits into from
Dec 19, 2024

Conversation

QunBB
Copy link
Contributor

@QunBB QunBB commented Sep 3, 2024

When using create_xml_agent or create_json_chat_agent to create a agent, and the function corresponding to the tool is a parameterless function, the XMLAgentOutputParser or JSONAgentOutputParser will parse the tool input into an empty string, BaseTool will parse it into a positional argument.
So, the program will crash finally because we invoke a parameterless function but with a positional argument.Specially, below code will raise StopIteration in _parse_input

from langchain import hub
from langchain.agents import AgentExecutor, create_json_chat_agent, create_xml_agent
from langchain_openai import ChatOpenAI

prompt = hub.pull("hwchase17/react-chat-json")

llm = ChatOpenAI()

# agent = create_xml_agent(llm, tools, prompt)
agent = create_json_chat_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

agent_executor.invoke(......)

Copy link

vercel bot commented Sep 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Dec 19, 2024 5:52pm

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. Ɑ: core Related to langchain-core 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Sep 3, 2024
@QunBB
Copy link
Contributor Author

QunBB commented Sep 3, 2024

@baskaryan I have added unit tests for the related pull request, please check it again.
The unit tests should raise StopIteration similarly with current code, as I mentioned above.So i think my code could be merged.

@efriis
Copy link
Member

efriis commented Sep 7, 2024

overall I think this looks good - as a heads up we're charging towards a 0.3 release right now, so core is in code freeze until that goes out

Will mark to review after 0.3 is out!

@dosubot dosubot bot added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label Dec 19, 2024
@ccurme ccurme merged commit 033ac41 into langchain-ai:master Dec 19, 2024
82 checks passed
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 Ɑ: core Related to langchain-core lgtm PR looks good. Use to confirm that a PR is ready for merging. size:S This PR changes 10-29 lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants