Repository navigation
docs(core): describe the TypeScript API on its own terms - #628
Conversation
|
Applying feedback from a sibling PR that turned up a defect here. @kazunori279 closed #2076 (the TypeScript streaming quickstart) on this principle:
Documentation must not assert a capability the code doesn't have. I checked this PR against that and found one place where it did — introduced by this PR, on the more authoritative surface.
/**
* Streaming mode: {@link StreamingMode.NONE}, {@link StreamingMode.SSE}
* or {@link StreamingMode.BIDI}.
*/
streamingMode?: StreamingMode;That presents three equal options. But Streaming is gated solely on
/**
* Reserved for bidirectional streaming, which is not implemented. Selecting
* it currently behaves as {@link StreamingMode.NONE}. Use
* {@link StreamingMode.SSE} for incremental responses.
*/
BIDI = 'bidi',Worth noting the ideal fix is upstream of the docs: an enum member that does nothing is better removed or made to throw than described. I've kept to comments here since that's this PR's scope, but I'm happy to open a separate issue against the SDK if that's useful. Verification
Correction to this PR's descriptionThe PR body cites "693,151 downloads/month but only ~948 external developers". Both figures are wrong and I'd rather retract them than leave them in a Google repo. A measurement audit since found the download count is ~96.7% pinned re-installs and CI — |
|
Correction to my comment above — the last section of it is wrong and I'd rather flag that than let it stand. I wrote that this PR's description "cites 693,151 downloads/month but only ~948 external developers". It doesn't. I checked all seven PRs in this series afterwards and none of them cite those figures; they were in my own working notes, and I attributed them to a PR body without re-reading it. Apologies for the noise. What I should have said, and what still holds: those two numbers circulate as a motivation for TypeScript onboarding work, and a measurement audit has since established both are unsound — the download count is ~96.7% pinned re-installs and CI ( The technical content of the comment above is unaffected: the |
ee15dda to
1c4ebfb
Compare
kazunori279
left a comment
There was a problem hiding this comment.
Thanks for this — the direction is right, and I verified most of the rewritten claims against main. One of them is factually wrong and should be fixed before merge; the other two are optional nits.
Needs a fix: BIDI is described as unimplemented, but bidirectional streaming is implemented
See the inline comments on core/src/agents/run_config.ts. Bidirectional streaming is a real, working code path — Runner.runLive() (core/src/runner/runner.ts:648) is a full implementation, and LlmAgent.runLiveFlow (core/src/agents/llm_agent.ts:959) has a reconnect loop. What is actually true is narrower: StreamingMode.BIDI is not the way to reach it. runLive itself calls createRunConfig (runner.ts:665), so passing BIDI throws there too.
The text on main ("Not yet supported") was already vague; this PR hardens it into "is not implemented", which makes it wrong rather than vague. Worth getting right, since this is exactly the kind of stale capability claim the PR sets out to remove.
Nit (optional): core/src/utils/output_schema_utils.ts
The new comment spends six lines on where the EAP-model gap could be fixed and why widening isGemini2OrAbove is risky. That is useful reasoning, but it reads as design discussion inside an API doc comment. Consider compressing it to a sentence or two and moving the "how to fix" part to a TODO with a bug reference.
Nit (optional): core/src/runner/runner.ts
RunnerConfig.agent still carries Mirrors adk-python, whose Runner.agent is typed BaseNode. (around line 71). Since the file is already touched by this PR, it looks in scope for the same cleanup.
Verified as correct
For the record, I checked these against main and they hold: the SingleAgentCallback/Context rewrite; the explanation that endInvocation is scoped to the agent that sets it; the generateContentConfig correction to the three rejected fields (the old text's planner advice was a Python-ism — there is no planner or thinkingConfig anywhere in core/src); maxLlmCalls / Number.MAX_SAFE_INTEGER; the function_tool.ts Zod-parse and Error in tool '<name>': … wording; the google_llm.ts @yields text, including the metadata-only-stream case, which matches StreamingResponseAggregator.close(); the ^...$ anchoring rationale in registry.ts; the logging_plugin.ts Runner example (the old agents: [myAgent] was not a valid RunnerConfig, the new one is); the base_plugin.ts example; the schema.ts cross-runtime warning, which I also checked against adk-python's sessions/schemas/v1.py; the example imports; the isGemini2OrAbove three-consumer claim; and the changes to a2a/auth.ts, load_web_page.ts and vertex_rag_retrieval_tool.ts.
| /** | ||
| * Bidirectional streaming. Not yet supported; passing this value to | ||
| * `createRunConfig` throws. Use {@link StreamingMode.SSE} for token | ||
| * streaming. | ||
| * Reserved for bidirectional streaming, which is not implemented. Passing | ||
| * this value to `createRunConfig` throws. Use {@link StreamingMode.SSE} for | ||
| * incremental responses. | ||
| */ |
There was a problem hiding this comment.
which is not implemented is not accurate. Bidirectional streaming is implemented — Runner.runLive() (core/src/runner/runner.ts:648) and LlmAgent.runLiveFlow (core/src/agents/llm_agent.ts:959) are real code paths. What does not work is reaching it through this enum value: runLive itself calls createRunConfig, which rejects BIDI.
| /** | |
| * Bidirectional streaming. Not yet supported; passing this value to | |
| * `createRunConfig` throws. Use {@link StreamingMode.SSE} for token | |
| * streaming. | |
| * Reserved for bidirectional streaming, which is not implemented. Passing | |
| * this value to `createRunConfig` throws. Use {@link StreamingMode.SSE} for | |
| * incremental responses. | |
| */ | |
| /** | |
| * Reserved. Bidirectional streaming is reached through `Runner.runLive()`, | |
| * not through this value: `runLive` itself calls `createRunConfig`, which | |
| * rejects `BIDI`. Use {@link StreamingMode.SSE} for incremental responses. | |
| */ |
There was a problem hiding this comment.
Applied in 0951a24. The comment now says bidirectional streaming is reached through Runner.runLive(), and only this enum value is rejected by createRunConfig.
| /** | ||
| * Streaming mode. Supported values are {@link StreamingMode.NONE} and | ||
| * {@link StreamingMode.SSE}. {@link StreamingMode.BIDI} is not yet | ||
| * supported and is rejected by `createRunConfig`. | ||
| * How the response is delivered. Defaults to {@link StreamingMode.NONE}, | ||
| * which emits one event when the turn completes; set | ||
| * {@link StreamingMode.SSE} to receive partial events as the response is | ||
| * produced. {@link StreamingMode.BIDI} is not implemented and is rejected by | ||
| * `createRunConfig`. | ||
| */ |
There was a problem hiding this comment.
Same issue: {@link StreamingMode.BIDI} is not implemented overstates it. Only the enum value is rejected.
| /** | |
| * Streaming mode. Supported values are {@link StreamingMode.NONE} and | |
| * {@link StreamingMode.SSE}. {@link StreamingMode.BIDI} is not yet | |
| * supported and is rejected by `createRunConfig`. | |
| * How the response is delivered. Defaults to {@link StreamingMode.NONE}, | |
| * which emits one event when the turn completes; set | |
| * {@link StreamingMode.SSE} to receive partial events as the response is | |
| * produced. {@link StreamingMode.BIDI} is not implemented and is rejected by | |
| * `createRunConfig`. | |
| */ | |
| /** | |
| * How the response is delivered. Defaults to {@link StreamingMode.NONE}, | |
| * which emits one event when the turn completes; set | |
| * {@link StreamingMode.SSE} to receive partial events as the response is | |
| * produced. {@link StreamingMode.BIDI} is rejected by `createRunConfig`; | |
| * bidirectional streaming is reached through `Runner.runLive()` instead. | |
| */ |
There was a problem hiding this comment.
Applied in 0951a24. The field doc now says createRunConfig rejects BIDI, and bidirectional streaming is reached through Runner.runLive() instead.
The doc comments in core/src feed the published TypeDoc reference at adk.dev/api-reference/typescript/, and several of them documented this library as a diff against another SDK a JavaScript reader has never used. Most encoded a real constraint; restate each as a fact about TypeScript. Notably ToolOptions now states positively where a tool's description and per-argument descriptions come from (the options and the schema, because types and JSDoc are erased at runtime), with a correct-usage example, instead of noting what is ignored.
…matic doc comments
The previous commit's ToolOptions rewrite stated two things that are false.
"The framework validates the arguments" is only true for a Zod object schema:
a genai `Schema` gets no runtime check at all, and passing {n: 'not-a-number'}
to a tool declaring a number reaches `execute` untouched. A reader who trusts
that sentence skips their own validation. "Everything the model is told comes
from these options" is contradicted by LongRunningFunctionTool, which builds
from the same ToolOptions and appends a sentence to the description. Both are
restated as what the code does, keeping the positive framing and the Zod
`.describe()` example.
Restores three notes the previous commit dropped rather than translated: the
EAP gap in output_schema_utils lives in the shared `isGemini2OrAbove`
predicate and is a bug, not a design decision; the SSRF block list follows RFC
6890; and the session DB's snake_case is a versioned on-disk interop contract,
not a style choice (a non-exported class, so it never reaches TypeDoc).
Also fixes public doc comments the previous commit walked past. `type[BaseLlm]`
is not TypeScript. `@param callbackContext: MUST be named 'callbackContext'
(enforced)` describes a keyword argument in a language that has none, and is
false besides: SingleAgentCallback is `(context: Context)`. `sys.maxsize` is
`Number.MAX_SAFE_INTEGER`. `@param stream bool = false` is not TSDoc. `httpx`
is a Python library. And five `@example` blocks did not compile - one imported
`StreamableHTTPConnectionParamsSchema`, which does not exist - all now verified
against the real types.
Five statements added or kept in the previous two commits describe
behaviour the code does not have. Each replacement here was checked by
running the code.
- llm_agent: `generateContentConfig` claimed `thinkingConfig` "must be
configured via `planner`". There is no planner in adk-js; the
constructor rejects only `tools`, `systemInstruction` and
`responseSchema`, and `thinkingConfig` reaches the wire untouched
(`generationConfig.thinkingConfig = {"thinkingBudget":0}` on a real
Vertex call).
- base_agent: "Returning `Content` ends the invocation" was a
regression. `endInvocation` is copied by value into the per-agent
invocation context, so a `SequentialAgent` still runs the remaining
sub-agents; the skip covers only this agent's own body and its
`afterAgentCallback`.
- output_schema_utils: the EAP gap is not one that can "only" be closed
in `isGemini2OrAbove` -- it can be closed here too; the reason not to
widen the shared predicate is its other callers.
- google_llm: a streaming call emits a final aggregated response
whenever the stream carried content *or* usage/grounding/citation
metadata, not only when content accumulated.
- function_tool: "unknown keys removed" holds for a default
`z.object()` only; `.passthrough()` forwards them and `.strict()`
rejects the call.
Also repairs the two doc examples that do not compile: the canonical
plugin example used a `this.logger` that does not exist, and the A2A
bearer-token example passed `process.env.MY_TOKEN` (`string |
undefined`) to a `string` parameter. All 17 TypeScript example blocks in
core/src now type-check.
Comments only: the emitted JS and .d.ts are byte-identical to `main`
once comments are stripped (804 files compared).
The doc comment listed NONE, SSE and BIDI as equal options. BIDI is accepted by the API but has no functional reference anywhere in core/src: streaming is gated solely on StreamingMode.SSE, so selecting BIDI silently behaves as NONE. A reader reasoning that bidi is a superset of SSE gets strictly worse behaviour with no warning. Document each enum member and state the real behaviour of BIDI. Comments only; the emitted JavaScript is unchanged.
1c4ebfb to
bacf098
Compare
StreamingMode.BIDI was documented as unimplemented, but bidirectional streaming is implemented via Runner.runLive(); only the enum value is rejected by createRunConfig. Correct both doc comments to say so. Also address review nits: compress the EAP-gap design discussion in output_schema_utils.ts to a short note, and drop the adk-python cross-reference from RunnerConfig.agent.
|
Both optional nits are also addressed in 0951a24: the EAP-gap discussion in |
…tion-response Only core/src/agents/functions.ts conflicted, against the docs-only google#628. That commit rewrote findMatchingFunctionCall's doc to describe the last event's *first* function response -- the behavior this branch replaces -- so the branch's own doc is kept. google#628's other rewrites, including findEventByFunctionCallId's, are taken as-is, and no 'Mirrors Python ADK's' phrasing remains in the file.
* docs(core): describe the TypeScript API on its own terms in doc comments
The doc comments in core/src feed the published TypeDoc reference at
adk.dev/api-reference/typescript/, and several of them documented this
library as a diff against another SDK a JavaScript reader has never used.
Most encoded a real constraint; restate each as a fact about TypeScript.
Notably ToolOptions now states positively where a tool's description and
per-argument descriptions come from (the options and the schema, because
types and JSDoc are erased at runtime), with a correct-usage example,
instead of noting what is ignored.
* docs(core): correct tool-description semantics and remaining non-idiomatic doc comments
The previous commit's ToolOptions rewrite stated two things that are false.
"The framework validates the arguments" is only true for a Zod object schema:
a genai `Schema` gets no runtime check at all, and passing {n: 'not-a-number'}
to a tool declaring a number reaches `execute` untouched. A reader who trusts
that sentence skips their own validation. "Everything the model is told comes
from these options" is contradicted by LongRunningFunctionTool, which builds
from the same ToolOptions and appends a sentence to the description. Both are
restated as what the code does, keeping the positive framing and the Zod
`.describe()` example.
Restores three notes the previous commit dropped rather than translated: the
EAP gap in output_schema_utils lives in the shared `isGemini2OrAbove`
predicate and is a bug, not a design decision; the SSRF block list follows RFC
6890; and the session DB's snake_case is a versioned on-disk interop contract,
not a style choice (a non-exported class, so it never reaches TypeDoc).
Also fixes public doc comments the previous commit walked past. `type[BaseLlm]`
is not TypeScript. `@param callbackContext: MUST be named 'callbackContext'
(enforced)` describes a keyword argument in a language that has none, and is
false besides: SingleAgentCallback is `(context: Context)`. `sys.maxsize` is
`Number.MAX_SAFE_INTEGER`. `@param stream bool = false` is not TSDoc. `httpx`
is a Python library. And five `@example` blocks did not compile - one imported
`StreamableHTTPConnectionParamsSchema`, which does not exist - all now verified
against the real types.
* docs(core): correct inaccurate behavioural claims in doc comments
Five statements added or kept in the previous two commits describe
behaviour the code does not have. Each replacement here was checked by
running the code.
- llm_agent: `generateContentConfig` claimed `thinkingConfig` "must be
configured via `planner`". There is no planner in adk-js; the
constructor rejects only `tools`, `systemInstruction` and
`responseSchema`, and `thinkingConfig` reaches the wire untouched
(`generationConfig.thinkingConfig = {"thinkingBudget":0}` on a real
Vertex call).
- base_agent: "Returning `Content` ends the invocation" was a
regression. `endInvocation` is copied by value into the per-agent
invocation context, so a `SequentialAgent` still runs the remaining
sub-agents; the skip covers only this agent's own body and its
`afterAgentCallback`.
- output_schema_utils: the EAP gap is not one that can "only" be closed
in `isGemini2OrAbove` -- it can be closed here too; the reason not to
widen the shared predicate is its other callers.
- google_llm: a streaming call emits a final aggregated response
whenever the stream carried content *or* usage/grounding/citation
metadata, not only when content accumulated.
- function_tool: "unknown keys removed" holds for a default
`z.object()` only; `.passthrough()` forwards them and `.strict()`
rejects the call.
Also repairs the two doc examples that do not compile: the canonical
plugin example used a `this.logger` that does not exist, and the A2A
bearer-token example passed `process.env.MY_TOKEN` (`string |
undefined`) to a `string` parameter. All 17 TypeScript example blocks in
core/src now type-check.
Comments only: the emitted JS and .d.ts are byte-identical to `main`
once comments are stripped (804 files compared).
* docs(core): document that StreamingMode.BIDI is not implemented
The doc comment listed NONE, SSE and BIDI as equal options. BIDI is
accepted by the API but has no functional reference anywhere in core/src:
streaming is gated solely on StreamingMode.SSE, so selecting BIDI silently
behaves as NONE. A reader reasoning that bidi is a superset of SSE gets
strictly worse behaviour with no warning.
Document each enum member and state the real behaviour of BIDI. Comments
only; the emitted JavaScript is unchanged.
* docs(core): correct BIDI capability claim and trim doc comments
StreamingMode.BIDI was documented as unimplemented, but bidirectional
streaming is implemented via Runner.runLive(); only the enum value is
rejected by createRunConfig. Correct both doc comments to say so.
Also address review nits: compress the EAP-gap design discussion in
output_schema_utils.ts to a short note, and drop the adk-python
cross-reference from RunnerConfig.agent.
---------
Co-authored-by: Amaad Martin <[email protected]>
A JavaScript developer should not be able to tell from the documentation that this library was ported from Python. Today they can — starting with the most-used API surface in the package.
These comments compile into the public TypeDoc reference at
adk.dev/api-reference/typescript/, so this is reader-facing text, not internal notes. Comments only: the emitted JS was built atmainand atHEADand diffed across 804 files with comments stripped — zero non-comment differences.The flagship
core/src/tools/function_tool.tsbegan:That sentence encodes a real constraint, expressed as a diff against a library the reader has never used. It now states positively where the model's view of a tool comes from —
name,description, and theparametersschema, because types and JSDoc are erased at runtime — with a Zod.describe()example that compiles.An independent reviewer wrote a working tool from that comment alone:
tsc --strictclean unedited, first try, and a real model called it with the.describe()text on the wire.Accuracy was the hard part, not tone
Two rounds of review caught five confidently-worded statements that were false, three of them introduced by this change. A wrong comment is worse than the awkward one it replaced, so each was reproduced by execution before being rewritten:
Schemapath.{n: 'not-a-number', extra: 'x'}reachedexecuteuntouched. Validation happens only on the Zod path. The comment now says which is which, and tells you to validate insideexecuteotherwise.LongRunningFunctionToolappends to the description. Now qualified, and verified to be the only such subclass.thinkingConfig"must be configured viaplanner" — there is noplannerin adk-js. One grep hit repo-wide: that comment.thinkingConfigworks directly and reaches the request as{"thinkingBudget":0}.Contentends the invocation" — a regression this change introduced. In aSequentialAgent, child1's callback returnedContentand child2 still ran. Now correctly scoped.isGemini2OrAbove"can only close the gap" — refuted by closing it elsewhere.Three earlier deletions were also restored, where removing a Python reference removed real information: a known bug that had started reading as intentional design, the RFC 6890 basis for an SSRF CIDR list, and the note that the on-disk session schema is a stable cross-implementation contract (that last one on a non-exported class, confirmed absent from the published reference).
Also fixed
type[BaseLlm](Python typing syntax on a public symbol) ·MUST be named 'callbackContext' (enforced)— a keyword-argument constraint in a language without keyword arguments, and false ·sys.maxsizewhere the code checksNumber.MAX_SAFE_INTEGER·@param stream booland@yields·httpx·// TODO: omitted Py LlmAgent features· and five@exampleblocks that did not compile, one importingStreamableHTTPConnectionParamsSchema, an identifier that exists nowhere but inside that comment.Verification
Unlike Python12→0,adk-python12→0,Python ADK2→0,sys.maxsize,type[,MUST be named,httpx,plannerall 0. The only survivingpythonispythonCommandPath/CodeExecutionLanguage.PYTHON, which genuinely executes Python.@exampleblock incore/srccontaining TypeScript extracted and compiled: 17 blocks, 0 failing (two were broken before this change).package-lock.jsonunmodified.Left deliberately:
.pyMIME mappings,pythonCommandPath, and the code-executor and skills features, which are genuinely about executing Python; and the snake_case wire-format transforms, where snake_case is the serialization format rather than an API ergonomics leak.One root cause, reported not fixed
CONTRIBUTING.md:94currently asks that TSDocs be "usually aligned with adk-python". That guidance is what produces this class of comment. Worth revisiting separately — andREADME.md:9and:102hotlink their logo and hero screenshot fromraw.githubusercontent.com/google/adk-python/, which was out of scope here.