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.
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.
To create an execution for a specific task, use the following method in the SDKs.
from julep import Julepimport yamlclient = Julep(api_key="YOUR_API_KEY")# Execute the task (assuming the task is already created)execution = client.executions.create( task_id="task_id", input={ "parameter1": "value1", "parameter2": "value2" })print(f"Execution ID: {execution.id}")
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.
After initiating an execution, it’s essential to monitor its progress and handle its completion or failure appropriately.
import timefrom julep import Julepclient = Julep(api_key="YOUR_API_KEY")execution_id = "YOUR_EXECUTION_ID"while True: result = client.executions.get(execution_id) print(f"Status: {result.status}") print(f"Current output: {result.output}") if result.status in ["succeeded", "failed", "cancelled"]: if result.status == "succeeded": print("Execution succeeded with output:", result.output) else: print("Execution ended with status:", result.status) break time.sleep(5) # Wait for 5 seconds before polling again
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:
from julep import Julepclient = Julep(api_key="YOUR_API_KEY")execution_id = "YOUR_EXECUTION_ID"transitions = client.executions.transitions.list(execution_id)print(transitions.items)
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.
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.
curl -X GET 'https://api.julep.ai/api/executions/{execution_id}/status.stream' \ -H 'Authorization: Bearer $JULEP_API_KEY'
from julep import AsyncClientclient = AsyncClient(api_key="YOUR_API_KEY")execution_id = "YOUR_EXECUTION_ID"# Subscribe to the live status stream (async generator)status_stream = await client.executions.status.stream(execution_id=execution_id)# Consume events in real-time using async forasync for event in status_stream: print("Execution status:", event.status, "updated at", event.updated_at)
This approach relies on Python’s async / await syntax. Make sure to:
Use AsyncClient not Client.
await client.executions.status.stream(...) to obtain the async generator.
To update or cancel an execution, you can use the change_status method in the SDKs.Example:
from julep import Julepclient = Julep(api_key="YOUR_API_KEY")execution_id = "YOUR_EXECUTION_ID"# To cancel an executionclient.executions.change_status(execution_id=execution_id, status="cancelled")# To resume an execution with specific inputclient.executions.change_status( execution_id=execution_id, status="running", input={ "parameter1": "value1", "parameter2": "value2" })
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.