From e7ef1c64c55ce004d4196fa7f425c38cef7e6160 Mon Sep 17 00:00:00 2001 From: sharath <29162020+tnfssc@users.noreply.github.com> Date: Mon, 16 Jun 2025 09:07:47 +0000 Subject: [PATCH 1/2] fix(thread_manager): enhance message content parsing and ensure proper compression of prepared messages --- backend/agentpress/thread_manager.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/agentpress/thread_manager.py b/backend/agentpress/thread_manager.py index 8a120f0b..e2f21f66 100644 --- a/backend/agentpress/thread_manager.py +++ b/backend/agentpress/thread_manager.py @@ -172,6 +172,10 @@ class ThreadManager: result: List[Dict[str, Any]] = [] for msg in messages: msg_content = msg.get('content') + # Try to parse msg_content as JSON if it's a string + if isinstance(msg_content, str): + try: msg_content = json.loads(msg_content) + except json.JSONDecodeError: pass if isinstance(msg_content, dict): # Create a copy to avoid modifying the original msg_content_copy = msg_content.copy() @@ -495,7 +499,7 @@ Here are the XML tools available with examples: openapi_tool_schemas = self.tool_registry.get_openapi_schemas() logger.debug(f"Retrieved {len(openapi_tool_schemas) if openapi_tool_schemas else 0} OpenAPI tool schemas") - prepared_messages = self._compress_messages(prepared_messages, llm_model) + prepared_messages = self._compress_messages(json.loads(json.dumps(prepared_messages)), llm_model) # 5. Make LLM API call logger.debug("Making LLM API call") From 85cb4b032ba614d1cfc665bccc418d9de824d50e Mon Sep 17 00:00:00 2001 From: Sharath <29162020+tnfssc@users.noreply.github.com> Date: Mon, 16 Jun 2025 14:39:13 +0530 Subject: [PATCH 2/2] Update backend/agentpress/thread_manager.py --- backend/agentpress/thread_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/agentpress/thread_manager.py b/backend/agentpress/thread_manager.py index e2f21f66..66c6f8c6 100644 --- a/backend/agentpress/thread_manager.py +++ b/backend/agentpress/thread_manager.py @@ -499,7 +499,7 @@ Here are the XML tools available with examples: openapi_tool_schemas = self.tool_registry.get_openapi_schemas() logger.debug(f"Retrieved {len(openapi_tool_schemas) if openapi_tool_schemas else 0} OpenAPI tool schemas") - prepared_messages = self._compress_messages(json.loads(json.dumps(prepared_messages)), llm_model) + prepared_messages = self._compress_messages(prepared_messages, llm_model) # 5. Make LLM API call logger.debug("Making LLM API call")