Index
- Use the Right Context: Always use the most specific context object provided (
ToolContextin tools/tool-callbacks,CallbackContextin agent/model-callbacks,ReadonlyContextwhere applicable). Use the fullInvocationContext(ctx) directly in_run_async_impl/_run_live_implonly when necessary. - State for Data Flow:
context.stateis the primary way to share data, remember preferences, and manage conversational memory within an invocation. Use prefixes (app:,user:,temp:) thoughtfully when using persistent storage. - Artifacts for Files: Use
context.save_artifactandcontext.load_artifactfor managing file references (like paths or URIs) or larger data blobs. Store references, load content on demand. - UI Rendering: Use
context.render_ui_widget(widget)to send rich UI components (like MCP App iframes) to the client. - Tracked Changes: Modifications to state or artifacts made via context methods are automatically linked to the current step's
EventActionsand handled by theSessionService. - Start Simple: Focus on
stateand basic artifact usage first. Explore authentication, memory, and advancedInvocationContextfields (like those for live streaming) as your needs become more complex.