docs(agents): add missing lifecycle methods to getCurrentAgent() context availability#29193
Open
dmmulroy wants to merge 1 commit intocloudflare:productionfrom
Open
Conversation
…ext availability table Add onStart(), onClose(), onStateChanged(), and onError() to the context availability table. Update the built-in methods list to include all lifecycle methods (onStart, onConnect, onMessage, onClose). Add a note explaining 'Inherited' context for methods like onStateChanged(), onError(), and queue callbacks where the available context depends on the calling context. Verified against the SDK source (packages/agents/src/index.ts) which wraps each lifecycle method with agentContext.run().
whoiskatrin
approved these changes
Mar 20, 2026
threepointone
approved these changes
Mar 20, 2026
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
Adds missing lifecycle methods to the
getCurrentAgent()context availability table on the API reference page.Changes
Context availability table
Added the following missing lifecycle methods:
onStart()— agent only (no connection, request, or email)onClose()— agent + connectiononStateChanged()— agent + inherited context from calleronError()— agent + inherited context from callerBuilt-in methods list
Updated the "Built-in vs custom methods" section to list all lifecycle methods that have context:
onStart,onRequest,onConnect,onMessage,onClose,onEmail,onStateChanged.Inherited context note
Added a note explaining what "Inherited" means in the table — these methods receive whatever context was active when they were triggered (e.g.,
onStateChanged()gets theconnectionwhen a client triggers a state update, but not when the server callssetState()).Also changed "Depends" to "Inherited" for queue callbacks for consistency.
Verification
Audited against the SDK source (
packages/agents/src/index.ts), checking everyagentContext.run()call to confirm the exact context each lifecycle method receives.