Skip to content

docs(agents): add missing lifecycle methods to getCurrentAgent() context availability#29193

Open
dmmulroy wants to merge 1 commit intocloudflare:productionfrom
dmmulroy:dillon/get-current-agent-context-availability
Open

docs(agents): add missing lifecycle methods to getCurrentAgent() context availability#29193
dmmulroy wants to merge 1 commit intocloudflare:productionfrom
dmmulroy:dillon/get-current-agent-context-availability

Conversation

@dmmulroy
Copy link

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 + connection
  • onStateChanged() — agent + inherited context from caller
  • onError() — agent + inherited context from caller

Built-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 the connection when a client triggers a state update, but not when the server calls setState()).

Also changed "Depends" to "Inherited" for queue callbacks for consistency.

Verification

Audited against the SDK source (packages/agents/src/index.ts), checking every agentContext.run() call to confirm the exact context each lifecycle method receives.

…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().
@github-actions github-actions bot added product:agents Build and deploy AI-powered Agents on Cloudflare that can act autonomously. size/s labels Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product:agents Build and deploy AI-powered Agents on Cloudflare that can act autonomously. size/s

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants