diff --git a/src/crewai/cli/crew_chat.py b/src/crewai/cli/crew_chat.py index 1b4e18c78..a0f8b23f6 100644 --- a/src/crewai/cli/crew_chat.py +++ b/src/crewai/cli/crew_chat.py @@ -246,7 +246,7 @@ def handle_user_input( available_functions=available_functions, ) - messages.append({"role": "assistant", "content": final_response}) + messages.append({"role": "assistant", "content": str(final_response)}) click.secho(f"\nAssistant: {final_response}\n", fg="green") diff --git a/src/crewai/utilities/reasoning_handler.py b/src/crewai/utilities/reasoning_handler.py index cb94eb38a..3a2f7b8bb 100644 --- a/src/crewai/utilities/reasoning_handler.py +++ b/src/crewai/utilities/reasoning_handler.py @@ -260,14 +260,22 @@ class AgentReasoning: available_functions={"create_reasoning_plan": _create_reasoning_plan}, ) - self.logger.debug(f"Function calling response: {response[:100]}...") - - try: - result = json.loads(response) - if "plan" in result and "ready" in result: - return result["plan"], result["ready"] - except (json.JSONDecodeError, KeyError): - pass + if isinstance(response, dict): + response_str = str(response) + self.logger.debug(f"Function calling response: {response_str[:100]}...") + + if "plan" in response and "ready" in response: + return response["plan"], response["ready"] + else: + response_str = str(response) + self.logger.debug(f"Function calling response: {response_str[:100]}...") + + try: + result = json.loads(response_str) + if "plan" in result and "ready" in result: + return result["plan"], result["ready"] + except (json.JSONDecodeError, KeyError): + pass response_str = str(response) return response_str, "READY: I am ready to execute the task." in response_str diff --git a/tests/task_test.py b/tests/task_test.py index 89fa3c53c..b1c44a8f6 100644 --- a/tests/task_test.py +++ b/tests/task_test.py @@ -162,6 +162,7 @@ def test_task_callback_returns_task_output(): "name": None, "expected_output": "Bullet point list of 5 interesting ideas.", "output_format": OutputFormat.RAW, + "completion_metadata": None, } assert output_dict == expected_output diff --git a/tests/test_integration_llm_features.py b/tests/test_integration_llm_features.py index b19f8877b..9e9849599 100644 --- a/tests/test_integration_llm_features.py +++ b/tests/test_integration_llm_features.py @@ -79,7 +79,7 @@ class TestIntegrationLLMFeatures: result = lite_agent.kickoff("Analyze this problem") - thinking_content = extract_xml_content(result.raw, "thinking") + thinking_content = extract_xml_content(result, "thinking") assert thinking_content is not None assert "step by step" in thinking_content assert "requirements" in thinking_content