Overview
A workflow defines your agent’s end-to-end task. Workflows are comprised ofact() statements and Python code that orchestrate the automation logic. The Nova Act SDK provides convenience wrappers for managing workflows deployed with the Nova Act AWS service.
The Context Manager
The core type driving workflow coordination with the Nova Act service isWorkflow. This class provides a context manager which handles calling the necessary workflow API operations from the Amazon Nova Act service.
Basic Usage
How It Works
TheWorkflow context manager:
- Calls
CreateWorkflowRunwhen your run starts - Calls
UpdateWorkflowRunwith the appropriate status when it finishes - Associates all called APIs (
CreateSession,CreateAct,InvokeActStep,UpdateAct) with the correct workflow + run
When using the
Workflow context manager, the workflow parameter must be passed to the NovaAct constructor to associate the session with the workflow run.The Decorator
For convenience, the SDK also exposes a decorator which can be used to annotate functions to be run under a given workflow. The decorator leverages ContextVars to inject the correctWorkflow object into each NovaAct instance within the function.
Basic Usage
When using the
@workflow decorator, you don’t need to provide the workflow keyword argument to NovaAct. The decorator automatically injects the workflow context using ContextVars.Authentication
Workflows support two authentication methods:AWS IAM Authentication
API Key Authentication
By default, if you don’t provide
boto_session_kwargs and don’t use an API key, the workflow will automatically load AWS credentials using boto3 with {"region_name": "us-east-1"} as the default configuration.Retry Handling
By default, when a Nova Act request times out, the SDK will retry it once. This can be overridden by passing aboto_config object:
Multi-Threading
TheWorkflow class works seamlessly with multi-threaded workflows.
Using the Context Manager
Using the Decorator
Because the@workflow decorator leverages ContextVars for injecting context, and because ContextVars are thread-specific, you must provide the context to any functions that will run in different threads.
- Using copy_context
- Manual Injection
Multi-Processing
Workflow Properties
TheWorkflow class exposes several useful properties:
Best Practices
1. Always Use Context Managers
Always use theWorkflow as a context manager to ensure proper cleanup and status updates:
2. Choose the Right Pattern
- Use the context manager when you need explicit control over the workflow object or are passing it to helper functions
- Use the decorator for cleaner code when the workflow context is only needed within a single function
3. Handle Exceptions
The workflow context manager automatically sets the workflow run status toFAILED if an exception occurs: