Features
Headless Mode
Run AI coding tasks asynchronously
The Local SDK provides a headless (asynchronous) mode for running AI coding tasks in the background without blocking your application.
Headless Methods
Starting a Headless Task
Starts an asynchronous coding task that runs in the background.
Parameters:
- prompt (
str
): Natural language instruction for the AI - editable_files (
List[str]
): Paths to files the AI may modify - readonly_files (
List[str]
, optional): Paths to files the AI may read but not change - task_id (
str
, optional): Custom identifier for the task
Returns:
Checking Task Status
Queries the status and result of a previously started headless task.
Parameters:
- task_id (
str
): The task identifier returned bycode_headless()
Returns a dictionary with different fields depending on the status:
For pending tasks:
For completed tasks:
For failed tasks:
If the task is not found:
Quick Headless Example
Run the real headless example script included in the examples:
This script will:
- Create
src/calculator.py
- Start an asynchronous coding task with
code_headless()
- Poll for status and print the diff when completed
Advanced Usage
Tracking Multiple Tasks
Integration with Web Applications
Here’s how you might use headless mode in a web application:
Best Practices
Task Management
- Generate unique task IDs if not provided
- Store task information for later reference
- Implement timeouts for polling to avoid infinite loops
- Use a proper task queue system for production applications
Error Handling
Performance Considerations
- For CPU-bound applications, limit the number of concurrent tasks
- Consider using a task queue system like Celery for production use
- Implement rate limiting to avoid exceeding API rate limits
- Store task results in a database for persistence