Skip to main content

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.
  • Transition Count: The number of transitions that have occurred in this execution.

Execution Configuration options

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:

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

Creating an Execution

To create an execution for a specific task, use the following method in the SDKs.
Check out the API reference here or SDK reference (Python here or JavaScript here for more details on different operations you can perform on executions.

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:
Check out the API reference here or SDK reference (Python here or JavaScript here for more details on different operations you can perform on executions.

Streaming Execution Status Updates

Using the raw SSE endpoint

You can subscribe to real-time status updates using the Server-Sent Events (SSE) endpoint. Each event conforms to the ExecutionStatusEvent schema and includes the following fields:
  • execution_id: The UUID of the execution.
  • status: The current execution status.
  • updated_at: ISO 8601 timestamp of the update.
  • error: Error message if the execution failed.
  • transition_count: Number of transitions that have occurred.
  • metadata: Arbitrary metadata for the event.
You’ll be getting events that look like this:

Using the Python SDK AsyncClient

This approach relies on Python’s async / await syntax. Make sure to:
  1. Use AsyncClient not Client.
  2. await client.executions.status.stream(...) to obtain the async generator.
  3. Iterate with async for to consume events.

Updating/Cancelling an Execution

To update or cancel an execution, you can use the change_status method in the SDKs. Example:
Check out the API reference here or SDK reference (Python here or JavaScript here for more details on different operations you can perform on executions.

Best Practices

Handle All Statuses

  • 1. Execution Statuses: Ensure your application gracefully handles all possible execution statuses, including failed and cancelled.

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