langchain/libs/core/langchain_core/tools
Qun 033ac41760
fix crash when using create_xml_agent with parameterless function as … (#26002)
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](https://github.com/langchain-ai/langchain/blob/master/libs/core/langchain_core/tools/base.py#L419)
```python
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(......)
```

---------

Co-authored-by: Erick Friis <erick@langchain.dev>
Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
Co-authored-by: Chester Curme <chester.curme@gmail.com>
2024-12-19 13:00:46 -05:00
..
__init__.py core[patch]: export InjectedToolCallId (#28772) 2024-12-17 19:29:20 +00:00
base.py fix crash when using create_xml_agent with parameterless function as … (#26002) 2024-12-19 13:00:46 -05:00
convert.py core[patch]: Improve type checking for the tool decorator (#27460) 2024-10-29 13:59:56 +00:00
render.py core: Put Python version as a project requirement so it is considered by ruff (#26608) 2024-09-18 14:37:57 +00:00
retriever.py multiple: pydantic 2 compatibility, v0.3 (#26443) 2024-09-13 14:38:45 -07:00
simple.py core[patch]: return ToolMessage from tool (#28605) 2024-12-10 09:59:38 +00:00
structured.py core: Add ruff rules for error messages (EM) (#26965) 2024-10-07 22:12:28 +00:00