Skip to content

docs(callbacks): correct Python callback signatures and return types - #2016

Open
GWeale wants to merge 2 commits into
google:mainfrom
GWeale:docs-audit-callbacks
Open

docs(callbacks): correct Python callback signatures and return types#2016
GWeale wants to merge 2 commits into
google:mainfrom
GWeale:docs-audit-callbacks

Conversation

@GWeale

@GWeale GWeale commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

The callback pages (plus the callback examples in the safety guide) described Java/Kotlin shapes as if they were Python, and one example used a signature the framework never calls.

Changes

  • docs/safety/index.md — the before_tool_callback example took a leading callback_context parameter; ADK invokes before-tool hooks with (tool, args, tool_context), so registering that function as written raises TypeError. Parameter dropped and state read off tool_context.state, which also replaces the tool_context.invocation_context.session.state chain in two nearby snippets.
  • docs/callbacks/index.md — the return-value section gave Kotlin's CallbackChoice.Continue(...) / Break(...) and Java's Map<String, Any> as the Python contract; it now says None, Content, LlmResponse, and dict.
  • docs/callbacks/types-of-callbacks.mdon_model_error_callback and on_tool_error_callback were undocumented; added with their arguments and their exception-suppression behavior. Also notes that every callback field accepts a list (invoked in order, first truthy return wins), that a callback may be def or async def, and that after_tool_callback receives the tool's raw return value — the {"result": ...} wrap happens after the callback runs, so a tool annotated -> str hands the callback a str.
  • docs/callbacks/design-patterns-and-best-practices.mdsave_artifact / load_artifact were shown without await; "callbacks execute synchronously" reworded to say the loop waits for each one and awaits async def callbacks; the "use the correct context type" advice now notes the two Python names are aliases of the same class.

How this was produced

Part of a page-by-page audit of the Python docs against the google/adk-python v2.5.0 source: every import resolved against a real 2.5.0 install, every constructor kwarg checked against model_fields / inspect.signature, every documented default read off the field. A second independent pass re-derived each claim from source rather than trusting the finding, and a third conformed the new wording to the surrounding pages. mkdocs build --strict is clean.

Only Python tabs and language-neutral prose were touched — this audit had no ground truth for the Go / Java / TypeScript SDKs.

Split out of a larger audit branch so each area can be reviewed on its own.

@netlify

netlify Bot commented Jul 28, 2026

Copy link
Copy Markdown

Deploy Preview for adk-docs-preview ready!

Name Link
🔨 Latest commit 631e757
🔍 Latest deploy log https://app.netlify.com/projects/adk-docs-preview/deploys/6a6a9989162dec00088531e9
😎 Deploy Preview https://deploy-preview-2016--adk-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant