ConstraintSatisfactionTask
Solves complex problems with multiple competing constraints using systematic search strategies, providing detailed reasoning and trade-off analysis.
{
"problem_description": "Allocate 5 microservices across 3 regions.",
"input_files": ["infrastructure/regions.yaml"],
"hard_constraints": [
"Region A must have at least 2 services",
"Total latency < 100ms"
],
"soft_constraints": {
"Cost Optimization": 0.8,
"High Availability": 0.6
},
"search_strategy": "backtracking",
"max_iterations": 50,
"related_files": ["docs/architecture.md"]
}
Solution Overview
Optimal allocation found using backtracking. Region A hosts Service 1 & 2. Region B hosts Service 3 & 4. Region C hosts Service 5.
- Latency: 84ms (Target < 100ms)
High Availability: 0.75 / 1.0
Live Results Showcase
Explore actual artifacts generated by this task in the test workspace.
| Field | Type | Description |
|---|---|---|
problem_description* |
String | The problem requiring constraint satisfaction. Be specific about the goals and constraints. |
input_files |
List<String> | The specific files (or file patterns, e.g. **/*.kt) to be used as input for the task. |
hard_constraints |
List<String> | Constraints that must be satisfied (cannot be violated). |
soft_constraints |
Map<String, Double> | Constraints to optimize with weights (0.0-1.0). |
search_strategy |
String | 'backtracking' (systematic), 'forward' (greedy), or 'local' (hill-climbing). Default: backtracking. |
max_iterations |
Int | Maximum search iterations before returning best solution. Default: 100. |
related_files |
List<String> | Additional files for context. |
Token Usage: Medium. Consumption scales with the number of constraints and the size of input files provided for context.
1. Initialization & Validation
The task validates that problem_description is present, search_strategy is valid, and all soft_constraints weights are between 0.0 and 1.0.
2. Context Gathering
Collects results from prior tasks and reads content from specified input_files and related_files to build a comprehensive problem context.
3. Execution
Uses a ChatAgent with a specialized CSP prompt to identify decision variables, formulate the CSP, and apply the chosen search strategy (Backtracking, Forward, or Local).
4. Finalization
Generates a detailed solution transcript (Markdown/HTML/PDF) and presents the final solution in a tabbed UI for user review.
Embedded Usage (Scenario B)
Invoke this task directly using the UnifiedHarness in a headless environment.
val harness = UnifiedHarness(serverless = true, ...)
harness.start()
val executionConfig = ConstraintSatisfactionTaskExecutionConfigData(
problem_description = "Optimize resource allocation for high-traffic API",
hard_constraints = listOf("Latency < 50ms", "Redundancy > 2"),
soft_constraints = mapOf("Cost" to 0.9, "Ease of Maintenance" to 0.4),
search_strategy = "backtracking"
)
harness.runTask(
taskType = ConstraintSatisfactionTask.ConstraintSatisfaction,
typeConfig = TaskTypeConfig(),
executionConfig = executionConfig,
workspace = File("./project-dir"),
autoFix = true
)
Kotlin Boilerplate (Orchestration)
val task = ConstraintSatisfactionTask(
orchestrationConfig = config,
planTask = ConstraintSatisfactionTaskExecutionConfigData(
problem_description = "Optimize resource allocation",
hard_constraints = listOf("Budget < 1000"),
search_strategy = "backtracking"
)
)
Prompt Segment
The following text is injected into the LLM context:
### ConstraintSatisfaction
Solves complex problems with multiple competing constraints using various search strategies.
- **Use when**: You need to balance hard requirements with weighted soft preferences (e.g., architecture, scheduling).
- **Inputs**: Problem description, hard/soft constraints, and optional file context.
- **Strategies**:
- `backtracking`: Systematic search for guaranteed satisfaction.
- `forward`: Greedy approach for speed.
- `local`: Hill-climbing for optimization in large search spaces.