MCPcopy Index your code
hub / github.com/google/adk-python / callback

Function callback

contributing/samples/mcp/mcp_progress_callback_agent/agent.py:109–129  ·  view source on GitHub ↗
(
      progress: float,
      total: float | None,
      message: str | None,
  )

Source from the content-addressed store, hash-verified

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

Calls

no outgoing calls

Tested by 1

test_create_callbackMethod · 0.40