Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

Auto-update documentation after merge [skip ci]

camel-docs-bot370cfc721b5c
diff --git a/docs/mintlify/docs.json b/docs/mintlify/docs.json
index 6f59fed31..97dfb1d97 100644
--- a/docs/mintlify/docs.json
+++ b/docs/mintlify/docs.json
@@ -431,6 +431,7 @@
"reference/camel.societies.workforce.task_channel",
"reference/camel.societies.workforce.utils",
"reference/camel.societies.workforce.worker",
+ "reference/camel.societies.workforce.workflow_memory_manager",
"reference/camel.societies.workforce.workforce",
"reference/camel.societies.workforce.workforce_callback",
"reference/camel.societies.workforce.workforce_logger",
diff --git a/docs/mintlify/reference/camel.societies.workforce.single_agent_worker.mdx b/docs/mintlify/reference/camel.societies.workforce.single_agent_worker.mdx
index b0bbcc372..711ac028e 100644
--- a/docs/mintlify/reference/camel.societies.workforce.single_agent_worker.mdx
+++ b/docs/mintlify/reference/camel.societies.workforce.single_agent_worker.mdx
@@ -139,6 +139,16 @@ def _get_conversation_accumulator(self):
Get or create the conversation accumulator agent.
+<a id="camel.societies.workforce.single_agent_worker.SingleAgentWorker._get_workflow_manager"></a>
+
+### _get_workflow_manager
+
+```python
+def _get_workflow_manager(self):
+```
+
+Get or create the workflow memory manager.
+
<a id="camel.societies.workforce.single_agent_worker.SingleAgentWorker.get_pool_stats"></a>
### get_pool_stats
@@ -177,119 +187,28 @@ performance in parallel workflows.
def load_workflow_memories(
self,
pattern: Optional[str] = None,
- max_files_to_load: int = 3,
- session_id: Optional[str] = None
+ max_workflows: int = 3,
+ session_id: Optional[str] = None,
+ use_smart_selection: bool = True
):
```
-Load workflow memories matching worker description
-from saved files.
+Load workflow memories using intelligent agent-based selection.
+
+This method uses the worker agent to intelligently select the most
+relevant workflows based on metadata (title, description, tags)
+rather than simple filename pattern matching.
-This method searches for workflow memory files that match the worker's
-description and loads them into the agent's memory using
-ContextUtility.
+Delegates to WorkflowMemoryManager for all workflow operations.
**Parameters:**
-- **pattern** (Optional[str]): Custom search pattern for workflow memory files. If None, uses worker description to generate pattern.
-- **max_files_to_load** (int): Maximum number of workflow files to load. (default: :obj:`3`)
+- **pattern** (Optional[str]): Legacy parameter for backward compatibility. When use_smart_selection=False, uses this pattern for file matching. Ignored when smart selection is enabled.
+- **max_workflows** (int): Maximum number of workflow files to load. (default: :obj:`3`)
- **session_id** (Optional[str]): Specific workforce session ID to load from. If None, searches across all sessions. (default: :obj:`None`)
+- **use_smart_selection** (bool): Whether to use agent-based intelligent workflow selection. When True, uses metadata and LLM to select most relevant workflows. When False, falls back to pattern matching. (default: :obj:`True`)
**Returns:**
bool: True if workflow memories were successfully loaded, False
otherwise.
-
-<a id="camel.societies.workforce.single_agent_worker.SingleAgentWorker._find_workflow_files"></a>
-
-### _find_workflow_files
-
-```python
-def _find_workflow_files(self, pattern: Optional[str], session_id: Optional[str] = None):
-```
-
-Find and return sorted workflow files matching the pattern.
-
-**Parameters:**
-
-- **pattern** (Optional[str]): Custom search pattern for workflow files. If None, uses worker description to generate pattern.
-- **session_id** (Optional[str]): Specific session ID to search in. If None, searches across all sessions.
-
-**Returns:**
-
- List[str]: Sorted list of workflow file paths (empty if
-validation fails).
-
-<a id="camel.societies.workforce.single_agent_worker.SingleAgentWorker._load_workflow_files"></a>
-
-### _load_workflow_files
-
-```python
-def _load_workflow_files(self, workflow_files: List[str], max_files_to_load: int):
-```
-
-Load workflow files and return count of successful loads.
-
-**Parameters:**
-
-- **workflow_files** (List[str]): List of workflow file paths to load.
-
-**Returns:**
-
- int: Number of successfully loaded workflow files.
-
-<a id="camel.societies.workforce.single_agent_worker.SingleAgentWorker._validate_workflow_save_requirements"></a>
-
-### _validate_workflow_save_requirements
-
-```python
-def _validate_workflow_save_requirements(self):
-```
-
-**Returns:**
-
- Optional[Dict[str, Any]]: Error result dict if validation fails,
-None if validation passes.
-
-<a id="camel.societies.workforce.single_agent_worker.SingleAgentWorker._generate_workflow_filename"></a>
-
-### _generate_workflow_filename
-
-```python
-def _generate_workflow_filename(self):
-```
-
-**Returns:**
-
- str: Sanitized filename without timestamp and without .md
-extension. Format: \{role_name\}_workflow
-
-<a id="camel.societies.workforce.single_agent_worker.SingleAgentWorker._prepare_workflow_prompt"></a>
-
-### _prepare_workflow_prompt
-
-```python
-def _prepare_workflow_prompt(self):
-```
-
-**Returns:**
-
- str: Structured prompt for workflow summary.
-
-<a id="camel.societies.workforce.single_agent_worker.SingleAgentWorker._select_agent_for_summarization"></a>
-
-### _select_agent_for_summarization
-
-```python
-def _select_agent_for_summarization(self, context_util: ContextUtility):
-```
-
-Select the best agent for workflow summarization.
-
-**Parameters:**
-
-- **context_util**: Context utility to set on selected agent.
-
-**Returns:**
-
- ChatAgent: Agent to use for summarization.
diff --git a/docs/mintlify/reference/camel.societies.workforce.workflow_memory_manager.mdx b/docs/mintlify/reference/camel.societies.workforce.workflow_memory_manager.mdx
new file mode 100644
index 000000000..78a059976
--- /dev/null
+++ b/docs/mintlify/reference/camel.societies.workforce.workflow_memory_manager.mdx
@@ -0,0 +1,302 @@
+<a id="camel.societies.workforce.workflow_memory_manager"></a>
+
+<a id="camel.societies.workforce.workflow_memory_manager.WorkflowSelectionMethod"></a>
+
+## WorkflowSelectionMethod
+
+```python
+class WorkflowSelectionMethod(Enum):
+```
+
+Enum representing the method used to select workflows.
+
+**Parameters:**
+
+- **AGENT_SELECTED**: Agent-based intelligent selection using metadata.
+- **ROLE_NAME_MATCH**: Pattern matching by role_name.
+- **MOST_RECENT**: Fallback to most recent workflows.
+- **ALL_AVAILABLE**: Returned all workflows (fewer than max requested).
+- **NONE**: No workflows available.
+
+<a id="camel.societies.workforce.workflow_memory_manager.WorkflowMemoryManager"></a>
+
+## WorkflowMemoryManager
+
+```python
+class WorkflowMemoryManager:
+```
+
+Manages workflow memory operations for workforce workers.
+
+This class encapsulates all workflow memory functionality including
+intelligent loading, saving, and selection of workflows. It separates
+workflow management concerns from the core worker task processing logic.
+
+**Parameters:**
+
+- **worker** (ChatAgent): The worker agent that will use workflows.
+- **description** (str): Description of the worker's role.
+- **context_utility** (Optional[ContextUtility]): Shared context utility for workflow operations. If None, creates a new instance.
+
+<a id="camel.societies.workforce.workflow_memory_manager.WorkflowMemoryManager.__init__"></a>
+
+### __init__
+
+```python
+def __init__(
+ self,
+ worker: ChatAgent,
+ description: str,
+ context_utility: Optional[ContextUtility] = None
+):
+```
+
+<a id="camel.societies.workforce.workflow_memory_manager.WorkflowMemoryManager._get_context_utility"></a>
+
+### _get_context_utility
+
+```python
+def _get_context_utility(self):
+```
+
+Get context utility with lazy initialization.
+
+<a id="camel.societies.workforce.workflow_memory_manager.WorkflowMemoryManager.load_workflows"></a>
+
+### load_workflows
+
+```python
+def load_workflows(
+ self,
+ pattern: Optional[str] = None,
+ max_files_to_load: int = 3,
+ session_id: Optional[str] = None,
+ use_smart_selection: bool = True
+):
+```
+
+Load workflow memories using intelligent agent-based selection.
+
+This method uses the worker agent to intelligently select the most
+relevant workflows based on workflow information (title, description,
+tags) rather than simple filename pattern matching.
+
+**Parameters:**
+
+- **pattern** (Optional[str]): Legacy parameter for backward compatibility. When use_smart_selection=False, uses this pattern for file matching. Ignored when smart selection is enabled.
+- **max_files_to_load** (int): Maximum number of workflow files to load. (default: :obj:`3`)
+- **session_id** (Optional[str]): Specific workforce session ID to load from. If None, searches across all sessions. (default: :obj:`None`)
+- **use_smart_selection** (bool): Whether to use agent-based intelligent workflow selection. When True, uses workflow information and LLM to select most relevant workflows. When False, falls back to pattern matching. (default: :obj:`True`)
+
+**Returns:**
+
+ bool: True if workflow memories were successfully loaded, False
+otherwise.
+
+<a id="camel.societies.workforce.workflow_memory_manager.WorkflowMemoryManager.save_workflow"></a>
+
+### save_workflow
+
+```python
+def save_workflow(self, conversation_accumulator: Optional[ChatAgent] = None):
+```
+
+Save the worker's current workflow memories using agent
+summarization.
+
+This method generates a workflow summary from the worker agent's
+conversation history and saves it to a markdown file.
+
+**Parameters:**
+
+- **conversation_accumulator** (Optional[ChatAgent]): Optional accumulator agent with collected conversations. If provided, uses this instead of the main worker agent.
+
+**Returns:**
+
+ Dict[str, Any]: Result dictionary with keys:
+- status (str): "success" or "error"
+- summary (str): Generated workflow summary
+- file_path (str): Path to saved file
+- worker_description (str): Worker description used
+
+<a id="camel.societies.workforce.workflow_memory_manager.WorkflowMemoryManager._select_relevant_workflows"></a>
+
+### _select_relevant_workflows
+
+```python
+def _select_relevant_workflows(
+ self,
+ workflows_metadata: List[Dict[str, Any]],
+ max_files: int,
+ session_id: Optional[str] = None
+):
+```
+
+Use worker agent to select most relevant workflows.
+
+This method creates a prompt with all available workflow information
+and uses the worker agent to intelligently select the most relevant
+workflows based on the worker's role and description.
+
+**Parameters:**
+
+- **workflows_metadata** (List[Dict[str, Any]]): List of workflow information dicts (contains title, description, tags, file_path).
+- **max_files** (int): Maximum number of workflows to select.
+- **session_id** (Optional[str]): Specific workforce session ID to search in for fallback pattern matching. If None, searches across all sessions. (default: :obj:`None`)
+
+**Returns:**
+
+ tuple[List[str], WorkflowSelectionMethod]: Tuple of (selected
+workflow file paths, selection method used).
+
+<a id="camel.societies.workforce.workflow_memory_manager.WorkflowMemoryManager._format_workflows_for_selection"></a>
+
+### _format_workflows_for_selection
+
+```python
+def _format_workflows_for_selection(self, workflows_metadata: List[Dict[str, Any]]):
+```
+
+Format workflow information into a readable prompt for selection.
+
+**Parameters:**
+
+- **workflows_metadata** (List[Dict[str, Any]]): List of workflow information dicts (contains title, description, tags, file_path).
+
+**Returns:**
+
+ str: Formatted string presenting workflows for LLM selection.
+
+<a id="camel.societies.workforce.workflow_memory_manager.WorkflowMemoryManager._find_workflow_files"></a>
+
+### _find_workflow_files
+
+```python
+def _find_workflow_files(self, pattern: Optional[str], session_id: Optional[str] = None):
+```
+
+Find and return sorted workflow files matching the pattern.
+
+**Parameters:**
+
+- **pattern** (Optional[str]): Custom search pattern for workflow files. If None, uses worker role_name to generate pattern.
+- **session_id** (Optional[str]): Specific session ID to search in. If None, searches across all sessions.
+
+**Returns:**
+
+ List[str]: Sorted list of workflow file paths (empty if
+validation fails).
+
+<a id="camel.societies.workforce.workflow_memory_manager.WorkflowMemoryManager._collect_workflow_contents"></a>
+
+### _collect_workflow_contents
+
+```python
+def _collect_workflow_contents(self, workflow_files: List[str]):
+```
+
+Collect and load workflow file contents.
+
+**Parameters:**
+
+- **workflow_files** (List[str]): List of workflow file paths to load.
+
+**Returns:**
+
+ List[Dict[str, str]]: List of dicts with 'filename' and
+'content' keys.
+
+<a id="camel.societies.workforce.workflow_memory_manager.WorkflowMemoryManager._format_workflows_for_context"></a>
+
+### _format_workflows_for_context
+
+```python
+def _format_workflows_for_context(self, workflows_to_load: List[Dict[str, str]]):
+```
+
+Format workflows into a context string for the agent.
+
+**Parameters:**
+
+- **workflows_to_load** (List[Dict[str, str]]): List of workflow dicts with 'filename' and 'content' keys.
+
+**Returns:**
+
+ str: Formatted workflow context string with header and all
+workflows.
+
+<a id="camel.societies.workforce.workflow_memory_manager.WorkflowMemoryManager._add_workflows_to_system_message"></a>
+
+### _add_workflows_to_system_message
+
+```python
+def _add_workflows_to_system_message(self, workflow_context: str):
+```
+
+Add workflow context to agent's system message.
+
+**Parameters:**
+
+- **workflow_context** (str): The formatted workflow context to add.
+
+**Returns:**
+
+ bool: True if successful, False otherwise.
+
+<a id="camel.societies.workforce.workflow_memory_manager.WorkflowMemoryManager._load_workflow_files"></a>
+
+### _load_workflow_files
+
+```python
+def _load_workflow_files(self, workflow_files: List[str], max_workflows: int):
+```
+
+Load workflow files and return count of successful loads.
+
+Loads all workflows together with a single header to avoid repetition.
+
+**Parameters:**
+
+- **workflow_files** (List[str]): List of workflow file paths to load.
+- **max_workflows** (int): Maximum number of workflows to load.
+
+**Returns:**
+
+ int: Number of successfully loaded workflow files.
+
+<a id="camel.societies.workforce.workflow_memory_manager.WorkflowMemoryManager._get_sanitized_role_name"></a>
+
+### _get_sanitized_role_name
+
+```python
+def _get_sanitized_role_name(self):
+```
+
+**Returns:**
+
+ str: Sanitized role name suitable for use in filenames.
+
+<a id="camel.societies.workforce.workflow_memory_manager.WorkflowMemoryManager._generate_workflow_filename"></a>
+
+### _generate_workflow_filename
+
+```python
+def _generate_workflow_filename(self):
+```
+
+**Returns:**
+
+ str: Sanitized filename without timestamp and without .md
+extension. Format: \{role_name\}_workflow
+
+<a id="camel.societies.workforce.workflow_memory_manager.WorkflowMemoryManager._prepare_workflow_prompt"></a>
+
+### _prepare_workflow_prompt
+
+```python
+def _prepare_workflow_prompt(self):
+```
+
+**Returns:**
+
+ str: Structured prompt for workflow summary.
diff --git a/docs/mintlify/reference/camel.societies.workforce.workforce.mdx b/docs/mintlify/reference/camel.societies.workforce.workforce.mdx
index a70dcbe05..06d08e419 100644
--- a/docs/mintlify/reference/camel.societies.workforce.workforce.mdx
+++ b/docs/mintlify/reference/camel.societies.workforce.workforce.mdx
@@ -773,8 +773,10 @@ processing for significantly better performance.
```python
def load_workflow_memories(
self,
- max_files_to_load: int = 3,
- session_id: Optional[str] = None
+ session_id: Optional[str] = None,
+ worker_max_workflows: int = 3,
+ coordinator_max_workflows: int = 5,
+ task_agent_max_workflows: int = 3
):
```
@@ -788,8 +790,10 @@ method. Workers match files based on their description names.
**Parameters:**
-- **max_files_to_load** (int): Maximum number of workflow files to load per worker. (default: :obj:`3`)
- **session_id** (Optional[str]): Specific workforce session ID to load from. If None, searches across all sessions. (default: :obj:`None`)
+- **worker_max_workflows** (int): Maximum number of workflow files to load per worker agent. (default: :obj:`3`)
+- **coordinator_max_workflows** (int): Maximum number of workflow files to load for the coordinator agent. (default: :obj:`5`)
+- **task_agent_max_workflows** (int): Maximum number of workflow files to load for the task planning agent. (default: :obj:`3`)
**Returns:**
@@ -802,7 +806,12 @@ True indicates successful loading, False indicates failure.
### _load_management_agent_workflows
```python
-def _load_management_agent_workflows(self, max_files_to_load: int, session_id: Optional[str] = None):
+def _load_management_agent_workflows(
+ self,
+ coordinator_max_workflows: int,
+ task_agent_max_workflows: int,
+ session_id: Optional[str] = None
+):
```
Load workflow summaries for coordinator and task planning agents.
@@ -815,7 +824,8 @@ successful strategies
**Parameters:**
-- **max_files_to_load** (int): Maximum number of workflow files to load.
+- **coordinator_max_workflows** (int): Maximum number of workflow files to load for the coordinator agent.
+- **task_agent_max_workflows** (int): Maximum number of workflow files to load for the task planning agent.
- **session_id** (Optional[str]): Specific session ID to load from. If None, searches across all sessions.
<a id="camel.societies.workforce.workforce.Workforce.set_channel"></a>
diff --git a/docs/mintlify/reference/camel.utils.context_utils.mdx b/docs/mintlify/reference/camel.utils.context_utils.mdx
index 8f9745e5c..6fbec3ee6 100644
--- a/docs/mintlify/reference/camel.utils.context_utils.mdx
+++ b/docs/mintlify/reference/camel.utils.context_utils.mdx
@@ -458,6 +458,52 @@ Filter out metadata section from markdown content.
str: Content with metadata section removed.
+<a id="camel.utils.context_utils.ContextUtility.extract_workflow_info"></a>
+
+### extract_workflow_info
+
+```python
+def extract_workflow_info(self, file_path: str):
+```
+
+Extract info from a workflow markdown file.
+
+This method reads only the essential info from a workflow file
+(title, description, tags) for use in workflow selection without
+loading the entire workflow content.
+
+**Parameters:**
+
+- **file_path** (str): Full path to the workflow markdown file.
+
+**Returns:**
+
+ Dict[str, Any]: Workflow info including title, description,
+tags, and file_path. Returns empty dict on error.
+
+<a id="camel.utils.context_utils.ContextUtility.get_all_workflows_info"></a>
+
+### get_all_workflows_info
+
+```python
+def get_all_workflows_info(self, session_id: Optional[str] = None):
+```
+
+Get info from all workflow files in workforce_workflows.
+
+This method scans the workforce_workflows directory for workflow
+markdown files and extracts their info for use in workflow
+selection.
+
+**Parameters:**
+
+- **session_id** (Optional[str]): If provided, only return workflows from this specific session. If None, returns workflows from all sessions.
+
+**Returns:**
+
+ List[Dict[str, Any]]: List of workflow info dicts, sorted
+by session timestamp (newest first).
+
<a id="camel.utils.context_utils.ContextUtility.get_workforce_shared"></a>
### get_workforce_shared