(
progress: float,
total: float | None,
message: str | None,
)
| 107 | session_id = callback_context.session.id |
| 108 | |
| 109 | async def callback( |
| 110 | progress: float, |
| 111 | total: float | None, |
| 112 | message: str | None, |
| 113 | ) -> None: |
| 114 | # Include tool name and session info in the progress output |
| 115 | prefix = f"[{tool_name}][session:{session_id}]" |
| 116 | if total is not None: |
| 117 | percentage = (progress / total) * 100 |
| 118 | bar_length = 20 |
| 119 | filled = int(bar_length * progress / total) |
| 120 | bar = "=" * filled + "-" * (bar_length - filled) |
| 121 | print(f"{prefix} [{bar}] {percentage:.0f}% {message or ''}") |
| 122 | # Example: Store progress in state (callback_context allows modification) |
| 123 | if callback_context: |
| 124 | callback_context.state["last_progress"] = progress |
| 125 | callback_context.state["last_total"] = total |
| 126 | else: |
| 127 | print( |
| 128 | f"{prefix} Progress: {progress} {f'- {message}' if message else ''}" |
| 129 | ) |
| 130 | |
| 131 | return callback |
| 132 |
no outgoing calls