Skip to content

Commit 62f732e

Browse files
docs(callbacks): clarify Python callback parameter names (#1727)
* docs(callbacks): clarify Python parameter names * Make callback parameter name warning collapsible, add full parameter reference table --------- Co-authored-by: Kristopher Overholt <koverholt@google.com>
1 parent 4df2ba7 commit 62f732e

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

docs/callbacks/types-of-callbacks.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,33 @@ These callbacks are available on *any* agent that inherits from `BaseAgent` (inc
1313
!!! Note
1414
The specific method names or return types may vary slightly by SDK language (e.g., return `None` in Python, return `Optional.empty()` or `Maybe.empty()` in Java). Refer to the language-specific API documentation for details.
1515

16+
??? warning "Python: Use the documented callback parameter names"
17+
18+
In Python, callback function parameter names must match the documented
19+
names exactly because ADK passes callback arguments by keyword. For example,
20+
use `callback_context` for agent and model callbacks, and `tool_context` for
21+
tool callbacks. Renaming these parameters to aliases such as `ctx` will cause
22+
runtime `TypeError` failures.
23+
24+
```python
25+
# Correct
26+
def before_agent_callback(callback_context):
27+
...
28+
29+
# Incorrect
30+
def before_agent_callback(ctx):
31+
...
32+
```
33+
34+
| Callback | Required parameter names |
35+
|---|---|
36+
| `before_agent_callback` | `callback_context` |
37+
| `after_agent_callback` | `callback_context` |
38+
| `before_model_callback` | `callback_context`, `llm_request` |
39+
| `after_model_callback` | `callback_context`, `llm_response` |
40+
| `before_tool_callback` | `tool`, `args`, `tool_context` |
41+
| `after_tool_callback` | `tool`, `args`, `tool_context`, `tool_response` |
42+
1643
### Before Agent Callback
1744

1845
**When:** Called *immediately before* the agent's `_run_async_impl` (or `_run_live_impl`) method is executed. It runs after the agent's `InvocationContext` is created but *before* its core logic begins.

0 commit comments

Comments
 (0)