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

chore: fix workforce test, update example

Wendongfb5e02956ae2
diff --git a/camel/toolkits/jina_reranker_toolkit.py b/camel/toolkits/jina_reranker_toolkit.py
index 02e443340..0816e23ba 100644
--- a/camel/toolkits/jina_reranker_toolkit.py
+++ b/camel/toolkits/jina_reranker_toolkit.py
@@ -34,7 +34,7 @@ class JinaRerankerToolkit(BaseToolkit):
def __init__(
self,
timeout: Optional[float] = None,
- model_name: Optional[str] = "jinaai/jina-reranker-m0",
+ model_name: str = "jinaai/jina-reranker-m0",
device: Optional[str] = None,
use_api: bool = True,
) -> None:
@@ -44,9 +44,8 @@ class JinaRerankerToolkit(BaseToolkit):
timeout (Optional[float]): The timeout value for API requests
in seconds. If None, no timeout is applied.
(default: :obj:`None`)
- model_name (Optional[str]): The reranker model name. If None,
- will use the default model.
- (default: :obj:`None`)
+ model_name (str): The reranker model name.
+ (default: :obj:`"jinaai/jina-reranker-m0"`)
device (Optional[str]): Device to load the model on. If None,
will use CUDA if available, otherwise CPU.
Only effective when use_api=False.
diff --git a/camel/toolkits/video_download_toolkit.py b/camel/toolkits/video_download_toolkit.py
index 59754d047..4dac932cd 100644
--- a/camel/toolkits/video_download_toolkit.py
+++ b/camel/toolkits/video_download_toolkit.py
@@ -26,7 +26,7 @@ from PIL import Image
from camel.logger import get_logger
from camel.toolkits.base import BaseToolkit
from camel.toolkits.function_tool import FunctionTool
-from camel.utils import MCPServer, dependencies_required
+from camel.utils import dependencies_required
logger = get_logger(__name__)
@@ -57,7 +57,6 @@ def _capture_screenshot(video_file: str, timestamp: float) -> Image.Image:
return Image.open(io.BytesIO(out))
-@MCPServer()
class VideoDownloaderToolkit(BaseToolkit):
r"""A class for downloading videos and optionally splitting them into
chunks.
diff --git a/examples/workforce/eigent.py b/examples/workforce/eigent.py
index 82ff32400..b57bbeb11 100644
--- a/examples/workforce/eigent.py
+++ b/examples/workforce/eigent.py
@@ -15,6 +15,7 @@
import asyncio
from camel.agents.chat_agent import ChatAgent
+from camel.logger import get_logger
from camel.messages.base import BaseMessage
from camel.models import BaseModelBackend, ModelFactory
from camel.societies.workforce import Workforce
@@ -47,6 +48,34 @@ from camel.toolkits import (
from camel.types import ModelPlatformType, ModelType
from camel.utils.commons import api_keys_required
+logger = get_logger(__name__)
+
+
+def send_message_to_user(message: str) -> None:
+ r"""Use this tool to send a tidy message to the user, including a
+ short title and a one-sentence description.
+
+ This one-way tool keeps the user informed about your progress,
+ decisions, or actions. It does not require a response.
+ You should use it to:
+ - Announce what you are about to do (e.g.,
+ 'Starting Task\nSearching for papers on
+ GUI Agents.').
+ - Report the result of an action (e.g.,
+ 'Search Complete\nFound 15 relevant
+ papers.').
+ - State a decision (e.g.,
+ 'Next Step\nAnalyzing the top 10
+ papers.').
+ - Give a status update during a long-running task.
+
+ Args:
+ message (str): The tidy and informative message for the user,
+ which should contain a title and a description.
+ """
+ print(f"\nAgent Message:\n{message}")
+ logger.info(f"\nAgent Message:\n{message}")
+
def developer_agent_factory(
model: BaseModelBackend,
@@ -55,7 +84,8 @@ def developer_agent_factory(
):
r"""Factory for creating a developer agent."""
tools = [
- *HumanToolkit().get_tools(),
+ send_message_to_user,
+ HumanToolkit().ask_human_via_console,
*TerminalToolkit(clone_current_env=True).get_tools(),
*CodeExecutionToolkit().get_tools(),
*edgeone_pages_mcp_toolkit.get_tools(),
@@ -64,8 +94,8 @@ def developer_agent_factory(
system_message = """You are a skilled coding assistant with DIRECT CODE
EXECUTION CAPABILITIES. You MUST use the `send_message_to_user` tool to
inform the user of every decision and action you take. Your message must
- be tidy and in one short sentence. This is a mandatory part of your
- workflow.
+ include a short title and a one-sentence description. This is a
+ mandatory part of your workflow.
Your capabilities include:
- WRITE AND EXECUTE code in real-time to solve tasks
@@ -112,7 +142,8 @@ def search_agent_factory(
# FunctionTool(SearchToolkit().search_baidu),
*BrowserNonVisualToolkit(headless=False).get_tools(),
*TerminalToolkit().get_tools(),
- *HumanToolkit().get_tools(),
+ send_message_to_user,
+ HumanToolkit().ask_human_via_console,
*Crawl4AIToolkit().get_tools(),
]
@@ -121,8 +152,9 @@ def search_agent_factory(
information to solve the given task.
You MUST use the `send_message_to_user` tool to inform the user of every
- decision and action you take. Your message must be tidy and in one short
- sentence. This is a mandatory part of your workflow.
+ decision and action you take. Your message must include a short title
+ and a one-sentence description. This is a mandatory part of your
+ workflow.
Keep in mind that:
- For each decision you make and action you take, you must send a message
@@ -195,7 +227,8 @@ def document_agent_factory(
*PPTXToolkit().get_tools(),
# *google_drive_mcp_toolkit.get_tools(),
# *RetrievalToolkit().get_tools(),
- *HumanToolkit().get_tools(),
+ send_message_to_user,
+ HumanToolkit().ask_human_via_console,
*MarkItDownToolkit().get_tools(),
*ExcelToolkit().get_tools(),
]
@@ -203,8 +236,8 @@ def document_agent_factory(
system_message = """You are a Document Processing Assistant specialized in
creating, modifying, and managing various document formats. You MUST use
the `send_message_to_user` tool to inform the user of every decision and
- action you take. Your message must be tidy and in one short sentence.
- This is a mandatory part of your workflow.
+ action you take. Your message must include a short title and a
+ one-sentence description. This is a mandatory part of your workflow.
Your capabilities include:
@@ -275,14 +308,15 @@ def multi_modal_agent_factory(model: BaseModelBackend, task_id: str):
*AudioAnalysisToolkit().get_tools(),
*ImageAnalysisToolkit().get_tools(),
*DalleToolkit().get_tools(),
- *HumanToolkit().get_tools(),
+ send_message_to_user,
+ HumanToolkit().ask_human_via_console,
]
system_message = """You are a Multi-Modal Processing Assistant specialized
in analyzing and generating various types of media content. You MUST use
the `send_message_to_user` tool to inform the user of every decision and
- action you take. Your message must be tidy and in one short sentence.
- This is a mandatory part of your workflow.
+ action you take. Your message must include a short title and a
+ one-sentence description. This is a mandatory part of your workflow.
Your capabilities include:
@@ -336,8 +370,9 @@ def social_medium_agent_factory(model: BaseModelBackend, task_id: str):
content="""
You are a Social Media Management Assistant with comprehensive capabilities
across multiple platforms. You MUST use the `send_message_to_user` tool to
-inform the user of every decision and action you take. Your message must be
-tidy and in one short sentence. This is a mandatory part of your workflow.
+inform the user of every decision and action you take. Your message must
+include a short title and a one-sentence description. This is a mandatory
+part of your workflow.
Your integrated toolkits enable you to:
@@ -390,7 +425,8 @@ operations.
*RedditToolkit().get_tools(),
*NotionToolkit().get_tools(),
*SlackToolkit().get_tools(),
- *HumanToolkit().get_tools(),
+ send_message_to_user,
+ HumanToolkit().ask_human_via_console,
],
)
@@ -427,38 +463,35 @@ async def main():
coordinator_agent = ChatAgent(
"You are a helpful coordinator. You MUST use the "
"`send_message_to_user` tool to inform the user of every "
- "decision and action you take. Your message must be tidy "
- "and in one short sentence. This is a mandatory part of "
- "your workflow.",
+ "decision and action you take. Your message must include a short "
+ "title and a one-sentence description. This is a mandatory part "
+ "of your workflow.",
model=model_backend_reason,
tools=[
- *HumanToolkit().get_tools(),
+ send_message_to_user,
],
)
task_agent = ChatAgent(
"You are a helpful task planner. You MUST use the "
"`send_message_to_user` tool to inform the user of every decision "
- "and action you take. Each message must be a single, concise "
- "sentence. This is a mandatory part of your workflow.\n\n"
- "Carefully examine the user's task. If it's a simple greeting, a "
- "direct question, or a conversational interaction (like 'hello' "
- "or 'thank you'), create a single task for a worker to respond "
- "directly using the `send_message_to_user` tool. For example, if "
- "the user says 'hello', create a task like: 'Respond to the "
- "user's greeting directly using the `send_message_to_user` tool.'",
+ "and action you take. Your message must include a short title and "
+ "a one-sentence description. This is a mandatory part of your "
+ "workflow.",
model=model_backend_reason,
tools=[
- *HumanToolkit().get_tools(),
+ send_message_to_user,
],
)
new_worker_agent = ChatAgent(
"You are a helpful worker. You MUST use the "
"`send_message_to_user` tool to inform the user of every "
- "decision and action you take. Your message must be tidy and in "
- "one short sentence. This is a mandatory part of your workflow.",
+ "decision and action you take. Your message must include a short "
+ "title and a one-sentence description. This is a mandatory part "
+ "of your workflow.",
model=model_backend,
tools=[
- *HumanToolkit().get_tools(),
+ send_message_to_user,
+ HumanToolkit().ask_human_via_console,
],
)
diff --git a/test/workforce/test_workforce.py b/test/workforce/test_workforce.py
index 6fa37ef54..3a8f8e976 100644
--- a/test/workforce/test_workforce.py
+++ b/test/workforce/test_workforce.py
@@ -73,12 +73,15 @@ async def test_post_task_timeout():
mock_task = MagicMock(spec=Task)
mock_task.id = "test_task_id"
- # Only verify that a TimeoutError is raised, not its specific message
- with pytest.raises(asyncio.TimeoutError):
- await workforce._post_task(mock_task, "test_worker_id")
+ # Since _post_task catches TimeoutError and doesn't re-raise it,
+ # we should test that it completes without raising an exception
+ # and that the in_flight_tasks counter is properly decremented
+ workforce._in_flight_tasks = 0
+ await workforce._post_task(mock_task, "test_worker_id")
# Verify the channel method was called
mock_channel.post_task.assert_called_once()
+ assert workforce._in_flight_tasks == 0
@pytest.mark.asyncio
@@ -123,11 +126,8 @@ async def test_listen_to_channel_recovers_from_timeout():
# Post initial ready tasks
await workforce._post_ready_tasks()
- # try to get returned task - should raise TimeoutError
- with pytest.raises(
- asyncio.TimeoutError, match="Simulated timeout"
- ):
- await workforce._get_returned_task()
+ returned_task_first = await workforce._get_returned_task()
+ assert returned_task_first is None # Should return None on timeout
# Ensure the mock was called for the first attempt
assert mock_channel.get_returned_task_by_publisher.call_count == 1
@@ -226,6 +226,7 @@ async def test_multiple_timeout_points():
mock_task.content = "Test task content"
mock_task.additional_info = {}
mock_task.result = "Mock task failed"
+ mock_task.assigned_worker_id = "test_worker_id"
mock_task.failure_count = 0
mock_task.get_depth.return_value = 0
@@ -250,13 +251,8 @@ async def test_multiple_timeout_points():
# Get task - should succeed
returned_task = await workforce._get_returned_task()
- # Handle failed task - should timeout during remove_task
- try:
+ with pytest.raises(asyncio.TimeoutError):
await workforce._handle_failed_task(returned_task)
- raise AssertionError("Should have timed out on first attempt")
- except asyncio.TimeoutError:
- # This is expected
- pass
finally:
workforce._running = False