You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The error you're encountering, "TypeError: Object of type AgentAction is not JSON serializable", is due to the fact that Python's built-in json.dumps() function doesn't know how to serialize the AgentAction object. It only knows how to serialize basic data types like dict, list, str, int, float, bool, None.
However, LangChain provides a dumps function in the dump.py file that can be used to serialize objects. This function uses a default function that checks if the object is an instance of the Serializable class and if so, calls the to_json method of the object. If the object is not an instance of Serializable, it calls the to_json_not_implemented function.
This code will convert the AgentAction object and any other objects in the intermediate_steps into a JSON format that can be printed. If the object is an instance of Serializable, its to_json method will be called. If not, the to_json_not_implemented function will be called.
You can find more information about this in the following sources:
This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
System Info
version 0.0.253
Running on a Jupyter Notebook in Google Colab
Who can help?
No response
Information
Related Components
Reproduction
Follow the steps in Access Intermediate Steps within the Agent "How To".
The final step calls for
print(json.dumps(response["intermediate_steps"], indent=2))
This is throwing the following error:
TypeError: Object of type AgentAction is not JSON serializable
Based on this issue I think it may be happening following a recent upgrade.
Expected behavior
Printing the intermediate steps as JSON.
The text was updated successfully, but these errors were encountered: