Overview

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

Syntax

lai.update_event(
    event_id: Optional[str] = None,
    description: Optional[str] = None,
    result: Optional[str] = None,
    cost_added: Optional[float] = None,
    model: Optional[str] = None,
    screenshots: Optional[List[str]] = None
) -> None

Parameters

event_id
string
The ID of the event to update. If not provided, updates the most recent event in the current step.
description
string
Updated description of the event.
result
string
Updated result or outcome of the event.
cost_added
float
Updated cost for the event.
model
string
Updated model or service identifier.
screenshots
List[str]
Updated list of screenshots. Each screenshot should be provided as a file path (which will be read and uploaded) or as base64-encoded image data.

Returns

This function returns None.

Examples

Progress Updates

import lucidicai as lai

lai.init(session_name="Progress Tracking")

lai.create_step(state="Data processing", action="Analyze dataset")

# Create initial event
event_id = lai.create_event(
    description="Starting data analysis",
    model="analyzer-v1"
)

# Update as processing progresses
for i in range(10):
    process_batch(i)
    
    lai.update_event(
        event_id=event_id,
        result=f"Processed {i+1}/10 batches"
    )

# Final update
lai.update_event(
    event_id=event_id,
    result="All batches processed successfully",
    cost_added=0.05
)

lai.end_step()

Adding Details During Execution

import lucidicai as lai

lai.init(session_name="Dynamic Updates")

lai.create_step(state="API integration", action="Fetch and process data")

# Create event
event_id = lai.create_event(
    description="Calling external API",
    model="external-api-v2"
)

# Make API call
response = call_external_api()

# Update with response info
lai.update_event(
    event_id=event_id,
    result=f"Received {len(response.data)} records",
    cost_added=response.billing_info.cost
)

# Process data
processed = process_response(response)

# Update again with processing results
lai.update_event(
    event_id=event_id,
    result=f"Processed {len(processed)} valid records from {len(response.data)} total"
)

lai.end_step()

Screenshot Updates

import lucidicai as lai

lai.init(session_name="Visual Processing")

lai.create_step(state="UI automation", action="Navigate application")

# Create event for UI interaction
event_id = lai.create_event(
    description="Navigating through application flow"
)

# Take initial screenshot
initial_screenshot = capture_screenshot()
lai.update_event(
    event_id=event_id,
    screenshots=[encode_base64(initial_screenshot)]
)

# Navigate and update
navigate_to_page("settings")
settings_screenshot = capture_screenshot()

lai.update_event(
    event_id=event_id,
    result="Navigated to settings page",
    screenshots=[
        encode_base64(initial_screenshot),
        encode_base64(settings_screenshot)
    ]
)

lai.end_step()

Cost Accumulation

import lucidicai as lai

lai.init(session_name="Cost Tracking")

lai.create_step(state="Multi-service operation", action="Use various APIs")

# Track cumulative costs
event_id = lai.create_event(
    description="Multi-service workflow",
    cost_added=0.0
)

total_cost = 0.0

# Service 1
cost1 = use_translation_service()
total_cost += cost1
lai.update_event(event_id=event_id, cost_added=total_cost)

# Service 2
cost2 = use_sentiment_analysis()
total_cost += cost2
lai.update_event(event_id=event_id, cost_added=total_cost)

# Service 3
cost3 = use_summarization()
total_cost += cost3
lai.update_event(
    event_id=event_id,
    cost_added=total_cost,
    result=f"Completed all services. Total cost: ${total_cost:.3f}"
)

lai.end_step()

Auto-Update Latest Event

import lucidicai as lai

lai.init(session_name="Quick Updates")

lai.create_step(state="Processing", action="Execute tasks")

# Create events
lai.create_event(description="Task 1")
lai.create_event(description="Task 2")
lai.create_event(description="Task 3")  # This is the latest

# Update the latest event (Task 3)
lai.update_event(
    result="Task 3 completed with warnings",
    model="task-processor-v3"
)

lai.end_step()

Notes

  • Can only update active (not ended) events
  • If event_id is not provided, updates the most recent event
  • Updates are incremental - only provided fields are updated
  • Multiple updates can be made to the same event
  • Screenshot updates replace the entire screenshot list

Error Handling

from lucidicai.errors import InvalidOperationError

try:
    lai.update_event(
        event_id="non-existent-id",
        result="This will fail"
    )
except InvalidOperationError:
    print("Event not found or already ended")

# Updating without active events
try:
    lai.update_event(result="No events to update")
except Exception:
    print("No active events in current step")

Best Practices

  1. Incremental Updates: Update events as information becomes available
  2. Cost Tracking: Keep costs updated for accurate billing
  3. Progress Indication: Use result field to show progress
  4. Error Context: Update with error information if failures occur
  5. Meaningful Updates: Only update when there’s new information

See Also