""" Integration test for the Small Moments agent with a self-reflection loop using a local Ollama setup. This test exercises the LangGraph flow built in tasks T003.3, T003.4, and T004.3. The exepcted behavior is for the call_llm node to produce an initial bad response, the call_supervisor node scores the response as "bad" and provides feedback for improvement, and it loops back to the call_llm node, which now produces a proper response based on the feedback provided by the supervisor. To run this test, enter the following code in the terminal: .venv/bin/pip install pytest (if not already installed) .venv/bin/pip install ollama (if not already installed) PYTHONPATH=src pytest tests/test_reflection_loop.py -q -s """ from walkxr_ai.agents.small_moments_roleplay_agent import SmallMomentsRoleplayAgent def test_roleplay_agent() -> None: # Instantiate the agent # Initializes persona/retrieval engine/Ollama model and builds LangGraph initial state agent = SmallMomentsRoleplayAgent() # Pass deliberately bad LLM response bad_response_test = "LOL that sucks" # Run the LangGraph flow and print the final response result = agent.get_response( user_input="Hello, I am feeling a little nervous today.", history=[], user_id="test_user", session_id="test_session", stage="conversation", debug_print=True, bad_response_test=bad_response_test ) print() print(result) # Basic assertions to verify the structure of the response assert isinstance(result, dict) # Is the result a dictionary? assert "debug" in result # Does the debug info exist? assert isinstance(result["debug"], dict) # Is the debug info a dictionary? assert result["debug"].get("error") is None # Do any errors occur? assert "response_text" in result # Does the response exist? assert isinstance(result["response_text"], str) # Is the response text a string? assert result["response_text"].strip() # Is the response non-empty?