# Create a context
ctx = InteractionContext()
ctxInteractionContext(state={}, request=None, session=None, data={}, metadata={})
The InteractionContext class provides a unified interface for accessing state, request data, and custom data within interaction patterns. This allows render functions and handlers to access everything they need without passing many individual parameters.
Context for interaction patterns providing access to state, request, and custom data.
The InteractionContext is typically created and managed by interaction pattern classes (like StepFlow), but here are examples showing how it’s used:
InteractionContext(state={}, request=None, session=None, data={}, metadata={})
Plugin ID: transcription_voxtral
Has file_path: False
# Context with custom data (typically from data loaders)
ctx_with_data = InteractionContext(
state={"user_id": "123"},
data={
"plugins": [
{"name": "voxtral", "title": "Voxtral HF"},
{"name": "whisper", "title": "Whisper"}
],
"plugin_count": 5
}
)
plugins = ctx_with_data.get_data("plugins", [])
print(f"Plugins available: {ctx_with_data.get_data('plugin_count')}")
print(f"First plugin: {plugins[0]}")Plugins available: 5
First plugin: {'name': 'voxtral', 'title': 'Voxtral HF'}
Here’s how the context is typically used within step render functions:
# Example render function signature
def render_plugin_selector(ctx: InteractionContext):
"""Render plugin selection step."""
# Access loaded data
plugins = ctx.get_data("plugins", [])
# Access current state
selected = ctx.get("plugin_id")
# Could access request if needed
# app_state = ctx.request.app.state
# Return rendered UI
return f"Render {len(plugins)} plugins, selected: {selected}"