Fix code samples that do not compile against the shipped SDKs - #2194
Open
GWeale wants to merge 4 commits into
Open
Fix code samples that do not compile against the shipped SDKs#2194GWeale wants to merge 4 commits into
GWeale wants to merge 4 commits into
Conversation
Checked the code samples against the real published libraries and corrected what does not compile or resolve. Verified against google-adk 2.8.0 for Python, @google/adk 2.0.0 for TypeScript, google-adk 1.6.0 for Java, adk-kotlin 0.8.0 for Kotlin, and adk/v2 2.3.0 for Go. Go: tool.Context does not exist in the v2 line and never has. The type is agent.Context, which this repository's own Go examples already use. Nine sites. Four import blocks also omitted the fmt they call. Java: two imports naming packages that do not exist, com.google.adk.agent (the package is agents) and com.google.adk.agents.Content (it is a genai type). Four wrong types, each confirmed against the jar with javap: EventActions.stateDelta returns Map not ConcurrentMap, artifactDelta returns Map<String, Integer> rather than ConcurrentMap<String, Part>, FunctionResponse.response yields Map<String, Object>, and loadArtifact takes the version as an int so the Optional argument matched no overload. Python: four coroutines used without await, which also masked a SearchMemoryResponse.results field that does not exist. The field is memories, holding MemoryEntry objects; the TypeScript and Java tabs of the same example had the same mistake. Also CodeExecutionInput imported from the wrong module, a calendar_tool_set object that does not exist in place of CalendarToolset, two positional Part.from_text calls against a keyword-only signature, five LlmAgent samples missing the required name, and an external access token sample built on an enum member and a field that the package does not define. Also corrects samples that could not parse at all: an unindented plugin class body, bracket and text block typos, a truncated call, an await in a non-async function, an await dedented out of the condition meant to guard it, a mid-file Java import, and a fence that opened at six spaces and closed at eight, which made a page render a literal code fence as body text.
code_workflow yields, which makes it an async generator, and returning a value from one is a syntax error. A generator node conveys its result by yielding an event whose output the runner copies to the context, which is the form the data handling page already uses.
This was referenced Sep 2, 2026
joefernandez
reviewed
Sep 3, 2026
| ``` | ||
|
|
||
| #### Use Google API toolsets (e.g., `calendar_tool_set`) | ||
| #### Use Google API toolsets (e.g., `CalendarToolset`) |
Collaborator
There was a problem hiding this comment.
simplify heading: don't use parenthesis, "e.g.," and avoid code syntax in headings
Suggested change
| #### Use Google API toolsets (e.g., `CalendarToolset`) | |
| #### Use Google API toolsets |
joefernandez
approved these changes
Sep 3, 2026
joefernandez
left a comment
Collaborator
There was a problem hiding this comment.
Approved. Please resolve conflicts for Live content.
These pages where rewritten in:
#2086
The three Live pages this branch touched (dev-guide/part3.md, dev-guide/part5.md, streaming-tools.md) were deleted by google#2086, which decomposed the dev guide. Their fixes are already handled on main: the InvocationContext and custom-Gemini examples no longer exist, the play_audio indentation is correct in all three successor pages, and live/tools.md already passes text= to Part.from_text.
Drop the parenthetical class lists from the two toolset headings in the authentication page. Nothing links to either anchor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this is
Code samples across the docs were checked against the real published library
for each language, and this corrects what does not compile or resolve. 21 files.
Nothing was executed. The samples call live Gemini and Vertex endpoints, so
every check is static: parsing, symbol resolution, and compilation or type
checking against the real artifacts.
Verified against
google-adk[all]2.8.0@google/adk2.0.0google-adk1.6.0examples/java/snippets/pom.xmladk-kotlin0.8.0examples/kotlin/build.gradle.ktsgoogle.golang.org/adk/v22.3.0mkdocs build --strictpasses. 21 rendered pages change, each matching anedited source file. Tab structure and code-fence rendering were compared
against
mainpage by page, because the strict build does not detect a codeblock that falls out of its tab.
Go:
tool.Contextdoes not existNine sites across six pages declared tool and callback functions taking
ctx tool.Context. Thetoolpackage has noContexttype — not in 2.3.0,and not in 2.0.0, which is what
examples/go/go.modpins, so this was nevervalid in the v2 line.
The type is
agent.Context, which carries exactly the surface these samplesuse:
Actions(),State(),Artifacts(),FunctionCallID(),SearchMemory(). This repository's own Go examples already usectx agent.Context45 times.Two import blocks were adjusted to match, and four others in
docs/context/index.mdomitted thefmtthey call.Java: two impossible imports and four wrong types
com.google.adk.agent.LlmAgent— the package isagents, plural.com.google.adk.agents.Content—Contentis a genai type.Four type errors, each confirmed with
javapagainst the 1.6.0 jar:EventActions.stateDelta()returnsMap, notConcurrentMap.EventActions.artifactDelta()returnsMap<String, Integer>, mappingfilename to version number. The docs declared
ConcurrentMap<String, Part>,wrong in both the map type and the value type.
FunctionResponse.response()yieldsMap<String, Object>, notMap<String, String>.BaseArtifactService.loadArtifacttakes the version as anintor omits it;the docs passed
Optional.empty()andOptional.of(0), matching no overload.Python: coroutines used without await, and a field that does not exist
search_memory,load_artifact,save_artifactandlist_artifactsare allasync. Four samples called them from a plaindefand read attributes off thereturned coroutine.
Fixing that exposed a second defect underneath: the memory sample then read
search_results.results, andSearchMemoryResponsehas no such field. It ismemories, holdingMemoryEntryobjects whose text is atentry.content.parts[].text.docs/sessions/memory.mdalready had this right.The TypeScript and Java tabs of the same example had the same mistake, and
are corrected too.
Also:
CodeExecutionInputimported fromgoogle.adk.code_executorsrather than...code_executors.code_execution_utils; acalendar_tool_setobject that doesnot exist, replaced by the real
CalendarToolsetclass, in a sample that alsoreferenced two variables it never defined; two positional
Part.from_textcallsagainst a keyword-only signature; five
LlmAgentsamples missing the requiredname, which raises aValidationError; and an external-access-token samplebuilt on
AuthCredentialTypes.GOOGLE_CREDENTIALSand agoogle_credentials_configfield, neither of which the package defines. Thereal setting is
external_access_token_keyon a toolset's credentials config.Samples that could not parse at all
An unindented plugin class body, which was the opening sample on the Plugins
page and raised
IndentationErroron the line after the class statement. Two)]bracket typos. A backslash-escaped Java text-block delimiter. A truncatedEventsCompactionConfig(call. Anawaitin a non-async function, and anotherdedented out of the
ifmeant to guard it. A mid-file Java import.#commentsopening Go and Java blocks where the TypeScript tab correctly used
//.One fence in
docs/integrations/application-integration.mdopened at six spacesand closed at eight, so it never terminated and the page rendered a literal
```javaas body text. That tab is a real code block now.Known defects this does not fix
Found while checking, left alone because the right correction needs a decision
from whoever owns the page:
docs/sessions/memory.mdhas a Go block mixing a package-levelfuncdeclaration with a
:=statement, which is not valid at file scope. Thecorrection needs the sample restructured, and the variable renamed, since it
currently shadows the imported
agentpackage.docs/sessions/session/index.mdcalls thesuspendfunctionscreateSessionanddeleteSessionfrom a top-level Kotlin context.docs/graphs/dynamic.mdhas a Python node that yields and then doesreturn code, which is a syntax error in an async generator.docs/integrations/gke-code-executor.mdbuilds anInvocationContext()withno arguments where three fields are required.
examples/python/snippets/tools/overview/doc_analysis.pydoes not compile:awaitinside a plaindef. It is included bydocs/tools-custom/index.md.where the API takes a single options object.
Overlap with my other open pull requests
Twelve of these files are also touched by pull requests I already have open:
#2024 (
docs/context/), #2025 (docs/tools-custom/), #2023(
docs/live/), #2021 (docs/agents/) and #2019(
docs/integrations/gke-code-executor.md). Those were opened earlier and coverdifferent defects on the same pages.
If it is easier to review, I am happy to close this and fold each change into
the matching open pull request instead. Say which you prefer.
A gap this surfaced
python-lint.yamlandpython-tests.yamlare filtered tosamples/python/**,and no
samples/directory exists, so on pull requests neither can ever run. NoPython, Java or TypeScript sample is checked by CI. That is why these defects
survived. Happy to follow up with a workflow that runs these checks.