Sometimes the Langchain Agent entering the custom tool with the input: "Invalid or incomplete response"
Even if the LLM seems to use the tool correctly.
Any idea why and how to fix that ?
I would point out that sometimes everything works as expected.
My tool:
@tool
def saveEvent(event: str) -> str:
"""Use it to save an event in my calendar. \
The input should be a VCALENDAR string and be formated as follow:
'''
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
SUMMARY: ```the name of the event in french if you don't know the name, create one limited to 10 words```
DESCRIPTION: ```Description of the event in french, if you don't know the description, summarize the message```
DTSTART: ```Start date of the event, use the paris timezone and format as follow: AAAAMMJJDhhmmssZ```
DTEND: ```End date of the event use the paris timezone and format as follow: AAAAMMJJDhhmmssZ```
LOCATION: ```the location of the event```
CATEGORIES: ```the categories of the event```
END:VEVENT
END:VCALENDAR
'''
This function will return 'OK' if the event is correctlly saved or 'ERROR' if there is an error."""
resp = calendar.save_event(event)
if resp:
return 'OK'
else:
return 'ERROR'
The agent:
tools = load_tools(['python_repl'], llm=llm)
agent= initialize_agent(
tools + [saveEvent],
llm,
agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
handle_parsing_errors=True,
max_iterations=3,
verbose = True)
messages = agent_prompt_template.format_prompt(text=message)
response = agent(messages.to_string())
The console output:
[llm/end] [1:chain:AgentExecutor > 2:chain:LLMChain > 3:llm:GPTLLM] [10.44s] Exiting LLM run with output:
{
"generations": [
[
{
"text": "Thought: I need to format the event information provided in the JSON into a VCALENDAR string according to the given template. Once I have the formatted event, I can use the 'saveEvent' tool to add it to the calendar.\n\nAction:\n```json\n{\n \"action\": \"saveEvent\",\n \"action_input\": \"BEGIN:VCALENDAR\\nVERSION:2.0\\nBEGIN:VEVENT\\nSUMMARY:Festival ForroDiois\\nDESCRIPTION:Marilia Cervi est une des trois prof invités au Festival ForroDiois. Elle partagera sa danse avec nous le samedi 17 juin et dimanches 18 juin (3 cours de 1h30 chacun).\\nDTSTART:20230617T000000Z\\nDTEND:20230617T020000Z\\nLOCATION:Non spécifié\\nCATEGORIES:danse,festival\\nEND:VEVENT\\nEND:VCALENDAR\"\n}\n```\n\n",
"generation_info": null
}
]
],
"llm_output": null,
"run": null
}
[chain/end] [1:chain:AgentExecutor > 2:chain:LLMChain] [10.44s] Exiting Chain run with output:
{
"text": "Thought: I need to format the event information provided in the JSON into a VCALENDAR string according to the given template. Once I have the formatted event, I can use the 'saveEvent' tool to add it to the calendar.\n\nAction:\n```json\n{\n \"action\": \"saveEvent\",\n \"action_input\": \"BEGIN:VCALENDAR\\nVERSION:2.0\\nBEGIN:VEVENT\\nSUMMARY:Festival ForroDiois\\nDESCRIPTION:Marilia Cervi est une des trois prof invités au Festival ForroDiois. Elle partagera sa danse avec nous le samedi 17 juin et dimanches 18 juin (3 cours de 1h30 chacun).\\nDTSTART:20230617T000000Z\\nDTEND:20230617T020000Z\\nLOCATION:Non spécifié\\nCATEGORIES:danse,festival\\nEND:VEVENT\\nEND:VCALENDAR\"\n}\n```\n\n"
}
[tool/start] [1:chain:AgentExecutor > 4:tool:_Exception] Entering Tool run with input:
"Invalid or incomplete response"
[tool/end] [1:chain:AgentExecutor > 4:tool:_Exception] [0.111ms] Exiting Tool run with output:
"Invalid or incomplete response"