Pretty-print turns, tool calls, and token totals to stdout.
(trajectory)
| 82 | |
| 83 | |
| 84 | def print_trajectory(trajectory) -> None: |
| 85 | """Pretty-print turns, tool calls, and token totals to stdout.""" |
| 86 | print(f"\n{HR}") |
| 87 | print(" Trace") |
| 88 | print(HR) |
| 89 | for turn in trajectory.turns: |
| 90 | print( |
| 91 | f"\n [Turn {turn.index}] " |
| 92 | f"in={turn.input_tokens} out={turn.output_tokens} tokens" |
| 93 | ) |
| 94 | if turn.text: |
| 95 | snippet = turn.text[:200] + ("..." if len(turn.text) > 200 else "") |
| 96 | print(f" text: {snippet}") |
| 97 | for tc in turn.tool_calls: |
| 98 | print(f" tool: {tc.name} input: {tc.input}") |
| 99 | if tc.output is not None: |
| 100 | out_str = str(tc.output) |
| 101 | snippet = out_str[:200] + ("..." if len(out_str) > 200 else "") |
| 102 | print(f" output: {snippet}") |
| 103 | print( |
| 104 | f"\n Total: {trajectory.total_input_tokens} input / " |
| 105 | f"{trajectory.total_output_tokens} output tokens " |
| 106 | f"({len(trajectory.turns)} turns, " |
| 107 | f"{len(trajectory.all_tool_calls)} tool calls)" |
| 108 | ) |
| 109 | |
| 110 | |
| 111 | def print_answer(answer: str) -> None: |