Skip to content

Document that callback parameter names must match exactly (e.g., callback_context, not ctx) #1205

@irskid5

Description

@irskid5

Summary

The callback documentation shows examples with specific parameter names like callback_context and llm_request, but doesn't explicitly state that these exact names are required. Users may assume they can use any parameter name (e.g., ctx instead of callback_context), leading to confusing runtime errors.

Problem

When defining a callback with a different parameter name:

async def my_callback(ctx: CallbackContext) -> Optional[types.Content]:
    # ...

The callback fails at runtime with:

TypeError: my_callback() got an unexpected keyword argument 'callback_context'

This happens because ADK invokes callbacks using keyword arguments:

callback(callback_context=callback_context, llm_request=llm_request)

Expected Behavior

The documentation should explicitly state that callback parameter names must match the expected names exactly, such as:

  • callback_context (not ctx, context, etc.)
  • llm_request / llm_response
  • tool, args, tool_context, tool_response

Suggested Fix

Add a note to the Callbacks documentation or Types of Callbacks page, such as:

Important: Callback parameter names must match exactly as shown in the examples. ADK invokes callbacks using keyword arguments, so using different parameter names (e.g., ctx instead of callback_context) will result in a TypeError.

Affected Pages

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions