camel-ai 0.2.76a13__py3-none-any.whl → 0.2.77__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of camel-ai might be problematic. Click here for more details.

@@ -70,16 +70,25 @@ class AlpacaDataCollector(BaseDataCollector):
70
70
  if not history:
71
71
  raise ValueError("No data collected.")
72
72
 
73
- # Validate and process history
74
- if len(history) == 3 and history[0].role == "system":
75
- history = history[1:] # Ignore the system message.
76
- elif len(history) != 2:
73
+ # Filter out system and tool-related messages
74
+ # Keep only user and final assistant messages
75
+ filtered_history = []
76
+ for msg in history:
77
+ if msg.role == "user":
78
+ filtered_history.append(msg)
79
+ elif msg.role == "assistant" and msg.message:
80
+ # Keep assistant messages with actual content
81
+ # (skip empty ones that only contain tool calls)
82
+ filtered_history.append(msg)
83
+
84
+ # Validate filtered history
85
+ if len(filtered_history) != 2:
77
86
  raise ValueError(
78
87
  f"AlpacaDataCollector only supports one message pair, but "
79
- f"got {len(history)}"
88
+ f"got {len(filtered_history)} after filtering tool messages"
80
89
  )
81
90
 
82
- input_message, output_message = history
91
+ input_message, output_message = filtered_history
83
92
  instruction = (
84
93
  self.system_message.content if self.system_message else ""
85
94
  ) + str(input_message.message)
@@ -293,58 +293,139 @@ Each subtask should be:
293
293
  - Written without any relative references (e.g., "the previous task").
294
294
  """
295
295
 
296
- FAILURE_ANALYSIS_PROMPT = TextPrompt(
297
- """You need to analyze a task failure and decide on the best recovery strategy.
298
-
299
- **TASK FAILURE DETAILS:**
300
- Task ID: {task_id}
301
- Task Content: {task_content}
302
- Failure Count: {failure_count}/3
303
- Error Message: {error_message}
304
- Worker ID: {worker_id}
305
- Task Depth: {task_depth}
306
- Additional Info: {additional_info}
307
-
308
- **AVAILABLE RECOVERY STRATEGIES:**
309
-
310
- 1. **RETRY**: Attempt the same task again without changes
311
- - Use for: Network errors, temporary API issues, random failures
312
- - Avoid for: Fundamental task misunderstanding, capability gaps
313
-
314
- 2. **REPLAN**: Modify the task content to address the underlying issue
315
- - Use for: Unclear requirements, insufficient context, correctable errors
316
- - Provide: Modified task content that addresses the failure cause
317
- - **CRITICAL**: The replanned task MUST be a clear, actionable
318
- instruction for an AI agent, not a question or request for a human.
319
-
320
- 3. **DECOMPOSE**: Break the task into smaller, more manageable subtasks
321
- - Use for: Complex tasks, capability mismatches, persistent failures
322
- - Consider: Whether the task is too complex for a single worker
323
-
324
- 4. **CREATE_WORKER**: Create a new worker node to handle the task
325
- - Use for: Fundamental task misunderstanding, capability gaps
326
-
327
- **ANALYSIS GUIDELINES:**
328
-
329
- - **Connection/Network Errors**: Almost always choose RETRY
330
- - **Model Processing Errors**: Consider REPLAN if the task can be clarified, otherwise DECOMPOSE
331
- - **Capability Gaps**: Choose DECOMPOSE to break into simpler parts. If a
332
- replan can work, ensure the new task is a command for an agent, not a
333
- request to a user.
334
- - **Ambiguous Requirements**: Choose REPLAN with clearer instructions
335
- - **High Failure Count**: Lean towards DECOMPOSE rather than repeated retries
336
- - **Deep Tasks (depth > 2)**: Prefer RETRY or REPLAN over further
337
- decomposition
296
+ TASK_ANALYSIS_PROMPT = TextPrompt(
297
+ """You are analyzing a task to evaluate its quality and determine recovery actions if needed.
298
+
299
+ **TASK INFORMATION:**
300
+ - Task ID: {task_id}
301
+ - Task Content: {task_content}
302
+ - Task Result: {task_result}
303
+ - Failure Count: {failure_count}
304
+ - Task Depth: {task_depth}
305
+ - Assigned Worker: {assigned_worker}
306
+
307
+ **ISSUE TYPE: {issue_type}**
308
+
309
+ {issue_specific_analysis}
310
+
311
+ **STEP 1: EVALUATE TASK QUALITY**
312
+
313
+ First, assess whether the task was completed successfully and meets quality standards:
314
+
315
+ **For Task Failures (with error messages):**
316
+ - The task did not complete successfully
317
+ - An error occurred during execution
318
+ - Quality is automatically insufficient
319
+ - Focus on analyzing the error cause
320
+
321
+ **For Quality Issues (task completed but needs evaluation):**
322
+ Evaluate the task result based on these criteria:
323
+ 1. **Completeness**: Does the result fully address all task requirements?
324
+ 2. **Accuracy**: Is the result correct and well-structured?
325
+ 3. **Missing Elements**: Are there any missing components or quality issues?
326
+
327
+ Provide:
328
+ - Quality score (0-100): Objective assessment of result quality
329
+ - Specific issues list: Any problems found in the result
330
+ - Quality sufficient: Boolean indicating if quality meets standards
331
+
332
+ **STEP 2: DETERMINE RECOVERY STRATEGY (if quality insufficient)**
333
+
334
+ If the task quality is insufficient, select the best recovery strategy:
335
+
336
+ **Available Strategies:**
337
+
338
+ 1. **retry** - Retry with the same worker and task content
339
+ - **Best for**:
340
+ * Network errors, connection timeouts, temporary API issues
341
+ * Random failures that are likely temporary
342
+ * Minor quality issues that may resolve on retry
343
+ - **Not suitable for**:
344
+ * Fundamental task misunderstandings
345
+ * Worker capability gaps
346
+ * Persistent quality problems
347
+
348
+ 2. **reassign** - Assign to a different worker
349
+ - **Best for**:
350
+ * Current worker lacks required skills/expertise
351
+ * Worker-specific quality issues
352
+ * Task requires different specialization
353
+ - **Not suitable for**:
354
+ * Task description is unclear (use replan instead)
355
+ * Task is too complex (use decompose instead)
356
+ - **Note**: Only available for quality issues, not failures
357
+
358
+ 3. **replan** - Modify task content with clearer instructions
359
+ - **Best for**:
360
+ * Unclear or ambiguous requirements
361
+ * Missing context or information
362
+ * Task description needs improvement
363
+ - **Requirements**:
364
+ * Provide modified_task_content with enhanced, clear instructions
365
+ * Modified task must be actionable for an AI agent
366
+ * Address the root cause identified in issues
367
+
368
+ 4. **decompose** - Break into smaller, manageable subtasks
369
+ - **Best for**:
370
+ * Task is too complex for a single worker
371
+ * Multiple distinct sub-problems exist
372
+ * Persistent failures despite retries
373
+ * Capability mismatches that need specialization
374
+ - **Consider**:
375
+ * Task depth (avoid if depth > 2)
376
+ * Whether subtasks can run in parallel
377
+
378
+ 5. **create_worker** - Create new specialized worker
379
+ - **Best for**:
380
+ * No existing worker has required capabilities
381
+ * Need specialized skills not currently available
382
+ - **Consider**:
383
+ * Whether decomposition could work instead
384
+ * Cost of creating new worker vs alternatives
385
+ - **Note**: Only available for task failures, not quality issues
386
+
387
+ **DECISION GUIDELINES:**
388
+
389
+ **Priority Rules:**
390
+ 1. Connection/Network Errors → **retry** (almost always)
391
+ 2. Deep Tasks (depth > 2) → Avoid decompose, prefer **retry** or **replan**
392
+ 3. Worker Skill Mismatch → **reassign** (quality) or **decompose** (failure)
393
+ 4. Unclear Requirements → **replan** with specifics
394
+ 5. Task Too Complex → **decompose** into subtasks
338
395
 
339
396
  **RESPONSE FORMAT:**
340
- You must return a valid JSON object with these fields:
341
- - "strategy": one of "retry", "replan", or "decompose"
342
- - "reasoning": explanation for your choice (1-2 sentences)
343
- - "modified_task_content": new task content if strategy is "replan", null otherwise
397
+ {response_format}
344
398
 
345
- **Example Response:**
346
- {{"strategy": "retry", "reasoning": "The connection error appears to be temporary and network-related, a simple retry should resolve this.", "modified_task_content": null}}
347
-
348
- **CRITICAL**: Return ONLY the JSON object. No explanations or text outside the JSON structure.
399
+ **CRITICAL**:
400
+ - Return ONLY a valid JSON object
401
+ - No explanations or text outside the JSON structure
402
+ - Ensure all required fields are included
403
+ - Use null for optional fields when not applicable
349
404
  """
350
405
  )
