🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
Auto-update documentation after merge
camel-docs-botbb428786fecb
diff --git a/docs/mintlify/docs.json b/docs/mintlify/docs.jsonindex 3909b38c1..ff46bc134 100644--- a/docs/mintlify/docs.json+++ b/docs/mintlify/docs.json@@ -412,6 +412,7 @@"reference/camel.societies.workforce.base","reference/camel.societies.workforce.role_playing_worker","reference/camel.societies.workforce.single_agent_worker",+ "reference/camel.societies.workforce.structured_output_handler","reference/camel.societies.workforce.task_channel","reference/camel.societies.workforce.utils","reference/camel.societies.workforce.worker",diff --git a/docs/mintlify/reference/camel.societies.workforce.role_playing_worker.mdx b/docs/mintlify/reference/camel.societies.workforce.role_playing_worker.mdxindex 24fa97da1..cb8fbba42 100644--- a/docs/mintlify/reference/camel.societies.workforce.role_playing_worker.mdx+++ b/docs/mintlify/reference/camel.societies.workforce.role_playing_worker.mdx@@ -19,6 +19,7 @@ A worker node that contains a role playing.- **user_agent_kwargs** (Optional[Dict]): The keyword arguments to initialize the user agent in the role playing, like the model name, etc. (default: :obj:`None`)- **summarize_agent_kwargs** (Optional[Dict]): The keyword arguments to initialize the summarize agent, like the model name, etc. (default: :obj:`None`)- **chat_turn_limit** (int): The maximum number of chat turns in the role playing. (default: :obj:`20`)+- **use_structured_output_handler** (bool, optional): Whether to use the structured output handler instead of native structured output. When enabled, the workforce will use prompts with structured output instructions and regex extraction to parse responses. This ensures compatibility with agents that don't reliably support native structured output. When disabled, the workforce uses the native response_format parameter. (default: :obj:`True`)<a id="camel.societies.workforce.role_playing_worker.RolePlayingWorker.__init__"></a>@@ -33,6 +34,7 @@ def __init__(assistant_agent_kwargs: Optional[Dict] = None,user_agent_kwargs: Optional[Dict] = None,summarize_agent_kwargs: Optional[Dict] = None,- chat_turn_limit: int = 20+ chat_turn_limit: int = 20,+ use_structured_output_handler: bool = True):```diff --git a/docs/mintlify/reference/camel.societies.workforce.single_agent_worker.mdx b/docs/mintlify/reference/camel.societies.workforce.single_agent_worker.mdxindex eb8b8f14b..dc910b4a6 100644--- a/docs/mintlify/reference/camel.societies.workforce.single_agent_worker.mdx+++ b/docs/mintlify/reference/camel.societies.workforce.single_agent_worker.mdx@@ -84,6 +84,7 @@ A worker node that consists of a single agent.- **pool_initial_size** (int): Initial size of the agent pool. (default: :obj:`1`)- **pool_max_size** (int): Maximum size of the agent pool. (default: :obj:`10`)- **auto_scale_pool** (bool): Whether to auto-scale the agent pool. (default: :obj:`True`)+- **use_structured_output_handler** (bool, optional): Whether to use the structured output handler instead of native structured output. When enabled, the workforce will use prompts with structured output instructions and regex extraction to parse responses. This ensures compatibility with agents that don't reliably support native structured output. When disabled, the workforce uses the native response_format parameter. (default: :obj:`True`)<a id="camel.societies.workforce.single_agent_worker.SingleAgentWorker.__init__"></a>@@ -97,7 +98,8 @@ def __init__(use_agent_pool: bool = True,pool_initial_size: int = 1,pool_max_size: int = 10,- auto_scale_pool: bool = True+ auto_scale_pool: bool = True,+ use_structured_output_handler: bool = True):```diff --git a/docs/mintlify/reference/camel.societies.workforce.structured_output_handler.mdx b/docs/mintlify/reference/camel.societies.workforce.structured_output_handler.mdxnew file mode 100644index 000000000..cd5f5ce92--- /dev/null+++ b/docs/mintlify/reference/camel.societies.workforce.structured_output_handler.mdx@@ -0,0 +1,192 @@+<a id="camel.societies.workforce.structured_output_handler"></a>++<a id="camel.societies.workforce.structured_output_handler.StructuredOutputHandler"></a>++## StructuredOutputHandler++```python+class StructuredOutputHandler:+```++Handler for generating prompts and extracting structured output from+agent responses.++This handler provides functionality to:+- Generate prompts that guide agents to produce structured output+- Extract structured data from agent responses using regex patterns+- Provide fallback mechanisms when extraction fails+- Support the existing structured output schemas used in workforce.py++<a id="camel.societies.workforce.structured_output_handler.StructuredOutputHandler.generate_structured_prompt"></a>++### generate_structured_prompt++```python+def generate_structured_prompt(+ base_prompt: str,+ schema: Type[BaseModel],+ examples: Optional[List[Dict[str, Any]]] = None,+ additional_instructions: Optional[str] = None+):+```++Generate a prompt that guides agents to produce structured output.++**Parameters:**++- **base_prompt** (str): The base prompt content.+- **schema** (Type[BaseModel]): The Pydantic model schema for the expected output.+- **examples** (Optional[List[Dict[str, Any]]]): Optional examples of valid output.+- **additional_instructions** (Optional[str]): Additional instructions for output formatting.++**Returns:**++ str: The enhanced prompt with structured output instructions.++<a id="camel.societies.workforce.structured_output_handler.StructuredOutputHandler.extract_json"></a>++### extract_json++```python+def extract_json(text: str, schema: Optional[Type[BaseModel]] = None):+```++Extract JSON data from text using multiple patterns.++**Parameters:**++- **text** (str): The text containing JSON data.+- **schema** (Optional[Type[BaseModel]]): Optional schema for targeted extraction.++**Returns:**++ Optional[Dict[str, Any]]: Extracted JSON data or None if extraction+fails.++<a id="camel.societies.workforce.structured_output_handler.StructuredOutputHandler._extract_with_schema_patterns"></a>++### _extract_with_schema_patterns++```python+def _extract_with_schema_patterns(text: str, schema: Type[BaseModel]):+```++Extract data using schema-specific patterns.++**Parameters:**++- **text** (str): The text to extract from.+- **schema** (Type[BaseModel]): The schema to use for extraction.++**Returns:**++ Optional[Dict[str, Any]]: Extracted data or None.++<a id="camel.societies.workforce.structured_output_handler.StructuredOutputHandler.parse_structured_response"></a>++### parse_structured_response++```python+def parse_structured_response(+ response_text: str,+ schema: Type[BaseModel],+ fallback_values: Optional[Dict[str, Any]] = None+):+```++Parse agent response into structured data with fallback support.++**Parameters:**++- **response_text** (str): The agent's response text.+- **schema** (Type[BaseModel]): The expected schema.+- **fallback_values** (Optional[Dict[str, Any]]): Fallback values to use if parsing fails.++**Returns:**++ Union[BaseModel, Dict[str, Any]]: Parsed data as schema instance+or fallback dictionary.++<a id="camel.societies.workforce.structured_output_handler.StructuredOutputHandler._fix_common_issues"></a>++### _fix_common_issues++```python+def _fix_common_issues(data: Dict[str, Any], schema: Type[BaseModel]):+```++Attempt to fix common validation issues in extracted data.++**Parameters:**++- **data** (Dict[str, Any]): The extracted data.+- **schema** (Type[BaseModel]): The target schema.++**Returns:**++ Optional[Dict[str, Any]]: Fixed data or None if unfixable.++<a id="camel.societies.workforce.structured_output_handler.StructuredOutputHandler._create_default_instance"></a>++### _create_default_instance++```python+def _create_default_instance(schema: Type[BaseModel]):+```++Create a default instance of the schema with minimal required+fields.++**Parameters:**++- **schema** (Type[BaseModel]): The schema to instantiate.++**Returns:**++ BaseModel: Default instance of the schema.++<a id="camel.societies.workforce.structured_output_handler.StructuredOutputHandler.validate_response"></a>++### validate_response++```python+def validate_response(+ response: Union[BaseModel, Dict[str, Any]],+ schema: Type[BaseModel]+):+```++Validate that a response conforms to the expected schema.++**Parameters:**++- **response**: The response to validate.+- **schema** (Type[BaseModel]): The expected schema.++**Returns:**++ bool: True if valid, False otherwise.++<a id="camel.societies.workforce.structured_output_handler.StructuredOutputHandler.create_fallback_response"></a>++### create_fallback_response++```python+def create_fallback_response(+ schema: Type[BaseModel],+ error_message: str,+ context: Optional[Dict[str, Any]] = None+):+```++Create a fallback response for a given schema with error context.++**Parameters:**++- **schema** (Type[BaseModel]): The schema to create a response for.+- **error_message** (str): The error message to include.+- **context** (Optional[Dict[str, Any]]): Additional context for the fallback.++**Returns:**++ BaseModel: A valid instance of the schema with fallback values.diff --git a/docs/mintlify/reference/camel.societies.workforce.workforce.mdx b/docs/mintlify/reference/camel.societies.workforce.workforce.mdxindex e665d7410..1deb2c8e6 100644--- a/docs/mintlify/reference/camel.societies.workforce.workforce.mdx+++ b/docs/mintlify/reference/camel.societies.workforce.workforce.mdx@@ -65,6 +65,7 @@ capabilities- **new_worker_agent** (Optional[ChatAgent], optional): A template agent for workers created dynamically at runtime when existing workers cannot handle failed tasks. If None, workers will be created with default settings including SearchToolkit, CodeExecutionToolkit, and ThinkingToolkit. (default: :obj:`None`)- **graceful_shutdown_timeout** (float, optional): The timeout in seconds for graceful shutdown when a task fails 3 times. During this period, the workforce remains active for debugging. Set to 0 for immediate shutdown. (default: :obj:`15.0`)- **share_memory** (bool, optional): Whether to enable shared memory across SingleAgentWorker instances in the workforce. When enabled, all SingleAgentWorker instances, coordinator agent, and task planning agent will share their complete conversation history and function-calling trajectory, providing better context for task handoffs and continuity. Note: Currently only supports SingleAgentWorker instances; RolePlayingWorker and nested Workforce instances do not participate in memory sharing. (default: :obj:`False`)+- **use_structured_output_handler** (bool, optional): Whether to use the structured output handler instead of native structured output. When enabled, the workforce will use prompts with structured output instructions and regex extraction to parse responses. This ensures compatibility with agents that don't reliably support native structured output. When disabled, the workforce uses the native response_format parameter. (default: :obj:`True`)**Note:**@@ -88,7 +89,8 @@ def __init__(task_agent: Optional[ChatAgent] = None,new_worker_agent: Optional[ChatAgent] = None,graceful_shutdown_timeout: float = 15.0,- share_memory: bool = False+ share_memory: bool = False,+ use_structured_output_handler: bool = True):```