function tool time in stream true

This commit is contained in:
Mery-Sanz 2025-04-30 10:30:48 +02:00
parent 0cfa72bcf5
commit dddcb40567
3 changed files with 6 additions and 30 deletions

View File

@ -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()

View File

@ -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:

View File

@ -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