Skip to content

Commit e812885

Browse files
authored
enhance: workforce fail handling prompt (#3692)
1 parent 20f2e90 commit e812885

File tree

7 files changed

+60
-21
lines changed

7 files changed

+60
-21
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ body:
2626
attributes:
2727
label: What version of camel are you using?
2828
description: Run command `python3 -c 'print(__import__("camel").__version__)'` in your shell and paste the output here.
29-
placeholder: E.g., 0.2.83a7
29+
placeholder: E.g., 0.2.83a8
3030
validations:
3131
required: true
3232

camel/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from camel.logger import disable_logging, enable_logging, set_log_level
1616

17-
__version__ = '0.2.83a7'
17+
__version__ = '0.2.83a8'
1818

1919
__all__ = [
2020
'__version__',

camel/societies/workforce/prompts.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,15 @@
340340
341341
**DECISION GUIDELINES:**
342342
343-
**Priority Rules:**
344-
1. Connection/Network Errors → **retry** (almost always)
345-
2. Deep Tasks (depth > 2) → Avoid decompose, prefer **retry** or **replan**
346-
3. Worker Skill Mismatch → **reassign** (quality) or **decompose** (failure)
347-
4. Unclear Requirements → **replan** with specifics
348-
5. Task Too Complex → **decompose** into subtasks
343+
**IMPORTANT: You MUST ONLY select from the ENABLED strategies listed above.**
344+
If a strategy is not in the ENABLED list, you CANNOT use it regardless of the guidelines below.
345+
346+
**Priority Rules (apply ONLY if the strategy is ENABLED):**
347+
1. Connection/Network Errors → prefer **retry** if enabled
348+
2. Deep Tasks (depth > 2) → Avoid decompose, prefer **retry** or **replan** if enabled
349+
3. Worker Skill Mismatch → prefer **reassign** (quality) or **decompose** (failure) if enabled, otherwise use **replan**
350+
4. Unclear Requirements → prefer **replan** with specifics if enabled
351+
5. Task Too Complex → prefer **decompose** into subtasks if enabled, otherwise use **replan**
349352
350353
**RESPONSE FORMAT:**
351354
{response_format}
@@ -355,7 +358,7 @@
355358
- No explanations or text outside the JSON structure
356359
- Ensure all required fields are included
357360
- Use null for optional fields when not applicable
358-
- ONLY use strategies listed above as ENABLED
361+
- **MANDATORY: The recovery_strategy MUST be one of the ENABLED strategies listed above. Using a disabled strategy will cause an error.**
359362
"""
360363
)
361364

camel/societies/workforce/workforce.py

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4542,15 +4542,29 @@ async def _handle_failed_task(self, task: Task) -> bool:
45424542
task, for_failure=True, error_message=detailed_error
45434543
)
45444544

4545-
# Fallback to first enabled strategy if no strategy recommended
4545+
# Validate and fallback recovery strategy based on enabled_strategies
4546+
config_strategies = self.failure_handling_config.enabled_strategies
45464547
if recovery_decision.recovery_strategy is None:
4547-
config_strategies = self.failure_handling_config.enabled_strategies
4548+
# No strategy recommended - use fallback
45484549
# config_strategies is None means all enabled, use RETRY as default
45494550
# otherwise use the first enabled strategy from user's config
45504551
if config_strategies is None:
45514552
recovery_decision.recovery_strategy = RecoveryStrategy.RETRY
45524553
else:
45534554
recovery_decision.recovery_strategy = config_strategies[0]
4555+
elif config_strategies is not None:
4556+
# Strategy recommended - validate it's in enabled list
4557+
if recovery_decision.recovery_strategy not in config_strategies:
4558+
# LLM recommended a disabled strategy, use first enabled
4559+
recommended = recovery_decision.recovery_strategy.value
4560+
enabled_list = [s.value for s in config_strategies]
4561+
fallback = config_strategies[0].value
4562+
logger.warning(
4563+
f"Task {task.id}: LLM recommended '{recommended}' "
4564+
f"but it's not in enabled_strategies {enabled_list}. "
4565+
f"Using '{fallback}' instead."
4566+
)
4567+
recovery_decision.recovery_strategy = config_strategies[0]
45544568

45554569
strategy_str = recovery_decision.recovery_strategy.value
45564570
logger.info(
@@ -5308,11 +5322,12 @@ async def _listen_to_channel(self) -> None:
53085322
f"Issues: {', '.join(quality_eval.issues)}"
53095323
)
53105324

5311-
# Fallback to first enabled strategy if none
5312-
# recommended
5325+
# Validate and fallback recovery strategy based on
5326+
# enabled_strategies
5327+
config = self.failure_handling_config
5328+
config_strategies = config.enabled_strategies
53135329
if quality_eval.recovery_strategy is None:
5314-
config = self.failure_handling_config
5315-
config_strategies = config.enabled_strategies
5330+
# No strategy recommended - use fallback
53165331
if config_strategies is None:
53175332
quality_eval.recovery_strategy = (
53185333
RecoveryStrategy.RETRY
@@ -5321,6 +5336,27 @@ async def _listen_to_channel(self) -> None:
53215336
quality_eval.recovery_strategy = (
53225337
config_strategies[0]
53235338
)
5339+
elif config_strategies is not None:
5340+
# Strategy recommended - validate it's enabled
5341+
if (
5342+
quality_eval.recovery_strategy
5343+
not in config_strategies
5344+
):
5345+
# LLM recommended a disabled strategy
5346+
rec = quality_eval.recovery_strategy.value
5347+
enabled = [
5348+
s.value for s in config_strategies
5349+
]
5350+
fallback = config_strategies[0].value
5351+
logger.warning(
5352+
f"Task {returned_task.id}: LLM "
5353+
f"recommended '{rec}' but it's not in "
5354+
f"enabled_strategies {enabled}. "
5355+
f"Using '{fallback}' instead."
5356+
)
5357+
quality_eval.recovery_strategy = (
5358+
config_strategies[0]
5359+
)
53245360

53255361
# Preserve assignee before cleanup - in normal
53265362
# flow, a task must be assigned before it can fail

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
project = 'CAMEL'
2828
copyright = '2024, CAMEL-AI.org'
2929
author = 'CAMEL-AI.org'
30-
release = '0.2.83a7'
30+
release = '0.2.83a8'
3131

3232
html_favicon = (
3333
'https://raw.githubusercontent.com/camel-ai/camel/master/misc/favicon.png'

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "camel-ai"
7-
version = "0.2.83a7"
7+
version = "0.2.83a8"
88
description = "Communicative Agents for AI Society Study"
99
authors = [{ name = "CAMEL-AI.org" }]
1010
requires-python = ">=3.10,<3.15"

uv.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)