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

feat: Workforce enhancement (#2690)

Wendong-Fanfb0ff19d0dc9
diff --git a/camel/datagen/self_improving_cot.py b/camel/datagen/self_improving_cot.py
index ca2421e48..d03f2d1a4 100644
--- a/camel/datagen/self_improving_cot.py
+++ b/camel/datagen/self_improving_cot.py
@@ -116,7 +116,7 @@ class SelfImprovingCoTPipeline:
samples to be drawn using the rejection sampling
method, where samples are accepted or rejected based on
a predefined condition to achieve a desired distribution.
- (default: :obj: `None`)
+ (default: :obj:`None`)
evaluate_agent (Optional[ChatAgent]): The chat agent used for
evaluating reasoning traces. (default: :obj:`None`)
reward_model (BaseRewardModel, optional): Model used to evaluate
diff --git a/camel/runtimes/configs.py b/camel/runtimes/configs.py
index c286011b1..d556ae80e 100644
--- a/camel/runtimes/configs.py
+++ b/camel/runtimes/configs.py
@@ -21,22 +21,22 @@ class TaskConfig(BaseModel):
Arttributes:
cmd (str or list): Command to be executed
- stdout (bool): Attach to stdout. (default: :obj: `True`)
- stderr (bool): Attach to stderr. (default: :obj: `True`)
- stdin (bool): Attach to stdin. (default: :obj: `False`)
- tty (bool): Allocate a pseudo-TTY. (default: :obj: `False`)
- privileged (bool): Run as privileged. (default: :obj: `False`)
- user (str): User to execute command as. (default: :obj: `""`)
+ stdout (bool): Attach to stdout. (default: :obj:`True`)
+ stderr (bool): Attach to stderr. (default: :obj:`True`)
+ stdin (bool): Attach to stdin. (default: :obj:`False`)
+ tty (bool): Allocate a pseudo-TTY. (default: :obj:`False`)
+ privileged (bool): Run as privileged. (default: :obj:`False`)
+ user (str): User to execute command as. (default: :obj:`""`)
detach (bool): If true, detach from the exec command.
- (default: :obj: `False`)
- stream (bool): Stream response data. (default: :obj: `False`)
+ (default: :obj:`False`)
+ stream (bool): Stream response data. (default: :obj:`False`)
socket (bool): Return the connection socket to allow custom
- read/write operations. (default: :obj: `False`)
+ read/write operations. (default: :obj:`False`)
environment (dict or list): A dictionary or a list of strings in
the following format ``["PASSWORD=xxx"]`` or
- ``{"PASSWORD": "xxx"}``. (default: :obj: `None`)
+ ``{"PASSWORD": "xxx"}``. (default: :obj:`None`)
workdir (str): Path to working directory for this exec session.
- (default: :obj: `None`)
+ (default: :obj:`None`)
demux (bool): Return stdout and stderr separately. (default: :obj:
`False`)
"""
diff --git a/camel/runtimes/daytona_runtime.py b/camel/runtimes/daytona_runtime.py
index 636d16cf5..7a5b04a6d 100644
--- a/camel/runtimes/daytona_runtime.py
+++ b/camel/runtimes/daytona_runtime.py
@@ -34,13 +34,13 @@ class DaytonaRuntime(BaseRuntime):
Args:
api_key (Optional[str]): The Daytona API key for authentication. If not
provided, it will try to use the DAYTONA_API_KEY environment
- variable. (default: :obj: `None`)
+ variable. (default: :obj:`None`)
api_url (Optional[str]): The URL of the Daytona server. If not
provided, it will try to use the DAYTONA_API_URL environment
variable. If none is provided, it will use "http://localhost:8000".
- (default: :obj: `None`)
+ (default: :obj:`None`)
language (Optional[str]): The programming language for the sandbox.
- (default: :obj: `"python"`)
+ (default: :obj:`"python"`)
"""
def __init__(
@@ -102,7 +102,7 @@ class DaytonaRuntime(BaseRuntime):
list of functions to add.
entrypoint (str): The entrypoint for the function.
arguments (Optional[Dict[str, Any]]): The arguments for the
- function. (default: :obj: `None`)
+ function. (default: :obj:`None`)
Returns:
DaytonaRuntime: The current runtime.
diff --git a/camel/runtimes/docker_runtime.py b/camel/runtimes/docker_runtime.py
index 6e163f674..04d4cffd0 100644
--- a/camel/runtimes/docker_runtime.py
+++ b/camel/runtimes/docker_runtime.py
@@ -45,7 +45,7 @@ class DockerRuntime(BaseRuntime):
port (int): The port number to use for the runtime API. (default: :obj:
`8000`)
remove (bool): Whether to remove the container after stopping it. '
- (default: :obj: `True`)
+ (default: :obj:`True`)
kwargs (dict): Additional keyword arguments to pass to the
Docker client.
"""
@@ -170,7 +170,7 @@ class DockerRuntime(BaseRuntime):
Args:
time_out (int): The number of seconds to wait for the container to
- start. (default: :obj: `15`)
+ start. (default: :obj:`15`)
Returns:
DockerRuntime: The DockerRuntime instance.
@@ -259,9 +259,9 @@ class DockerRuntime(BaseRuntime):
list of functions to add.
entrypoint (str): The entrypoint for the function.
redirect_stdout (bool): Whether to return the stdout of
- the function. (default: :obj: `False`)
+ the function. (default: :obj:`False`)
arguments (Optional[Dict[str, Any]]): The arguments for the
- function. (default: :obj: `None`)
+ function. (default: :obj:`None`)
Returns:
DockerRuntime: The DockerRuntime instance.
@@ -330,7 +330,7 @@ class DockerRuntime(BaseRuntime):
Args:
remove (Optional[bool]): Whether to remove the container
- after stopping it. (default: :obj: `None`)
+ after stopping it. (default: :obj:`None`)
Returns:
DockerRuntime: The DockerRuntime instance.
@@ -366,7 +366,7 @@ class DockerRuntime(BaseRuntime):
r"""Wait for the API Server to be ready.
Args:
- timeout (int): The number of seconds to wait. (default: :obj: `10`)
+ timeout (int): The number of seconds to wait. (default: :obj:`10`)
Returns:
bool: Whether the API Server is ready.
diff --git a/camel/runtimes/remote_http_runtime.py b/camel/runtimes/remote_http_runtime.py
index 3711f0764..67b9b1732 100644
--- a/camel/runtimes/remote_http_runtime.py
+++ b/camel/runtimes/remote_http_runtime.py
@@ -36,9 +36,9 @@ class RemoteHttpRuntime(BaseRuntime):
Args:
host (str): The host of the remote server.
- port (int): The port of the remote server. (default: :obj: `8000`)
+ port (int): The port of the remote server. (default: :obj:`8000`)
python_exec (str): The python executable to run the API server.
- (default: :obj: `python3`)
+ (default: :obj:`python3`)
"""
def __init__(
@@ -90,9 +90,9 @@ class RemoteHttpRuntime(BaseRuntime):
list of functions to add.
entrypoint (str): The entrypoint for the function.
redirect_stdout (bool): Whether to return the stdout of
- the function. (default: :obj: `False`)
+ the function. (default: :obj:`False`)
arguments (Optional[Dict[str, Any]]): The arguments for the
- function. (default: :obj: `None`)
+ function. (default: :obj:`None`)
Returns:
RemoteHttpRuntime: The current runtime.
@@ -162,7 +162,7 @@ class RemoteHttpRuntime(BaseRuntime):
r"""Wait for the API Server to be ready.
Args:
- timeout (int): The number of seconds to wait. (default: :obj: `10`)
+ timeout (int): The number of seconds to wait. (default: :obj:`10`)
Returns:
bool: Whether the API Server is ready.
diff --git a/camel/societies/workforce/prompts.py b/camel/societies/workforce/prompts.py
index 2aaa17025..6ee3dacfb 100644
--- a/camel/societies/workforce/prompts.py
+++ b/camel/societies/workforce/prompts.py
@@ -49,17 +49,6 @@ The information returned should be concise and clear.
ASSIGN_TASK_PROMPT = TextPrompt(
"""You need to assign multiple tasks to worker nodes based on the information below.
-Here are the tasks to be assigned:
-==============================
-{tasks_info}
-==============================
-
-Following is the information of the existing worker nodes. The format is <ID>:<description>:<additional_info>. Choose the most capable worker node ID for each task.
-
-==============================
-{child_nodes_info}
-==============================
-
For each task, you need to:
1. Choose the most capable worker node ID for that task
2. Identify any dependencies between tasks (if task B requires results from task A, then task A is a dependency of task B)
@@ -80,9 +69,21 @@ Example valid response:
]
}}
-IMPORTANT: Carefully analyze the sequence of tasks. A task's dependencies MUST include the IDs of all prior tasks whose outputs are necessary for its execution. For example, a task to 'Summarize Paper X' MUST depend on the task that 'Finds/Retrieves Paper X'. Similarly, a task that 'Compiles a report from summaries' MUST depend on all 'Summarize Paper X' tasks. Incorrect or missing dependencies will lead to critical operational failures and an inability to complete the overall objective. Be meticulous in defining these relationships.
+***CRITICAL: DEPENDENCY MANAGEMENT IS YOUR IMPORTANT RESPONSIBILITY.***
+Carefully analyze the sequence of tasks. A task's dependencies MUST include the IDs of all prior tasks whose outputs are necessary for its execution. For example, a task to 'Summarize Paper X' MUST depend on the task that 'Finds/Retrieves Paper X'. Similarly, a task that 'Compiles a report from summaries' MUST depend on all 'Summarize Paper X' tasks. **Incorrect or missing dependencies will lead to critical operational failures and an inability to complete the overall objective.** Be meticulous in defining these relationships.
Do not include any other text, explanations, justifications, or conversational filler before or after the JSON object. Return ONLY the JSON object.
+
+Here are the tasks to be assigned:
+==============================
+{tasks_info}
+==============================
+
+Following is the information of the existing worker nodes. The format is <ID>:<description>:<additional_info>. Choose the most capable worker node ID for each task.
+
+==============================
+{child_nodes_info}
+==============================
"""
)
diff --git a/camel/societies/workforce/single_agent_worker.py b/camel/societies/workforce/single_agent_worker.py
index cf3000914..027ff4f8e 100644
--- a/camel/societies/workforce/single_agent_worker.py
+++ b/camel/societies/workforce/single_agent_worker.py
@@ -13,9 +13,12 @@
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
from __future__ import annotations
+import asyncio
import datetime
import json
-from typing import Any, List
+import time
+from collections import deque
+from typing import Any, List, Optional
from colorama import Fore
@@ -26,44 +29,237 @@ from camel.societies.workforce.worker import Worker
from camel.tasks.task import Task, TaskState, validate_task_content
+class AgentPool:
+ r"""A pool of agent instances for efficient reuse.
+
+ This pool manages a collection of pre-cloned agents. It supports
+ auto-scaling based ondemand and intelligent reuse of existing agents.
+
+ Args:
+ base_agent (ChatAgent): The base agent to clone from.
+ initial_size (int): Initial number of agents in the pool.
+ (default: :obj:`1`)
+ max_size (int): Maximum number of agents in the pool.
+ (default: :obj:`10`)
+ auto_scale (bool): Whether to automatically scale the pool size.
+ (default: :obj:`True`)
+ scale_factor (float): Factor by which to scale the pool when needed.
+ (default: :obj:`1.5`)
+ idle_timeout (float): Time in seconds after which idle agents are
+ removed. (default: :obj:`180.0`)
+ """
+
+ def __init__(
+ self,
+ base_agent: ChatAgent,
+ initial_size: int = 1,
+ max_size: int = 10,
+ auto_scale: bool = True,
+ scale_factor: float = 1.5,
+ idle_timeout: float = 180.0, # 3 minutes
+ ):
+ self.base_agent = base_agent
+ self.max_size = max_size
+ self.auto_scale = auto_scale
+ self.scale_factor = scale_factor
+ self.idle_timeout = idle_timeout
+
+ # Pool management
+ self._available_agents: deque = deque()
+ self._in_use_agents: set = set()
+ self._agent_last_used: dict = {}
+ self._lock = asyncio.Lock()
+
+ # Statistics
+ self._total_borrows = 0
+ self._total_clones_created = 0
+ self._pool_hits = 0
+
+ # Initialize pool
+ self._initialize_pool(initial_size)
+
+ def _initialize_pool(self, size: int) -> None:
+ r"""Initialize the pool with the specified number of agents."""
+ for _ in range(min(size, self.max_size)):
+ agent = self._create_fresh_agent()
+ self._available_agents.append(agent)
+
+ def _create_fresh_agent(self) -> ChatAgent:
+ r"""Create a fresh agent instance."""
+ agent = self.base_agent.clone(with_memory=False)
+ self._total_clones_created += 1
+ return agent
+
+ async def get_agent(self) -> ChatAgent:
+ r"""Get an agent from the pool, creating one if necessary."""
+ async with self._lock:
+ self._total_borrows += 1
+
+ # Try to get from available agents first
+ if self._available_agents:
+ agent = self._available_agents.popleft()
+ self._in_use_agents.add(id(agent))
+ self._pool_hits += 1
+
+ # Reset the agent state
+ agent.reset()
+ return agent
+
+ # Check if we can create new agents
+ total_agents = len(self._available_agents) + len(
+ self._in_use_agents
+ )
+ if total_agents < self.max_size:
+ agent = self._create_fresh_agent()
+ self._in_use_agents.add(id(agent))
+ return agent
+
+ # Pool exhausted, wait and retry or create temporary agent
+ if self.auto_scale:
+ # Create a temporary agent that won't be returned to pool
+ return self._create_fresh_agent()
+ else:
+ # Wait for an agent to become available
+ while not self._available_agents:
+ await asyncio.sleep(0.1)
+
+ agent = self._available_agents.popleft()
+ self._in_use_agents.add(id(agent))
+ agent.reset()
+ return agent
+
+ async def return_agent(self, agent: ChatAgent) -> None:
+ r"""Return an agent to the pool."""
+ async with self._lock:
+ agent_id = id(agent)
+
+ if agent_id in self._in_use_agents:
+ self._in_use_agents.remove(agent_id)
+
+ # Only return to pool if we're under max size
+ if len(self._available_agents) < self.max_size:
+ # Reset agent state before returning to pool
+ agent.reset()
+ self._available_agents.append(agent)
+ self._agent_last_used[agent_id] = time.time()
+
+ async def cleanup_idle_agents(self) -> None:
+ r"""Remove idle agents from the pool to free memory."""
+ if not self.auto_scale:
+ return
+
+ async with self._lock:
+ current_time = time.time()
+ agents_to_remove = []
+
+ for agent in list(self._available_agents):
+ agent_id = id(agent)
+ last_used = self._agent_last_used.get(agent_id, current_time)
+
+ if current_time - last_used > self.idle_timeout:
+ agents_to_remove.append(agent)
+
+ for agent in agents_to_remove:
+ self._available_agents.remove(agent)
+ agent_id = id(agent)
+ self._agent_last_used.pop(agent_id, None)
+
+ def get_stats(self) -> dict:
+ r"""Get pool statistics."""
+ return {
+ "available_agents": len(self._available_agents),
+ "in_use_agents": len(self._in_use_agents),
+ "total_borrows": self._total_borrows,
+ "total_clones_created": self._total_clones_created,
+ "pool_hits": self._pool_hits,
+ "hit_rate": self._pool_hits / max(self._total_borrows, 1),
+ }
+
+
class SingleAgentWorker(Worker):
r"""A worker node that consists of a single agent.
Args:
description (str): Description of the node.
worker (ChatAgent): Worker of the node. A single agent.
- max_concurrent_tasks (int): Maximum number of tasks this worker can
- process concurrently. (default: :obj:`10`)
+ use_agent_pool (bool): Whether to use agent pool for efficiency.
+ (default: :obj:`True`)
+ 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`)
"""
def __init__(
self,
description: str,
worker: ChatAgent,
- max_concurrent_tasks: int = 10,
+ use_agent_pool: bool = True,
+ pool_initial_size: int = 1,
+ pool_max_size: int = 10,
+ auto_scale_pool: bool = True,
) -> None:
node_id = worker.agent_id
super().__init__(
description,
node_id=node_id,
- max_concurrent_tasks=max_concurrent_tasks,
)
self.worker = worker
+ self.use_agent_pool = use_agent_pool
+
+ self.agent_pool: Optional[AgentPool] = None
+ self._cleanup_task: Optional[asyncio.Task] = None
+ # Initialize agent pool if enabled
+ if self.use_agent_pool:
+ self.agent_pool = AgentPool(
+ base_agent=worker,
+ initial_size=pool_initial_size,
+ max_size=pool_max_size,
+ auto_scale=auto_scale_pool,
+ )
def reset(self) -> Any:
r"""Resets the worker to its initial state."""
super().reset()
self.worker.reset()
+ # Reset agent pool if it exists
+ if self.agent_pool:
+ # Stop cleanup task
+ if self._cleanup_task and not self._cleanup_task.done():
+ self._cleanup_task.cancel()
+
+ # Reinitialize pool
+ self.agent_pool = AgentPool(
+ base_agent=self.worker,
+ )
+
+ async def _get_worker_agent(self) -> ChatAgent:
+ r"""Get a worker agent, either from pool or by cloning."""
+ if self.use_agent_pool and self.agent_pool:
+ return await self.agent_pool.get_agent()
+ else:
+ # Fallback to original cloning approach
+ return self.worker.clone(with_memory=False)
+
+ async def _return_worker_agent(self, agent: ChatAgent) -> None:
+ r"""Return a worker agent to the pool if pooling is enabled."""
+ if self.use_agent_pool and self.agent_pool:
+ await self.agent_pool.return_agent(agent)
+ # If not using pool, agent will be garbage collected
+
async def _process_task(
self, task: Task, dependencies: List[Task]
) -> TaskState:
- r"""Processes a task with its dependencies using a cloned agent.
+ r"""Processes a task with its dependencies using an efficient agent
+ management system.
This method asynchronously processes a given task, considering its
- dependencies, by sending a generated prompt to a cloned worker agent.
- Using a cloned agent ensures that concurrent tasks don't interfere
- with each other's state.
+ dependencies, by sending a generated prompt to a worker agent.
+ Uses an agent pool for efficiency when enabled, or falls back to
+ cloning when pool is disabled.
Args:
task (Task): The task to process, which includes necessary details
@@ -74,17 +270,17 @@ class SingleAgentWorker(Worker):
TaskState: `TaskState.DONE` if processed successfully, otherwise
`TaskState.FAILED`.
"""
- # Clone the agent for this specific task to avoid state conflicts
- # when processing multiple tasks concurrently
- worker_agent = self.worker.clone(with_memory=False)
-
- dependency_tasks_info = self._get_dep_tasks_info(dependencies)
- prompt = PROCESS_TASK_PROMPT.format(
- content=task.content,
- dependency_tasks_info=dependency_tasks_info,
- additional_info=task.additional_info,
- )
+ # Get agent efficiently (from pool or by cloning)
+ worker_agent = await self._get_worker_agent()
+
try:
+ dependency_tasks_info = self._get_dep_tasks_info(dependencies)
+ prompt = PROCESS_TASK_PROMPT.format(
+ content=task.content,
+ dependency_tasks_info=dependency_tasks_info,
+ additional_info=task.additional_info,
+ )
+
response = await worker_agent.astep(
prompt, response_format=TaskResult
)
@@ -94,8 +290,11 @@ class SingleAgentWorker(Worker):
f"\n{e}{Fore.RESET}"
)
return TaskState.FAILED
+ finally:
+ # Return agent to pool or let it be garbage collected
+ await self._return_worker_agent(worker_agent)
- # Get actual token usage from the cloned agent that processed this task
+ # Get actual token usage from the agent that processed this task
try:
_, total_token_count = worker_agent.memory.get_context()
except Exception:
@@ -117,11 +316,11 @@ class SingleAgentWorker(Worker):
"timestamp": str(datetime.datetime.now()),
"description": f"Attempt by "
f"{getattr(worker_agent, 'agent_id', worker_agent.role_name)} "
- f"(cloned from "
+ f"(from pool/clone of "
f"{getattr(self.worker, 'agent_id', self.worker.role_name)}) "
f"to process task {task.content}",
"response_content": response.msg.content,
- "tool_calls": response.info["tool_calls"],
+ "tool_calls": response.info.get("tool_calls"),
"total_token_count": total_token_count,
}
@@ -157,3 +356,34 @@ class SingleAgentWorker(Worker):
task.result = task_result.content
return TaskState.DONE
+
+ async def _listen_to_channel(self):
+ r"""Override to start cleanup task when pool is enabled."""
+ # Start cleanup task for agent pool
+ if self.use_agent_pool and self.agent_pool:
+ self._cleanup_task = asyncio.create_task(self._periodic_cleanup())
+
+ # Call parent implementation
+ await super()._listen_to_channel()
+
+ # Stop cleanup task
+ if self._cleanup_task and not self._cleanup_task.done():
+ self._cleanup_task.cancel()
+
+ async def _periodic_cleanup(self):
+ r"""Periodically clean up idle agents from the pool."""
+ while True:
+ try:
+ await asyncio.sleep(60) # Cleanup every minute
+ if self.agent_pool:
+ await self.agent_pool.cleanup_idle_agents()
+ except asyncio.CancelledError:
+ break
+ except Exception as e:
+ print(f"Error in pool cleanup: {e}")
+
+ def get_pool_stats(self) -> Optional[dict]:
+ r"""Get agent pool statistics if pool is enabled."""
+ if self.use_agent_pool and self.agent_pool:
+ return self.agent_pool.get_stats()
+ return None
diff --git a/camel/societies/workforce/utils.py b/camel/societies/workforce/utils.py
index f535c9fe1..3468da754 100644
--- a/camel/societies/workforce/utils.py
+++ b/camel/societies/workforce/utils.py
@@ -50,7 +50,8 @@ class TaskAssignment(BaseModel):
)
dependencies: List[str] = Field(
default_factory=list,
- description="List of task IDs that must complete before this task.",
+ description="List of task IDs that must complete before this task. "
+ "This is critical for the task decomposition and execution.",
)
@@ -156,7 +157,14 @@ def check_if_running(
)
return None
else:
- raise last_exception
+ raise (
+ last_exception
+ if last_exception
+ else RuntimeError(
+ f"Unexpected failure in {func.__name__} "
+ "with no exception captured."
+ )
+ )
return wrapper
diff --git a/camel/societies/workforce/worker.py b/camel/societies/workforce/worker.py
index af415bb03..d1e715bcd 100644
--- a/camel/societies/workforce/worker.py
+++ b/camel/societies/workforce/worker.py
@@ -36,18 +36,14 @@ class Worker(BaseNode, ABC):
description (str): Description of the node.
node_id (Optional[str]): ID of the node. If not provided, it will
be generated automatically. (default: :obj:`None`)
- max_concurrent_tasks (int): Maximum number of tasks this worker can
- process concurrently. (default: :obj:`10`)
"""
def __init__(
self,
description: str,
node_id: Optional[str] = None,
- max_concurrent_tasks: int = 10,
) -> None:
super().__init__(description, node_id=node_id)
- self.max_concurrent_tasks = max_concurrent_tasks
self._active_task_ids: Set[str] = set()
def __repr__(self):
@@ -114,17 +110,12 @@ class Worker(BaseNode, ABC):
@check_if_running(False)
async def _listen_to_channel(self):
- r"""Continuously listen to the channel, process tasks that are
- assigned to this node concurrently up to max_concurrent_tasks limit.
+ r"""Continuously listen to the channel and process assigned tasks.
- This method supports parallel task execution when multiple tasks
- are assigned to the same worker.
+ This method supports parallel task execution without artificial limits.
"""
self._running = True
- logger.info(
- f"{self} started with max {self.max_concurrent_tasks} "
- f"concurrent tasks."
- )
+ logger.info(f"{self} started.")
# Keep track of running task coroutines
running_tasks: Set[asyncio.Task] = set()
@@ -141,39 +132,24 @@ class Worker(BaseNode, ABC):
except Exception as e:
logger.error(f"Task processing failed: {e}")
- # Check if we can accept more tasks
- if len(running_tasks) < self.max_concurrent_tasks:
- try:
- # Try to get a new task (with short timeout to avoid
- # blocking)
- task = await asyncio.wait_for(
- self._get_assigned_task(), timeout=1.0
- )
-
- # Create and start processing task
- task_coroutine = asyncio.create_task(
- self._process_single_task(task)
- )
- running_tasks.add(task_coroutine)
-
- except asyncio.TimeoutError:
- # No tasks available, continue loop
- if not running_tasks:
- # No tasks running and none available, short sleep
- await asyncio.sleep(0.1)
- continue
- else:
- # At max capacity, wait for at least one task to complete
- if running_tasks:
- done, running_tasks = await asyncio.wait(
- running_tasks, return_when=asyncio.FIRST_COMPLETED
- )
- # Process completed tasks
- for completed_task in done:
- try:
- await completed_task
- except Exception as e:
- logger.error(f"Task processing failed: {e}")
+ # Try to get a new task (with short timeout to avoid blocking)
+ try:
+ task = await asyncio.wait_for(
+ self._get_assigned_task(), timeout=1.0
+ )
+
+ # Create and start processing task
+ task_coroutine = asyncio.create_task(
+ self._process_single_task(task)
+ )
+ running_tasks.add(task_coroutine)
+
+ except asyncio.TimeoutError:
+ # No tasks available, continue loop
+ if not running_tasks:
+ # No tasks running and none available, short sleep
+ await asyncio.sleep(0.1)
+ continue
except Exception as e:
logger.error(
diff --git a/camel/societies/workforce/workforce.py b/camel/societies/workforce/workforce.py
index 81700b8b1..254dc5987 100644
--- a/camel/societies/workforce/workforce.py
+++ b/camel/societies/workforce/workforce.py
@@ -674,8 +674,8 @@ class Workforce(BaseNode):
# Reset state for tasks being moved back to pending
for task in tasks_to_move_back:
# Handle all possible task states
- if task.state in [TaskState.DONE, TaskState.FAILED]:
- task.state = TaskState.OPEN
+ if task.state in [TaskState.DONE, TaskState.OPEN]:
+ task.state = TaskState.FAILED # TODO: Add logic for OPEN
# Clear result to avoid confusion
task.result = None
# Reset failure count to give task a fresh start
@@ -881,7 +881,7 @@ class Workforce(BaseNode):
self.reset()
self._task = task
self._state = WorkforceState.RUNNING
- task.state = TaskState.OPEN
+ task.state = TaskState.FAILED # TODO: Add logic for OPEN
self._pending_tasks.append(task)
# Decompose the task into subtasks first
@@ -998,21 +998,23 @@ class Workforce(BaseNode):
self,
description: str,
worker: ChatAgent,
- max_concurrent_tasks: int = 10,
+ pool_max_size: int = 10,
) -> Workforce:
r"""Add a worker node to the workforce that uses a single agent.
Args:
description (str): Description of the worker node.
worker (ChatAgent): The agent to be added.
- max_concurrent_tasks (int): Maximum number of tasks this worker can
- process concurrently. (default: :obj:`10`)
+ pool_max_size (int): Maximum size of the agent pool.
+ (default: :obj:`10`)
Returns:
Workforce: The workforce node itself.
"""
worker_node = SingleAgentWorker(
- description, worker, max_concurrent_tasks
+ description=description,
+ worker=worker,
+ pool_max_size=pool_max_size,
)
self._children.append(worker_node)
if self.metrics_logger:
@@ -1194,6 +1196,13 @@ class Workforce(BaseNode):
response = self.coordinator_agent.step(
prompt, response_format=TaskAssignResult
)
+ if response.msg is None or response.msg.content is None:
+ logger.error(
+ "Coordinator agent returned empty response for task assignment"
+ )
+ # Return empty result as fallback
+ return TaskAssignResult(assignments=[])
+
result_dict = json.loads(response.msg.content, parse_int=str)
task_assign_result = TaskAssignResult(**result_dict)
return task_assign_result
@@ -1231,8 +1240,21 @@ class Workforce(BaseNode):
response = self.coordinator_agent.step(
prompt, response_format=WorkerConf
)
- result_dict = json.loads(response.msg.content)
- new_node_conf = WorkerConf(**result_dict)
+ if response.msg is None or response.msg.content is None:
+ logger.error(
+ "Coordinator agent returned empty response for worker creation"
+ )
+ # Create a fallback worker configuration
+ new_node_conf = WorkerConf(
+ description=f"Fallback worker for "
+ f"task: {task.content[:50]}...",
+ role="General Assistant",
+ sys_msg="You are a general assistant that can help "
+ "with various tasks.",
+ )
+ else:
+ result_dict = json.loads(response.msg.content)
+ new_node_conf = WorkerConf(**result_dict)
new_agent = self._create_new_agent(
new_node_conf.role,
@@ -1242,7 +1264,7 @@ class Workforce(BaseNode):
new_node = SingleAgentWorker(
description=new_node_conf.description,
worker=new_agent,
- max_concurrent_tasks=10, # TODO: make this configurable
+ pool_max_size=10, # TODO: make this configurable
)
new_node.set_channel(self._channel)
@@ -1384,10 +1406,10 @@ class Workforce(BaseNode):
metadata={'failure_count': task.failure_count},
)
- if task.failure_count >= 3:
+ if task.failure_count > 3:
return True
- if task.get_depth() >= 3:
+ if task.get_depth() > 3:
# Create a new worker node and reassign
assignee = self._create_worker_node_for_task(task)
@@ -1685,7 +1707,7 @@ class Workforce(BaseNode):
await self._graceful_shutdown(returned_task)
break
elif returned_task.state == TaskState.OPEN:
- # TODO: multi-layer workforce
+ # TODO: Add logic for OPEN
pass
else:
raise ValueError(
@@ -1797,7 +1819,7 @@ class Workforce(BaseNode):
new_instance.add_single_agent_worker(
child.description,
cloned_worker,
- child.max_concurrent_tasks,
+ pool_max_size=10,
)
elif isinstance(child, RolePlayingWorker):
new_instance.add_role_playing_worker(
@@ -1808,7 +1830,6 @@ class Workforce(BaseNode):
child.user_agent_kwargs,
child.summarize_agent_kwargs,
child.chat_turn_limit,
- child.max_concurrent_tasks,
)
elif isinstance(child, Workforce):
new_instance.add_workforce(child.clone(with_memory))
diff --git a/camel/tasks/task.py b/camel/tasks/task.py
index 72158cabe..cd56bf1e3 100644
--- a/camel/tasks/task.py
+++ b/camel/tasks/task.py
@@ -25,10 +25,12 @@ from typing import (
Union,
)
-from pydantic import BaseModel
+from pydantic import BaseModel, Field
if TYPE_CHECKING:
from camel.agents import ChatAgent
+import uuid
+
from camel.logger import get_logger
from camel.messages import BaseMessage
from camel.prompts import TextPrompt
@@ -142,27 +144,29 @@ class Task(BaseModel):
content (str): string content for task.
id (str): An unique string identifier for the task. This should
ideally be provided by the provider/model which created the task.
- (default: :obj: `""`)
+ (default: :obj:`uuid.uuid4()`)
state (TaskState): The state which should be OPEN, RUNNING, DONE or
- DELETED. (default: :obj: `TaskState.OPEN`)
- type (Optional[str]): task type. (default: :obj: `None`)
+ DELETED. (default: :obj:`TaskState.FAILED`)
+ type (Optional[str]): task type. (default: :obj:`None`)
parent (Optional[Task]): The parent task, None for root task.
- (default: :obj: `None`)
+ (default: :obj:`None`)
subtasks (List[Task]): The childrent sub-tasks for the task.
- (default: :obj: `[]`)
+ (default: :obj:`[]`)
result (Optional[str]): The answer for the task.
- (default: :obj: `""`)
+ (default: :obj:`""`)
failure_count (int): The failure count for the task.
- (default: :obj: `0`)
+ (default: :obj:`0`)
additional_info (Optional[Dict[str, Any]]): Additional information for
- the task. (default: :obj: `None`)
+ the task. (default: :obj:`None`)
"""
content: str
- id: str = ""
+ id: str = Field(default_factory=lambda: str(uuid.uuid4()))
- state: TaskState = TaskState.OPEN
+ state: TaskState = (
+ TaskState.FAILED
+ ) # TODO: Add logic for OPEN in workforce.py
type: Optional[str] = None
@@ -204,7 +208,9 @@ class Task(BaseModel):
def reset(self):
r"""Reset Task to initial state."""
- self.state = TaskState.OPEN
+ self.state = (
+ TaskState.FAILED
+ ) # TODO: Add logic for OPEN in workforce.py
self.result = ""
def update_result(self, result: str):
diff --git a/camel/toolkits/aci_toolkit.py b/camel/toolkits/aci_toolkit.py
index 7f9ef69d1..0639b39f8 100644
--- a/camel/toolkits/aci_toolkit.py
+++ b/camel/toolkits/aci_toolkit.py
@@ -48,14 +48,14 @@ class ACIToolkit(BaseToolkit):
Args:
api_key (Optional[str]): The API key for authentication.
- (default: :obj: `None`)
+ (default: :obj:`None`)
base_url (Optional[str]): The base URL for the ACI API.
- (default: :obj: `None`)
+ (default: :obj:`None`)
linked_account_owner_id (Optional[str]): ID of the owner of the
linked account, e.g., "johndoe"
- (default: :obj: `None`)
+ (default: :obj:`None`)
timeout (Optional[float]): Request timeout.
- (default: :obj: `None`)
+ (default: :obj:`None`)
"""
from aci import ACI
@@ -80,20 +80,20 @@ class ACIToolkit(BaseToolkit):
Args:
intent (Optional[str]): Search results will be sorted by relevance
to this intent.
- (default: :obj: `None`)
+ (default: :obj:`None`)
allowed_app_only (bool): If true, only return apps that
are allowed by the agent/accessor, identified by the api key.
- (default: :obj: `True`)
+ (default: :obj:`True`)
include_functions (bool): If true, include functions
(name and description) in the search results.
- (default: :obj: `False`)
+ (default: :obj:`False`)
categories (Optional[List[str]]): List of categories to filter the
search results. Defaults to an empty list.
- (default: :obj: `None`)
+ (default: :obj:`None`)
limit (Optional[int]): Maximum number of results to return.
- (default: :obj: `10`)
+ (default: :obj:`10`)
offset (Optional[int]): Offset for pagination.
- (default: :obj: `0`)
+ (default: :obj:`0`)
Returns:
Optional[List[AppBasic]]: List of matching apps if successful,
@@ -123,10 +123,10 @@ class ACIToolkit(BaseToolkit):
Args:
app_names (Optional[List[str]]): List of app names to filter the
- results. (default: :obj: `None`)
+ results. (default: :obj:`None`)
limit (Optional[int]): Maximum number of results to return.
- (default: :obj: `10`)
- offset (Optional[int]): Offset for pagination. (default: :obj: `0`)
+ (default: :obj:`10`)
+ offset (Optional[int]): Offset for pagination. (default: :obj:`0`)
Returns:
Union[List[AppConfiguration], str]: List of configured apps if
@@ -356,15 +356,15 @@ class ACIToolkit(BaseToolkit):
Args:
app_names (Optional[List[str]]): List of app names to filter the
- search results. (default: :obj: `None`)
+ search results. (default: :obj:`None`)
intent (Optional[str]): The search query/intent.
- (default: :obj: `None`)
+ (default: :obj:`None`)
allowed_apps_only (bool): If true, only return
- functions from allowed apps. (default: :obj: `True`)
+ functions from allowed apps. (default: :obj:`True`)
limit (Optional[int]): Maximum number of results to return.
- (default: :obj: `10`)
+ (default: :obj:`10`)
offset (Optional[int]): Offset for pagination.
- (default: :obj: `0`)
+ (default: :obj:`0`)
Returns:
List[Dict]: List of matching functions
@@ -395,7 +395,7 @@ class ACIToolkit(BaseToolkit):
owner id in the ACI dashboard (https://platform.aci.dev).
allowed_apps_only (bool): If true, only returns functions/apps
that are allowed to be used by the agent/accessor, identified
- by the api key. (default: :obj: `False`)
+ by the api key. (default: :obj:`False`)
Returns:
Dict: Result of the function execution
diff --git a/camel/toolkits/arxiv_toolkit.py b/camel/toolkits/arxiv_toolkit.py
index 5e80b48b3..d4a82252b 100644
--- a/camel/toolkits/arxiv_toolkit.py
+++ b/camel/toolkits/arxiv_toolkit.py
@@ -49,9 +49,9 @@ class ArxivToolkit(BaseToolkit):
query (str): The search query string used to search for papers on
arXiv.
paper_ids (List[str], optional): A list of specific arXiv paper
- IDs to search for. (default: :obj: `None`)
+ IDs to search for. (default: :obj:`None`)
max_results (int, optional): The maximum number of search results
- to retrieve. (default: :obj: `5`)
+ to retrieve. (default: :obj:`5`)
Returns:
Generator: A generator that yields results from the arXiv search
@@ -80,9 +80,9 @@ class ArxivToolkit(BaseToolkit):
Args:
query (str): The search query string.
paper_ids (List[str], optional): A list of specific arXiv paper
- IDs to search for. (default: :obj: `None`)
+ IDs to search for. (default: :obj:`None`)
max_results (int, optional): The maximum number of search results
- to return. (default: :obj: `5`)
+ to return. (default: :obj:`5`)
Returns:
List[Dict[str, str]]: A list of dictionaries, each containing
@@ -138,9 +138,9 @@ class ArxivToolkit(BaseToolkit):
Args:
query (str): The search query string.
paper_ids (List[str], optional): A list of specific arXiv paper
- IDs to download. (default: :obj: `None`)
+ IDs to download. (default: :obj:`None`)
max_results (int, optional): The maximum number of search results
- to download. (default: :obj: `5`)
+ to download. (default: :obj:`5`)
output_dir (str, optional): The directory to save the downloaded
PDFs. Defaults to the current directory.
diff --git a/camel/toolkits/dappier_toolkit.py b/camel/toolkits/dappier_toolkit.py
index 34fd6ec39..788760c8b 100644
--- a/camel/toolkits/dappier_toolkit.py
+++ b/camel/toolkits/dappier_toolkit.py
@@ -126,22 +126,22 @@ class DappierToolkit(BaseToolkit):
query (str): The user query for retrieving recommendations.
data_model_id (str, optional): The data model ID to use for
recommendations. Data model IDs always start with the prefix
- "dm_". (default: :obj: `dm_01j0pb465keqmatq9k83dthx34`)
+ "dm_". (default: :obj:`dm_01j0pb465keqmatq9k83dthx34`)
similarity_top_k (int, optional): The number of top documents to
- retrieve based on similarity. (default: :obj: `9`)
+ retrieve based on similarity. (default: :obj:`9`)
ref (Optional[str], optional): The site domain where AI
- recommendations should be displayed. (default: :obj: `None`)
+ recommendations should be displayed. (default: :obj:`None`)
num_articles_ref (int, optional): The minimum number of articles
to return from the specified reference domain (`ref`). The
remaining articles will come from other sites in the RAG
- model. (default: :obj: `0`)
+ model. (default: :obj:`0`)
search_algorithm (Literal[
"most_recent",
"semantic",
"most_recent_semantic",
"trending",
], optional): The search algorithm to use for retrieving
- articles. (default: :obj: `most_recent`)
+ articles. (default: :obj:`most_recent`)
Returns:
List[Dict[str, str]]: A list of recommended articles or content
diff --git a/camel/toolkits/file_write_toolkit.py b/camel/toolkits/file_write_toolkit.py
index a7bb29db4..7487072d8 100644
--- a/camel/toolkits/file_write_toolkit.py
+++ b/camel/toolkits/file_write_toolkit.py
@@ -50,11 +50,11 @@ class FileWriteToolkit(BaseToolkit):
output_dir (str): The default directory for output files.
Defaults to the current working directory.
timeout (Optional[float]): The timeout for the toolkit.
- (default: :obj: `None`)
+ (default: :obj:`None`)
default_encoding (str): Default character encoding for text
- operations. (default: :obj: `utf-8`)
+ operations. (default: :obj:`utf-8`)
backup_enabled (bool): Whether to create backups of existing files
- before overwriting. (default: :obj: `True`)
+ before overwriting. (default: :obj:`True`)
"""
super().__init__(timeout=timeout)
self.output_dir = Path(output_dir).resolve()
@@ -96,7 +96,7 @@ class FileWriteToolkit(BaseToolkit):
Args:
file_path (Path): The target file path.
content (str): The text content to write.
- encoding (str): Character encoding to use. (default: :obj: `utf-8`)
+ encoding (str): Character encoding to use. (default: :obj:`utf-8`)
"""
with file_path.open("w", encoding=encoding) as f:
f.write(content)
@@ -157,7 +157,7 @@ class FileWriteToolkit(BaseToolkit):
content (str): The text content to write.
use_latex (bool): Whether to use LaTeX for rendering. (requires
LaTeX toolchain). If False, uses FPDF for simpler PDF
- generation. (default: :obj: `False`)
+ generation. (default: :obj:`False`)
Raises:
RuntimeError: If the 'pylatex' or 'fpdf' library is not installed
@@ -236,7 +236,7 @@ class FileWriteToolkit(BaseToolkit):
file_path (Path): The target file path.
content (Union[str, List[List]]): The CSV content as a string or
list of lists.
- encoding (str): Character encoding to use. (default: :obj: `utf-8`)
+ encoding (str): Character encoding to use. (default: :obj:`utf-8`)
"""
import csv
@@ -259,7 +259,7 @@ class FileWriteToolkit(BaseToolkit):
Args:
file_path (Path): The target file path.
content (str): The JSON content as a string.
- encoding (str): Character encoding to use. (default: :obj: `utf-8`)
+ encoding (str): Character encoding to use. (default: :obj:`utf-8`)
"""
import json
@@ -288,7 +288,7 @@ class FileWriteToolkit(BaseToolkit):
Args:
file_path (Path): The target file path.
content (str): The YAML content as a string.
- encoding (str): Character encoding to use. (default: :obj: `utf-8`)
+ encoding (str): Character encoding to use. (default: :obj:`utf-8`)
"""
with file_path.open("w", encoding=encoding) as f:
f.write(content)
@@ -302,7 +302,7 @@ class FileWriteToolkit(BaseToolkit):
Args:
file_path (Path): The target file path.
content (str): The HTML content to write.
- encoding (str): Character encoding to use. (default: :obj: `utf-8`)
+ encoding (str): Character encoding to use. (default: :obj:`utf-8`)
"""
with file_path.open("w", encoding=encoding) as f:
f.write(content)
@@ -316,7 +316,7 @@ class FileWriteToolkit(BaseToolkit):
Args:
file_path (Path): The target file path.
content (str): The Markdown content to write.
- encoding (str): Character encoding to use. (default: :obj: `utf-8`)
+ encoding (str): Character encoding to use. (default: :obj:`utf-8`)
"""
with file_path.open("w", encoding=encoding) as f:
f.write(content)
diff --git a/camel/toolkits/github_toolkit.py b/camel/toolkits/github_toolkit.py
index 6c13e7844..f29cbccae 100644
--- a/camel/toolkits/github_toolkit.py
+++ b/camel/toolkits/github_toolkit.py
@@ -158,7 +158,7 @@ class GithubToolkit(BaseToolkit):
Args:
repo_name (str): The name of the GitHub repository.
state (Literal["open", "closed", "all"]): The state of pull
- requests to retrieve. (default: :obj: `all`)
+ requests to retrieve. (default: :obj:`all`)
Options are:
- "open": Retrieve only open pull requests.
- "closed": Retrieve only closed pull requests.
@@ -202,7 +202,7 @@ class GithubToolkit(BaseToolkit):
Args:
repo_name (str): The name of the GitHub repository.
state (Literal["open", "closed", "all"]): The state of pull
- requests to retrieve. (default: :obj: `all`)
+ requests to retrieve. (default: :obj:`all`)
Options are:
- "open": Retrieve only open pull requests.
- "closed": Retrieve only closed pull requests.
@@ -285,7 +285,7 @@ class GithubToolkit(BaseToolkit):
repo_name (str): The name of the GitHub repository.
path (str): The repository path to start the traversal from.
empty string means starts from the root directory.
- (default: :obj: `""`)
+ (default: :obj:`""`)
Returns:
List[str]: A list of file paths within the specified directory
diff --git a/camel/toolkits/pptx_toolkit.py b/camel/toolkits/pptx_toolkit.py
index 862903526..35b7decd7 100644
--- a/camel/toolkits/pptx_toolkit.py
+++ b/camel/toolkits/pptx_toolkit.py
@@ -62,7 +62,7 @@ class PPTXToolkit(BaseToolkit):
output_dir (str): The default directory for output files.
Defaults to the current working directory.
timeout (Optional[float]): The timeout for the toolkit.
- (default: :obj: `None`)
+ (default: :obj:`None`)
"""
super().__init__(timeout=timeout)
self.output_dir = Path(output_dir).resolve()
@@ -120,7 +120,7 @@ class PPTXToolkit(BaseToolkit):
frame_paragraph: The paragraph to format.
text (str): The text to format.
set_color_to_white (bool): Whether to set the color to white.
- (default: :obj: `False`)
+ (default: :obj:`False`)
"""
from pptx.dml.color import RGBColor
@@ -170,7 +170,7 @@ class PPTXToolkit(BaseToolkit):
flat_items_list (List[Tuple[str, int]]): The list of items to be
displayed.
set_color_to_white (bool): Whether to set the font color to white.
- (default: :obj: `False`)
+ (default: :obj:`False`)
"""
if not flat_items_list:
logger.warning("Empty bullet point list provided")
@@ -368,7 +368,7 @@ class PPTXToolkit(BaseToolkit):
supplied, it is resolved to self.output_dir.
template (Optional[str]): The path to the template PPTX file.
Initializes a presentation from a given template file Or PPTX
- file. (default: :obj: `None`)
+ file. (default: :obj:`None`)
Returns:
str: A success message indicating the file was created.
diff --git a/camel/toolkits/sympy_toolkit.py b/camel/toolkits/sympy_toolkit.py
index 68fbad50e..cc62475bc 100644
--- a/camel/toolkits/sympy_toolkit.py
+++ b/camel/toolkits/sympy_toolkit.py
@@ -39,7 +39,7 @@ class SymPyToolkit(BaseToolkit):
Args:
default_variable (str): The default variable for
- operations (default: :obj: `x`)
+ operations (default: :obj:`x`)
"""
super().__init__(timeout=timeout)
self.default_variable = default_variable
diff --git a/camel/toolkits/task_planning_toolkit.py b/camel/toolkits/task_planning_toolkit.py
index 36695922f..4bcdf49a0 100644
--- a/camel/toolkits/task_planning_toolkit.py
+++ b/camel/toolkits/task_planning_toolkit.py
@@ -32,7 +32,7 @@ class TaskPlanningToolkit(BaseToolkit):
Args:
timeout (Optional[float]): The timeout for the toolkit.
- (default: :obj: `None`)
+ (default: :obj:`None`)
"""
super().__init__(timeout=timeout)
@@ -53,7 +53,7 @@ class TaskPlanningToolkit(BaseToolkit):
string is the content for a new sub-task.
original_task_id (Optional[str]): The id of the task to be
decomposed. If not provided, a new id will be generated.
- (default: :obj: `None`)
+ (default: :obj:`None`)
Returns:
List[Task]: A list of newly created sub-task objects.
@@ -99,7 +99,7 @@ class TaskPlanningToolkit(BaseToolkit):
sub_task_contents (List[str]): A list of strings, where each
string is the content for a new sub-task.
original_task_id (Optional[str]): The id of the task to be
- decomposed. (default: :obj: `None`)
+ decomposed. (default: :obj:`None`)
Returns:
List[Task]: Reordered or modified tasks.
diff --git a/camel/toolkits/thinking_toolkit.py b/camel/toolkits/thinking_toolkit.py
index 20a7f5e03..efe982266 100644
--- a/camel/toolkits/thinking_toolkit.py
+++ b/camel/toolkits/thinking_toolkit.py
@@ -32,7 +32,7 @@ class ThinkingToolkit(BaseToolkit):
Args:
timeout (Optional[float]): The timeout for the toolkit.
- (default: :obj: `None`)
+ (default: :obj:`None`)
"""
super().__init__(timeout=timeout)
self.plans: List[str] = []
diff --git a/examples/workforce/eigent.py b/examples/workforce/eigent.py
index df4c86c0c..630fb0755 100644
--- a/examples/workforce/eigent.py
+++ b/examples/workforce/eigent.py
@@ -15,7 +15,6 @@
import asyncio
from camel.agents.chat_agent import ChatAgent
-from camel.loaders import Firecrawl
from camel.messages.base import BaseMessage
from camel.models import BaseModelBackend, ModelFactory
from camel.societies.workforce import Workforce
@@ -47,7 +46,7 @@ def developer_agent_factory(model: BaseModelBackend, task_id: str):
r"""Factory for creating a developer agent."""
tools = [
*TerminalToolkit().get_tools(),
- *HumanToolkit().get_tools(),
+ HumanToolkit().ask_human_via_console,
*CodeExecutionToolkit().get_tools(),
]
@@ -88,15 +87,15 @@ async def search_agent_factory(
terminal_toolkits = TerminalToolkit()
human_toolkits = HumanToolkit()
tools = [
- FunctionTool(search_toolkits.search_wiki),
- # FunctionTool(search_toolkits.search_google),
+ # FunctionTool(search_toolkits.search_wiki),
+ FunctionTool(search_toolkits.search_google),
# FunctionTool(search_toolkits.search_bing),
# FunctionTool(search_toolkits.search_baidu),
*playwright_toolkit.get_tools(),
# *browser_toolkits.get_tools(),
*terminal_toolkits.get_tools(),
- *human_toolkits.get_tools(),
- Firecrawl().scrape,
+ human_toolkits.ask_human_via_console,
+ # Firecrawl().scrape,
]
system_message = """You are a helpful assistant that can search the web,
@@ -167,7 +166,7 @@ def document_agent_factory(model: BaseModelBackend, task_id: str):
*FileWriteToolkit().get_tools(),
*PPTXToolkit().get_tools(),
# *RetrievalToolkit().get_tools(),
- *HumanToolkit().get_tools(),
+ HumanToolkit().ask_human_via_console,
]
system_message = """You are a Document Processing Assistant specialized in
@@ -224,7 +223,7 @@ def multi_modal_agent_factory(model: BaseModelBackend, task_id: str):
*AudioAnalysisToolkit().get_tools(),
*ImageAnalysisToolkit().get_tools(),
*DalleToolkit().get_tools(),
- *HumanToolkit().get_tools(),
+ HumanToolkit().ask_human_via_console,
]
system_message = """You are a Multi-Modal Processing Assistant specialized
@@ -332,7 +331,7 @@ When assisting users, always:
*RedditToolkit().get_tools(),
*NotionToolkit().get_tools(),
*SlackToolkit().get_tools(),
- *HumanToolkit().get_tools(),
+ HumanToolkit().ask_human_via_console,
],
)
@@ -345,18 +344,18 @@ async def main():
# Create a single model backend for all agents
model_backend = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
- model_type=ModelType.GPT_4_1_MINI,
+ model_type=ModelType.GPT_4_1,
# model_config_dict={
- # "max_tokens": 64000,
- # }
+ # "max_tokens": 32768,
+ # },
)
model_backend_reason = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
- model_type=ModelType.O3_MINI,
+ model_type=ModelType.GPT_4_1,
# model_config_dict={
- # "max_tokens": 64000,
- # }
+ # "max_tokens": 32768,
+ # },
)
task_id = 'workforce_task'
@@ -386,14 +385,23 @@ async def main():
)
workforce.add_single_agent_worker(
- "Search & Information Retrieval Agent", worker=search_agent
+ "Search Agent: Can search the web, extract webpage content, "
+ "simulate browser actions, and provide relevant information to "
+ "solve the given task.",
+ worker=search_agent,
).add_single_agent_worker(
- "Software Development & Code Generation Agent",
+ "Developer Agent: A skilled coding assistant that can write and "
+ "execute code, run terminal commands, and verify solutions to "
+ "complete tasks.",
worker=developer_agent,
).add_single_agent_worker(
- "Document Creation & Management Agent", worker=document_agent
+ "Document Agent: A document processing assistant for creating, "
+ "modifying, and managing various document formats, including "
+ "presentations.",
+ worker=document_agent,
).add_single_agent_worker(
- "Multi-Modal Content Analysis & Generation Agent",
+ "Multi-Modal Agent: A multi-modal processing assistant for "
+ "analyzing, and generating media content like audio and images.",
worker=multi_modal_agent,
)