406
+
407
+ FAILURE_ANALYSIS_RESPONSE_FORMAT = """JSON format:
408
+ {
409
+ "reasoning": "explanation (1-2 sentences)",
410
+ "recovery_strategy": "retry|replan|decompose|create_worker",
411
+ "modified_task_content": "new content if replan, else null",
412
+ "issues": ["error1", "error2"]
413
+ }"""
414
+
415
+ QUALITY_EVALUATION_RESPONSE_FORMAT = """JSON format:
416
+ {
417
+ "quality_score": 0-100,
418
+ "reasoning": "explanation (1-2 sentences)",
419
+ "issues": ["issue1", "issue2"],
420
+ "recovery_strategy": "retry|reassign|replan|decompose or null",
421
+ "modified_task_content": "new content if replan, else null"
422
+ }"""
423
+
424
+ TASK_AGENT_SYSTEM_MESSAGE = """You are an intelligent task management assistant responsible for planning, analyzing, and quality control.
425
+
426
+ Your responsibilities include:
427
+ 1. **Task Decomposition**: Breaking down complex tasks into manageable subtasks that can be executed efficiently and in parallel when possible.
428
+ 2. **Failure Analysis**: Analyzing task failures to determine the root cause and recommend appropriate recovery strategies (retry, replan, decompose, or create new worker).
429
+ 3. **Quality Evaluation**: Assessing completed task results to ensure they meet quality standards and recommending recovery strategies if quality is insufficient (retry, reassign, replan, or decompose).
430
+
431
+ You must provide structured, actionable analysis based on the task context, failure history, worker capabilities, and quality criteria. Your decisions directly impact the efficiency and success of the workforce system."""