Executions
Understanding Task Executions and Their Lifecycle
Overview
Executions in Julep represent instances of tasks that have been initiated with specific inputs. They embody the lifecycle of a task, managing its progression through various states from initiation to completion. Understanding executions is crucial for effectively managing and monitoring the behavior of your AI agents and their workflows.
Components
Executions are comprised of several key components that work together to manage and monitor the state of a task:
- Execution ID: A unique identifier for each execution instance.
- Task ID: The identifier of the task being executed.
- Input: The inputs provided to the task at the time of execution.
- Status: The current state of the execution (e.g., queued, running, succeeded).
- Output: The result produced by the execution upon completion.
- Transitions: The sequence of state changes that the execution undergoes.
Execution Configuration options
Option | Type | Description | Default |
---|---|---|---|
task_id | string | The ID of the task to execute | Required |
input | object | The input to the task | Required |
metadata | object | Additional metadata for the execution instance | null |
Lifecycle of an Execution
An execution follows a well-defined lifecycle, transitioning through various states from start to finish. Understanding these states helps in monitoring and managing task executions effectively.
Execution Statuses
Executions can exist in one of the following statuses:
Status | Description |
---|---|
queued | The execution is queued and waiting to start. |
starting | The execution is starting. |
running | The execution is currently running. |
awaiting_input | The execution is suspended and awaiting user input to resume. |
succeeded | The execution has completed successfully. |
failed | The execution has failed due to an error. |
cancelled | The execution has been cancelled by the user or system. |
Execution State Machine
The state transitions of an execution are governed by a state machine that ensures proper progression and handling of different scenarios.
Execution State Transitions
Executions in Julep follow a specific state transition model. The transitions are governed by both the execution status and the transition type:
- Init: The execution is initialized.
- Start: The execution begins.
- Step: A step within the execution is executed.
- Wait: The execution is waiting for an external input.
- Resume: The execution resumes after waiting.
- Finish: The execution completes successfully.
- Error: The execution encounters an error.
- Cancel: The execution is cancelled.
Transition Types
Transition Type | Description |
---|---|
init | Initializes the execution. |
start | Starts the execution process. |
step | Executes a step within the task. |
wait | Pauses execution waiting for external input. |
resume | Resumes execution after a wait. |
finish | Marks the execution as successfully completed. |
error | Marks the execution as failed due to an error. |
cancel | Cancels the execution. |
Creating an Execution
To create an execution for a specific task, use the following method in the SDKs.
Monitoring an Execution
After initiating an execution, itβs essential to monitor its progress and handle its completion or failure appropriately.
To view more details about the status of the execution and how it is transitioning between states, you can use list the transitions of an execution.
Example:
Updating/Cancelling an Execution
To update or cancel an execution, you can use the change_status
method in the SDKs.
Example:
Best Practices
Handle All Statuses
- 1. Execution Statuses: Ensure your application gracefully handles all possible execution statuses, including
failed
andcancelled
.
Polling Interval
- 1. Polling Interval: Choose an appropriate polling interval to balance responsiveness and API usage.
Logging
- 1. Logging: Maintain detailed logs of execution statuses and outputs for auditing and debugging purposes.
Next Steps
- Checkout the Tutorial - Learn how to use executions in a tutorial
- Checkout the Execution Lifecycle - Learn more about the execution lifecycle