From dddcb40567553d2f557ca608595eee16e6c81ad9 Mon Sep 17 00:00:00 2001 From: Mery-Sanz Date: Wed, 30 Apr 2025 10:30:48 +0200 Subject: [PATCH] function tool time in stream true --- src/cai/cli.py | 11 ++--------- src/cai/tools/common.py | 8 ++++---- src/cai/util.py | 17 ----------------- 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/src/cai/cli.py b/src/cai/cli.py index 2444ac93..53c9ce05 100644 --- a/src/cai/cli.py +++ b/src/cai/cli.py @@ -134,13 +134,8 @@ load_dotenv() # set_default_openai_client(external_client) # Global variables for timing tracking -START_TIME = None # Track the start time of the current session -GLOBAL_START_TIME = time.time() # Track the start time of the entire CLI run -LAST_TOOL_TIME = None # Track the last time a tool was executed -ACTIVE_TIME = 0.0 # Track the time spent actively executing tools -IDLE_TIME = 0.0 # Track the time spent idle -LAST_STATE_CHANGE = None # Track when the state last changed between active and idle -IS_ACTIVE = False # Track if we're currently in an active state +global START_TIME +START_TIME = time.time() set_tracing_disabled(True) @@ -177,8 +172,6 @@ def run_cai_cli(starting_agent, context_variables=None, stream=False, max_turns= """ agent = starting_agent turn_count = 0 - global START_TIME - START_TIME = time.time() ACTIVE_TIME = 0 idle_time = 0 console = Console() diff --git a/src/cai/tools/common.py b/src/cai/tools/common.py index 8fd02bfc..7d5878d0 100644 --- a/src/cai/tools/common.py +++ b/src/cai/tools/common.py @@ -320,9 +320,9 @@ def _run_local_streamed(command, call_id, timeout=100, tool_name=None): header.append("(", style="yellow") header.append(args_str, style="yellow") header.append(")", style="yellow") - start_time = time.time() tool_time = 0 - total_time = START_TIME + start_time = time.time() + total_time = time.time() - START_TIME timing_info = [] if total_time: timing_info.append(f"Total: {format_time(total_time)}") @@ -330,7 +330,7 @@ def _run_local_streamed(command, call_id, timeout=100, tool_name=None): timing_info.append(f"Tool: {format_time(tool_time)}") if timing_info: header.append(f" [{' | '.join(timing_info)}]", style="cyan") - + content = Text() panel = Panel( @@ -358,7 +358,7 @@ def _run_local_streamed(command, call_id, timeout=100, tool_name=None): # Update tool_time and header with new timing info tool_time = time.time() - start_time - total_time = time.time() - start_time + tool_time + total_time = time.time() - START_TIME # Remove any previous timing info from header (rebuild header) timing_info = [] if total_time: diff --git a/src/cai/util.py b/src/cai/util.py index e7a64e1c..ca0af158 100644 --- a/src/cai/util.py +++ b/src/cai/util.py @@ -1366,23 +1366,6 @@ def cli_print_tool_output(tool_name="", args="", output="", call_id=None, execut args_str = ", ".join(arg_parts) else: args_str = str(args) - - # Helper function to format time in a human-readable way - def format_time(seconds): - if seconds is None: - return "N/A" - - if seconds < 60: - return f"{seconds:.1f}s" - elif seconds < 3600: - minutes = int(seconds / 60) - seconds_remainder = seconds % 60 - return f"{minutes}m {seconds_remainder:.1f}s" - else: - hours = int(seconds / 3600) - minutes = int((seconds % 3600) / 60) - return f"{hours}h {minutes}m" - # Get session timing information try: from cai.cli import START_TIME