refactor: improve pretty_print method to enhance clarity and fixed print_on = True by default

pull/935/head
harshalmore31 4 weeks ago
parent 3ca109909a
commit c3e8ad99cb

@ -2787,18 +2787,22 @@ class Agent:
return self.role return self.role
def pretty_print(self, response: str, loop_count: int): def pretty_print(self, response: str, loop_count: int):
if self.print_on is False: """Pretty-print agent responses depending on user preferences.
if self.streaming_on is True:
# Skip printing here since real streaming is handled in call_llm Printing should occur when `self.print_on` is *True* (the default). We
# This avoids double printing when streaming_on=True also avoid double printing if real-time streaming is already enabled.
pass """
elif self.print_on is False:
pass # Only print if printing is enabled
else: if self.print_on:
# logger.info(f"Response: {response}") # Skip extra printing while streaming the streaming panel is
# already handled inside `call_llm`.
if self.streaming_on:
return
formatter.print_panel( formatter.print_panel(
f"{self.agent_name}: {response}", f"{self.agent_name}: {response}",
f"Agent Name {self.agent_name} [Max Loops: {loop_count} ]", f"Agent Name {self.agent_name} [Loop: {loop_count}]",
) )
def parse_llm_output(self, response: Any): def parse_llm_output(self, response: Any):
@ -2912,7 +2916,8 @@ class Agent:
# execute_tool_call_simple returns a string directly, not an object with content attribute # execute_tool_call_simple returns a string directly, not an object with content attribute
text_content = f"MCP Tool Response: \n\n {json.dumps(tool_response, indent=2)}" text_content = f"MCP Tool Response: \n\n {json.dumps(tool_response, indent=2)}"
if self.print_on is False: # Display tool output if printing is enabled
if self.print_on:
formatter.print_panel( formatter.print_panel(
text_content, text_content,
"MCP Tool Response: 🛠️", "MCP Tool Response: 🛠️",

Loading…
Cancel
Save