From ea037e1bff3065145d63d07bf96a499ea7127849 Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman Date: Mon, 7 Jul 2025 22:40:03 +0000 Subject: [PATCH] refactor: update logging and error handling in LLMAgent and TemplateRenderer --- src/cleveragents/agents/llm.py | 2 +- src/cleveragents/templates/renderer.py | 6 ++---- tests/features/steps/llm_agent_detailed_steps.py | 8 ++++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/cleveragents/agents/llm.py b/src/cleveragents/agents/llm.py index 40ab9c90..75c58193 100644 --- a/src/cleveragents/agents/llm.py +++ b/src/cleveragents/agents/llm.py @@ -222,7 +222,7 @@ class LLMAgent(AgentWithMemory): } pretty_context = pprint.pformat(display_context, indent=2) logger.debug( - f"--- LLMAgent '{self.name}' render context ---\n{pretty_context}" + f"--- LLMAgent '{self.name}' final render context ---\n{pretty_context}" ) # --- END: ADDED FOR DEBUGGING --- diff --git a/src/cleveragents/templates/renderer.py b/src/cleveragents/templates/renderer.py index 452790d5..d913f22a 100644 --- a/src/cleveragents/templates/renderer.py +++ b/src/cleveragents/templates/renderer.py @@ -252,11 +252,9 @@ class TemplateRenderer: else: raise TemplateError(f"Unsupported template engine: {self.engine_type}") except Exception as e: - desc = ( - source_description or f"string starting with: '{template_str[:40]}...'" - ) + desc = f" for {source_description}" if source_description else "" raise TemplateError( - f"Failed to render template for {desc}: {str(e)}" + f"Failed to render template string{desc}: {str(e)}" ) from e def get_template(self, name: str) -> str: diff --git a/tests/features/steps/llm_agent_detailed_steps.py b/tests/features/steps/llm_agent_detailed_steps.py index d32c98d8..c9c1b4cb 100644 --- a/tests/features/steps/llm_agent_detailed_steps.py +++ b/tests/features/steps/llm_agent_detailed_steps.py @@ -325,8 +325,8 @@ def step_impl(context): ) original_process_response = context.agent.process_response - def mock_process_response(response): - context.processed_response = original_process_response(response) + def mock_process_response(response, ctx=None): + context.processed_response = original_process_response(response, ctx) return context.processed_response context.agent.process_response = mock_process_response @@ -353,8 +353,8 @@ def step_impl(context): ) original_process_response = context.agent.process_response - def mock_process_response(response): - context.processed_response = original_process_response(response) + def mock_process_response(response, ctx=None): + context.processed_response = original_process_response(response, ctx) return context.processed_response context.agent.process_response = mock_process_response