Print session statistics
(agent: Agent, session_start: datetime)
| 259 | |
| 260 | |
| 261 | def print_stats(agent: Agent, session_start: datetime): |
| 262 | """Print session statistics""" |
| 263 | duration = datetime.now() - session_start |
| 264 | hours, remainder = divmod(int(duration.total_seconds()), 3600) |
| 265 | minutes, seconds = divmod(remainder, 60) |
| 266 | |
| 267 | # Count different types of messages |
| 268 | user_msgs = sum(1 for m in agent.messages if m.role == "user") |
| 269 | assistant_msgs = sum(1 for m in agent.messages if m.role == "assistant") |
| 270 | tool_msgs = sum(1 for m in agent.messages if m.role == "tool") |
| 271 | |
| 272 | print(f"\n{Colors.BOLD}{Colors.BRIGHT_CYAN}Session Statistics:{Colors.RESET}") |
| 273 | print(f"{Colors.DIM}{'─' * 40}{Colors.RESET}") |
| 274 | print(f" Session Duration: {hours:02d}:{minutes:02d}:{seconds:02d}") |
| 275 | print(f" Total Messages: {len(agent.messages)}") |
| 276 | print(f" - User Messages: {Colors.BRIGHT_GREEN}{user_msgs}{Colors.RESET}") |
| 277 | print(f" - Assistant Replies: {Colors.BRIGHT_BLUE}{assistant_msgs}{Colors.RESET}") |
| 278 | print(f" - Tool Calls: {Colors.BRIGHT_YELLOW}{tool_msgs}{Colors.RESET}") |
| 279 | print(f" Available Tools: {len(agent.tools)}") |
| 280 | if agent.api_total_tokens > 0: |
| 281 | print(f" API Tokens Used: {Colors.BRIGHT_MAGENTA}{agent.api_total_tokens:,}{Colors.RESET}") |
| 282 | print(f"{Colors.DIM}{'─' * 40}{Colors.RESET}\n") |
| 283 | |
| 284 | |
| 285 | def parse_args() -> argparse.Namespace: |