Overview

The update_step function allows you to modify an existing step’s information while it’s still active. This is useful for tracking progress, updating evaluations, or adding information discovered during execution.

Syntax

lai.update_step(
    step_id: Optional[str] = None,
    state: Optional[str] = None,
    action: Optional[str] = None,
    goal: Optional[str] = None,
    eval_score: Optional[float] = None,
    eval_description: Optional[str] = None,
    screenshot: Optional[str] = None,
    screenshot_path: Optional[str] = None
) -> None

Parameters

step_id
string
The ID of the step to update. If not provided, updates the current active step.
state
string
Updated description of the current state or context.
action
string
Updated description of what action the agent is taking.
goal
string
Updated description of what the agent aims to achieve.
eval_score
float
Updated evaluation score (typically 0.0 to 1.0).
eval_description
string
Updated text description of the evaluation.
screenshot
string
Base64-encoded screenshot to add or replace. Provide either this or screenshot_path.
screenshot_path
string
Path to a screenshot file. Provide either this or screenshot.

Returns

This function returns None.

Examples

Basic Progress Update

import lucidicai as lai

lai.init(session_name="Data Processing")

# Create initial step
lai.create_step(
    state="Starting data processing",
    action="Load and validate dataset",
    eval_score=0.0
)

# Update as processing progresses
for i, batch in enumerate(data_batches):
    process_batch(batch)
    progress = (i + 1) / len(data_batches)
    
    lai.update_step(
        eval_score=progress,
        eval_description=f"Processed {i+1}/{len(data_batches)} batches"
    )

lai.end_step()

Updating Based on Results

import lucidicai as lai

lai.init(session_name="Model Training")

step_id = lai.create_step(
    state="Model initialized",
    action="Train model on dataset",
    goal="Achieve >90% accuracy"
)

# Train model
model = train_model(data)
accuracy = evaluate_model(model)

# Update step based on results
if accuracy > 0.9:
    lai.update_step(
        step_id=step_id,
        eval_score=1.0,
        eval_description=f"Success! Achieved {accuracy:.2%} accuracy"
    )
else:
    lai.update_step(
        step_id=step_id,
        eval_score=accuracy,
        eval_description=f"Accuracy {accuracy:.2%} below target"
    )

lai.end_step()

Adding Screenshots During Execution

import lucidicai as lai

lai.init(session_name="UI Automation")

# Create step
lai.create_step(
    state="Browser opened",
    action="Navigate through checkout flow",
    goal="Complete purchase successfully"
)

# Navigate and capture screenshots at key points
navigate_to_cart()
lai.update_step(
    state="Cart page loaded",
    screenshot_path="/tmp/cart_screenshot.png"
)

fill_shipping_info()
lai.update_step(
    state="Shipping info completed",
    screenshot_path="/tmp/shipping_screenshot.png"
)

complete_payment()
lai.update_step(
    state="Payment processed",
    eval_score=1.0,
    eval_description="Checkout completed successfully",
    screenshot_path="/tmp/confirmation_screenshot.png"
)

lai.end_step()

Using with Decorators

import lucidicai as lai
from lucidicai.decorators import get_decorator_step

@lai.step(state="Initial state", action="Process data")
def process_with_updates(data: dict) -> dict:
    # Get the current step ID
    step_id = get_decorator_step()
    
    # Update as processing happens
    lai.update_step(
        step_id=step_id,
        state="Validation phase",
        eval_score=0.3
    )
    
    validated = validate_data(data)
    
    lai.update_step(
        step_id=step_id,
        state="Transformation phase",
        eval_score=0.7
    )
    
    result = transform_data(validated)
    
    # Final update
    lai.update_step(
        step_id=step_id,
        eval_score=1.0,
        eval_description="Processing completed successfully"
    )
    
    return result

Notes

  • Can only update active (not ended) steps
  • If step_id is not provided, updates the current active step
  • Updates are incremental - only provided fields are updated
  • Multiple updates can be made to the same step
  • Screenshot updates replace previous screenshots

Error Handling

from lucidicai.errors import InvalidOperationError

try:
    lai.update_step(eval_score=0.5)
except InvalidOperationError:
    print("No active step to update")

Best Practices

  1. Progress Tracking: Use eval_score to show progress (0.0 to 1.0)
  2. State Evolution: Update state description as context changes
  3. Meaningful Updates: Only update when there’s significant new information
  4. Final Evaluation: Always update eval_score before ending the step

See Also