Workflow class executes steps, persists runs, and manages workflow sessions.
Parameters
Functions
run
Execute the workflow synchronously with optional streaming.
Parameters:
input(Optional[Union[str, Dict[str, Any], List[Any], BaseModel]]): The input to send to the workflowadditional_data(Optional[Dict[str, Any]]): Additional data to include with the inputuser_id(Optional[str]): User ID to userun_id(Optional[str]): Run ID to use. A UUID is generated when omittedsession_id(Optional[str]): Session ID to usesession_state(Optional[Dict[str, Any]]): Session state to useaudio(Optional[List[Audio]]): Audio files to includeimages(Optional[List[Image]]): Image files to includevideos(Optional[List[Video]]): Video files to includefiles(Optional[List[File]]): Files to includestream(Optional[bool]): Whether to stream the response. Defaults to the workflow settingstream_events(Optional[bool]): Whether to stream intermediate stepsbackground(Optional[bool]): Reserved for API parity. Synchronous background execution is unsupportedbackground_tasks(Optional[Any]): Background task manager passed to step executorsdependencies(Optional[Dict[str, Any]]): Run-level dependencies merged with workflow dependenciesmetadata(Optional[Dict[str, Any]]): Run-level metadata merged with workflow metadataadd_dependencies_to_context(Optional[bool]): Override whether downstream agents and teams receive dependencies in contextadd_session_state_to_context(Optional[bool]): Override whether downstream agents and teams receive session state in context**kwargs: Additional arguments passed to the workflow agent or step executors
Union[WorkflowRunOutput, Iterator[WorkflowRunOutputEvent]]: Either a WorkflowRunOutput or an iterator of WorkflowRunOutputEvents, depending on thestreamparameter
arun
Execute the workflow asynchronously with optional streaming.
Parameters:
input(Optional[Union[str, Dict[str, Any], List[Any], BaseModel, List[Message]]]): The input to send to the workflowadditional_data(Optional[Dict[str, Any]]): Additional data to include with the inputuser_id(Optional[str]): User ID to userun_id(Optional[str]): Run ID to use. A UUID is generated when omittedsession_id(Optional[str]): Session ID to usesession_state(Optional[Dict[str, Any]]): Session state to useaudio(Optional[List[Audio]]): Audio files to includeimages(Optional[List[Image]]): Image files to includevideos(Optional[List[Video]]): Video files to includefiles(Optional[List[File]]): Files to includestream(Optional[bool]): Whether to stream the response. Defaults to the workflow settingstream_events(Optional[bool]): Whether to stream intermediate stepsbackground(Optional[bool]): Whether to run in backgroundwebsocket(Optional[WebSocket]): WebSocket for real-time communicationenable_websocket(bool): Use WebSocket transport when background streaming. Requireswebsocketbackground_tasks(Optional[Any]): Background task manager passed to step executorsdependencies(Optional[Dict[str, Any]]): Run-level dependencies merged with workflow dependenciesmetadata(Optional[Dict[str, Any]]): Run-level metadata merged with workflow metadataadd_dependencies_to_context(Optional[bool]): Override whether downstream agents and teams receive dependencies in contextadd_session_state_to_context(Optional[bool]): Override whether downstream agents and teams receive session state in context**kwargs: Additional arguments passed to the workflow agent or step executors
Union[WorkflowRunOutput, AsyncIterator[WorkflowRunOutputEvent]]: Either a WorkflowRunOutput or an iterator of WorkflowRunOutputEvents, depending on thestreamparameter
continue_run
Resume a paused workflow run after HITL requirements have been resolved. Used for both step-level and executor-level pauses. See HITL overview.
Parameters:
run_response(Optional[WorkflowRunOutput]): The pausedWorkflowRunOutputto continue. If not provided,run_idandsession_idmust be supplied to load it from the database.run_id(Optional[str]): The run_id of the paused run. Required ifrun_responseis not provided.session_id(Optional[str]): The session_id of the paused run. Required ifrun_responseis not provided.step_requirements(Optional[List[StepRequirement]]): Updated step requirements with confirmation status. Defaults to the requirements fromrun_response.stream(Optional[bool]): Whether to stream the response. Defaults to the workflow’s stream setting.stream_events(Optional[bool]): Whether to stream events. Defaults to the workflow’sstream_eventssetting.**kwargs: Additional arguments passed to resumed step executors
Union[WorkflowRunOutput, Iterator[WorkflowRunOutputEvent]]: AWorkflowRunOutputifstream=False, otherwise an iterator of events.
ValueError: If neitherrun_responsenor (run_id+session_id) are provided, the run is not paused, or step requirements have not been resolved.
acontinue_run
Asynchronous variant of continue_run. Required when the workflow’s database is async.
It accepts the same parameters as continue_run, plus:
background(Optional[bool]): Whether to continue the run in the backgroundwebsocket(Optional[WebSocket]): WebSocket for real-time communicationenable_websocket(bool): Use WebSocket transport when background streaming. Requireswebsocket**kwargs: Additional arguments passed to resumed step executors
Union[WorkflowRunOutput, AsyncIterator[WorkflowRunOutputEvent]]: AWorkflowRunOutputifstream=False, otherwise an async iterator of events
print_response
Print workflow execution with rich formatting and optional streaming.
Parameters:
input(Union[str, Dict[str, Any], List[Any], BaseModel, List[Message]]): The input to send to the workflowadditional_data(Optional[Dict[str, Any]]): Additional data to include with the inputuser_id(Optional[str]): User ID to usesession_id(Optional[str]): Session ID to useaudio(Optional[List[Audio]]): Audio files to includeimages(Optional[List[Image]]): Image files to includevideos(Optional[List[Video]]): Video files to includefiles(Optional[List[File]]): Files to includestream(Optional[bool]): Whether to stream the response contentmarkdown(bool): Whether to render content as markdownshow_time(bool): Whether to show execution timeshow_step_details(bool): Whether to show individual step outputsconsole(Optional[Any]): Rich console instance (optional)**kwargs: Additional arguments passed torun()
aprint_response
Print workflow execution with rich formatting and optional streaming asynchronously.
Parameters:
input(Union[str, Dict[str, Any], List[Any], BaseModel, List[Message]]): The input to send to the workflowadditional_data(Optional[Dict[str, Any]]): Additional data to include with the inputuser_id(Optional[str]): User ID to usesession_id(Optional[str]): Session ID to useaudio(Optional[List[Audio]]): Audio files to includeimages(Optional[List[Image]]): Image files to includevideos(Optional[List[Video]]): Video files to includefiles(Optional[List[File]]): Files to includestream(Optional[bool]): Whether to stream the response contentmarkdown(bool): Whether to render content as markdownshow_time(bool): Whether to show execution timeshow_step_details(bool): Whether to show individual step outputsconsole(Optional[Any]): Rich console instance (optional)**kwargs: Additional arguments passed toarun()
cli_app
Run an interactive command-line interface to interact with the workflow.
Parameters:
input(Optional[str]): The input to send to the workflowsession_id(Optional[str]): Session ID to useuser_id(Optional[str]): User ID to useuser(str): Name for the user (default: “User”)emoji(str): Emoji for the user (default: “:technologist:”)stream(Optional[bool]): Whether to stream the response contentmarkdown(bool): Whether to render content as markdown (default: True)show_time(bool): Whether to show execution time (default: True)show_step_details(bool): Whether to show individual step outputs (default: True)exit_on(Optional[List[str]]): List of commands to exit the CLI**kwargs: Additional keyword arguments
acli_app
Run an interactive command-line interface to interact with the workflow asynchronously.
Parameters:
input(Optional[str]): The input to send to the workflowsession_id(Optional[str]): Session ID to useuser_id(Optional[str]): User ID to useuser(str): Name for the user (default: “User”)emoji(str): Emoji for the user (default: “:technologist:”)stream(Optional[bool]): Whether to stream the response contentmarkdown(bool): Whether to render content as markdown (default: True)show_time(bool): Whether to show execution time (default: True)show_step_details(bool): Whether to show individual step outputs (default: True)exit_on(Optional[List[str]]): List of commands to exit the CLI**kwargs: Additional keyword arguments
cancel_run
Cancel a running workflow execution.
Parameters:
run_id(str): The run_id to cancel
bool: True if the run was found and marked for cancellation, False otherwise
acancel_run
Cancel a running workflow asynchronously.
Parameters:
run_id(str): The run ID to cancel
bool: True if the run was found and marked for cancellation, False otherwise
get_run
Get the status and details of a background workflow run.
Parameters:
run_id(str): The run ID to getsession_id(Optional[str]): Session ID used for database lookup
Optional[WorkflowRunOutput]: The workflow run output if found
get_run_output
Get a WorkflowRunOutput from the database.
Parameters:
run_id(str): The run IDsession_id(Optional[str]): Session ID to useuser_id(Optional[str]): User ID used to scope the session lookup
Optional[WorkflowRunOutput]: The run output
get_last_run_output
Get the last run response from the database for the given session ID.
Parameters:
session_id(Optional[str]): Session ID to use
Optional[WorkflowRunOutput]: The last run output
get_chat_history
Return the input and output interactions for each run in the session.
Parameters:
session_id(Optional[str]): The session ID to get the chat history for. If not provided, the current cached session ID is usedlast_n_runs(Optional[int]): Number of recent runs to include. If None, all runs will be considered
List[WorkflowChatInteraction]: The input and output interactions for each run
get_session
Get the session for the given session ID.
Parameters:
session_id(Optional[str]): Session ID to useuser_id(Optional[str]): User ID used to scope the session lookup
Optional[WorkflowSession]: The workflow session
get_session_state
Get the session state for the given session ID.
Parameters:
session_id(Optional[str]): Session ID to use
Dict[str, Any]: The session state
update_session_state
Merge values into the session state and persist the session.
Parameters:
session_state_updates(Dict[str, Any]): Values to merge into session statesession_id(Optional[str]): Session ID to use
Dict[str, Any]: The updated session state
get_session_name
Get the session name for the given session ID.
Parameters:
session_id(Optional[str]): Session ID to use
str: The session name
set_session_name
Set the session name and save to storage.
Parameters:
session_id(Optional[str]): Session ID to useautogenerate(bool): Whether to autogenerate the namesession_name(Optional[str]): The name to set
WorkflowSession: The updated session
get_session_metrics
Get the session metrics for the given session ID.
Parameters:
session_id(Optional[str]): Session ID to use
Optional[SessionMetrics]: The session metrics
delete_session
Delete a session.
Parameters:
session_id(str): Session ID to deleteuser_id(Optional[str]): User ID used to scope the session deletion
save_session
Save the WorkflowSession to storage.
Parameters:
session(WorkflowSession): The session to save
to_dict
Convert workflow to dictionary representation.
Returns:
Dict[str, Any]: Dictionary representation of the workflow
run_parameters
Return the input parameters accepted by the workflow. Callable workflows expose their function signature. Step-based workflows expose a required string message parameter.
Returns:
Dict[str, Any]: Parameter names mapped to their defaults, annotations, and required status
from_dict
Create a workflow from a dictionary.
Parameters:
data(Dict[str, Any]): Serialized workflow configurationdb(Optional[BaseDb]): Database used to reconstruct step executorslinks(Optional[List[Dict[str, Any]]]): Links for the workflow versionregistry(Optional[Registry]): Registry used to resolve schemas and executors
Workflow: Reconstructed workflow
save
Save the workflow component and configuration.
Parameters:
db(Optional[BaseDb]): Database to save to. Defaults to the workflow databasestage(str): Component stage. Defaults to"published"label(Optional[str]): Configuration labelnotes(Optional[str]): Configuration notes
Optional[int]: Saved configuration version, orNonewhen saving fails
load
Load a workflow configuration from a database.
Parameters:
id(str): Workflow IDdb(BaseDb): Database to load fromregistry(Optional[Registry]): Registry used to reconstruct schemas and executorslabel(Optional[str]): Configuration labelversion(Optional[int]): Configuration version
Optional[Workflow]: Loaded workflow, orNonewhen no matching configuration exists
delete
Delete the workflow component.
Parameters:
db(Optional[BaseDb]): Database to delete from. Defaults to the workflow databasehard_delete(bool): Permanently delete the component whenTrue
bool: Whether the workflow was deleted
deep_copy
Create a copy with isolated mutable state while sharing heavy resources such as database connections.
Parameters:
update(Optional[Dict[str, Any]]): Fields to override on the copied workflow
Workflow: Copied workflow
aget_run(), aget_run_output(), aget_last_run_output(), aget_chat_history(), aget_session(), aget_session_state(), aupdate_session_state(), aget_session_name(), aset_session_name(), aget_session_metrics(), adelete_session(), and asave_session().