diff --git a/src/cai/sdk/agents/models/openai_chatcompletions.py b/src/cai/sdk/agents/models/openai_chatcompletions.py index 04de9fa8..7d439481 100644 --- a/src/cai/sdk/agents/models/openai_chatcompletions.py +++ b/src/cai/sdk/agents/models/openai_chatcompletions.py @@ -373,6 +373,7 @@ class OpenAIChatCompletionsModel(Model): # Add a placeholder response for any tool call generated during this interaction # We don't know the actual tool calls, so we'll use what we know from timing # Any tool call that was generated within the last 5 seconds is likely from this interaction + import time current_time = time.time() for call_id, call_info in list(_Converter.recent_tool_calls.items()): if 'start_time' in call_info and (current_time - call_info['start_time']) < 5.0: diff --git a/src/cai/util.py b/src/cai/util.py index 5edb55f1..98b95150 100644 --- a/src/cai/util.py +++ b/src/cai/util.py @@ -2443,6 +2443,42 @@ def _create_tool_panel_content(tool_name, args, output, execution_info=None, tok # Fallback if syntax highlighting fails, just add raw output group_content.extend([Text("\n"), Text(output)]) + # Fallback for other tools to display their output if not handled above + elif output and output.strip(): # Check if output is not None and not just whitespace + output_lang_name = "text" + try: + # Attempt to parse as JSON to infer language + json.loads(output) + output_lang_name = "json" + except json.JSONDecodeError: + # Basic check for XML-like content if not JSON + if output.strip().startswith("<") and output.strip().endswith(">"): + output_lang_name = "xml" + # Add more detections for other types (e.g., YAML) if needed + + # Use get_language_from_code_block for consistent language mapping + syntax_lang = get_language_from_code_block(output_lang_name) + + output_syntax = Syntax( + output, + syntax_lang, + theme="monokai", + background_color="#272822", # Consistent theme + word_wrap=True, + line_numbers=True, # Usually helpful for structured output + indent_guides=True + ) + + output_display_panel = Panel( + output_syntax, + title="Tool Output", # Generic title + border_style="green", # Consistent + title_align="left", + box=ROUNDED, + padding=(0, 1) + ) + group_content.extend([Text("\n"), output_display_panel]) + # Add token info if available if token_content: group_content.extend([Text("\n"), token_content])