From e12f570ead16547b0dee11f61ea429d8a79d4f5d Mon Sep 17 00:00:00 2001 From: Mohammad Mohtashim <45242107+keenborder786@users.noreply.github.com> Date: Tue, 1 Oct 2024 00:54:51 +0500 Subject: [PATCH] Merge pull request #26794 * [chore]: Agent Observation should be casted to string to avoid errors * Merge branch 'master' into fix_observation_type_streaming * [chore]: Using Json.dumps * [chore]: Exact same logic as when casting agent oobservation to string --- libs/core/langchain_core/agents.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libs/core/langchain_core/agents.py b/libs/core/langchain_core/agents.py index 39393317473..6e8cdc975eb 100644 --- a/libs/core/langchain_core/agents.py +++ b/libs/core/langchain_core/agents.py @@ -189,10 +189,17 @@ def _convert_agent_observation_to_messages( Returns: AIMessage that corresponds to the original tool invocation. """ + if isinstance(agent_action, AgentActionMessageLog): return [_create_function_message(agent_action, observation)] else: - return [HumanMessage(content=observation)] + content = observation + if not isinstance(observation, str): + try: + content = json.dumps(observation, ensure_ascii=False) + except Exception: + content = str(observation) + return [HumanMessage(content=content)] def _create_function_message(