camel-ai 0.2.71a11__py3-none-any.whl → 0.2.71a12__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of camel-ai might be problematic. Click here for more details.
- camel/__init__.py +1 -1
- camel/agents/chat_agent.py +1 -1
- camel/societies/workforce/prompts.py +1 -1
- camel/societies/workforce/role_playing_worker.py +1 -1
- camel/societies/workforce/worker.py +1 -1
- camel/societies/workforce/workforce.py +53 -18
- camel/tasks/task.py +9 -5
- camel/toolkits/search_toolkit.py +49 -46
- camel/utils/tool_result.py +1 -1
- {camel_ai-0.2.71a11.dist-info → camel_ai-0.2.71a12.dist-info}/METADATA +1 -1
- {camel_ai-0.2.71a11.dist-info → camel_ai-0.2.71a12.dist-info}/RECORD +13 -13
- {camel_ai-0.2.71a11.dist-info → camel_ai-0.2.71a12.dist-info}/WHEEL +0 -0
- {camel_ai-0.2.71a11.dist-info → camel_ai-0.2.71a12.dist-info}/licenses/LICENSE +0 -0
camel/__init__.py
CHANGED
camel/agents/chat_agent.py
CHANGED
|
@@ -147,7 +147,7 @@ Here is the content of the parent task for you to refer to:
|
|
|
147
147
|
Here are results of some prerequisite tasks that you can refer to:
|
|
148
148
|
|
|
149
149
|
==============================
|
|
150
|
-
{
|
|
150
|
+
{dependency_tasks_info}
|
|
151
151
|
==============================
|
|
152
152
|
|
|
153
153
|
Here are some additional information about the task:
|
|
@@ -122,7 +122,7 @@ class RolePlayingWorker(Worker):
|
|
|
122
122
|
prompt = ROLEPLAY_PROCESS_TASK_PROMPT.format(
|
|
123
123
|
content=task.content,
|
|
124
124
|
parent_task_content=task.parent.content if task.parent else "",
|
|
125
|
-
|
|
125
|
+
dependency_tasks_info=dependency_tasks_info,
|
|
126
126
|
additional_info=task.additional_info,
|
|
127
127
|
)
|
|
128
128
|
role_play_session = RolePlaying(
|
|
@@ -1008,7 +1008,7 @@ class Workforce(BaseNode):
|
|
|
1008
1008
|
if not validate_task_content(new_content, task_id):
|
|
1009
1009
|
logger.warning(
|
|
1010
1010
|
f"Task {task_id} content modification rejected: "
|
|
1011
|
-
f"Invalid content. Content preview: '{new_content
|
|
1011
|
+
f"Invalid content. Content preview: '{new_content}'"
|
|
1012
1012
|
)
|
|
1013
1013
|
return False
|
|
1014
1014
|
|
|
@@ -1194,7 +1194,7 @@ class Workforce(BaseNode):
|
|
|
1194
1194
|
task.result = "Task failed: Invalid or empty content provided"
|
|
1195
1195
|
logger.warning(
|
|
1196
1196
|
f"Task {task.id} rejected: Invalid or empty content. "
|
|
1197
|
-
f"Content preview: '{task.content
|
|
1197
|
+
f"Content preview: '{task.content}'"
|
|
1198
1198
|
)
|
|
1199
1199
|
return task
|
|
1200
1200
|
|
|
@@ -1327,7 +1327,7 @@ class Workforce(BaseNode):
|
|
|
1327
1327
|
task.result = "Task failed: Invalid or empty content provided"
|
|
1328
1328
|
logger.warning(
|
|
1329
1329
|
f"Task {task.id} rejected: Invalid or empty content. "
|
|
1330
|
-
f"Content preview: '{task.content
|
|
1330
|
+
f"Content preview: '{task.content}'"
|
|
1331
1331
|
)
|
|
1332
1332
|
return task
|
|
1333
1333
|
|
|
@@ -1853,7 +1853,7 @@ class Workforce(BaseNode):
|
|
|
1853
1853
|
logger.error(
|
|
1854
1854
|
f"JSON parsing error in task assignment: Invalid response "
|
|
1855
1855
|
f"format - {e}. Response content: "
|
|
1856
|
-
f"{response.msg.content
|
|
1856
|
+
f"{response.msg.content}"
|
|
1857
1857
|
)
|
|
1858
1858
|
return TaskAssignResult(assignments=[])
|
|
1859
1859
|
|
|
@@ -1985,6 +1985,37 @@ class Workforce(BaseNode):
|
|
|
1985
1985
|
|
|
1986
1986
|
return final_assignments
|
|
1987
1987
|
|
|
1988
|
+
def _update_task_dependencies_from_assignments(
|
|
1989
|
+
self, assignments: List[TaskAssignment], tasks: List[Task]
|
|
1990
|
+
) -> None:
|
|
1991
|
+
r"""Update Task.dependencies with actual Task objects based on
|
|
1992
|
+
assignments.
|
|
1993
|
+
|
|
1994
|
+
Args:
|
|
1995
|
+
assignments (List[TaskAssignment]): The task assignments
|
|
1996
|
+
containing dependency IDs.
|
|
1997
|
+
tasks (List[Task]): The tasks that were assigned.
|
|
1998
|
+
"""
|
|
1999
|
+
# Create a lookup map for all available tasks
|
|
2000
|
+
all_tasks = {}
|
|
2001
|
+
for task_list in [self._completed_tasks, self._pending_tasks, tasks]:
|
|
2002
|
+
for task in task_list:
|
|
2003
|
+
all_tasks[task.id] = task
|
|
2004
|
+
|
|
2005
|
+
# Update dependencies for each assigned task
|
|
2006
|
+
for assignment in assignments:
|
|
2007
|
+
if not assignment.dependencies:
|
|
2008
|
+
continue
|
|
2009
|
+
|
|
2010
|
+
matching_tasks = [t for t in tasks if t.id == assignment.task_id]
|
|
2011
|
+
if matching_tasks:
|
|
2012
|
+
task = matching_tasks[0]
|
|
2013
|
+
task.dependencies = [
|
|
2014
|
+
all_tasks[dep_id]
|
|
2015
|
+
for dep_id in assignment.dependencies
|
|
2016
|
+
if dep_id in all_tasks
|
|
2017
|
+
]
|
|
2018
|
+
|
|
1988
2019
|
async def _find_assignee(
|
|
1989
2020
|
self,
|
|
1990
2021
|
tasks: List[Task],
|
|
@@ -2021,19 +2052,24 @@ class Workforce(BaseNode):
|
|
|
2021
2052
|
|
|
2022
2053
|
# if all assignments are valid and all tasks are assigned, return early
|
|
2023
2054
|
if not invalid_assignments and not unassigned_tasks:
|
|
2055
|
+
self._update_task_dependencies_from_assignments(
|
|
2056
|
+
valid_assignments, tasks
|
|
2057
|
+
)
|
|
2024
2058
|
return TaskAssignResult(assignments=valid_assignments)
|
|
2025
2059
|
|
|
2026
|
-
# handle retry and fallback for
|
|
2027
|
-
#
|
|
2028
|
-
all_problem_assignments = invalid_assignments
|
|
2060
|
+
# handle retry and fallback for invalid assignments and unassigned
|
|
2061
|
+
# tasks
|
|
2029
2062
|
retry_and_fallback_assignments = (
|
|
2030
2063
|
await self._handle_assignment_retry_and_fallback(
|
|
2031
|
-
|
|
2064
|
+
invalid_assignments, tasks, valid_worker_ids
|
|
2032
2065
|
)
|
|
2033
2066
|
)
|
|
2034
|
-
valid_assignments
|
|
2067
|
+
all_assignments = valid_assignments + retry_and_fallback_assignments
|
|
2068
|
+
|
|
2069
|
+
# Update Task.dependencies for all final assignments
|
|
2070
|
+
self._update_task_dependencies_from_assignments(all_assignments, tasks)
|
|
2035
2071
|
|
|
2036
|
-
return TaskAssignResult(assignments=
|
|
2072
|
+
return TaskAssignResult(assignments=all_assignments)
|
|
2037
2073
|
|
|
2038
2074
|
async def _post_task(self, task: Task, assignee_id: str) -> None:
|
|
2039
2075
|
# Record the start time when a task is posted
|
|
@@ -2107,7 +2143,7 @@ class Workforce(BaseNode):
|
|
|
2107
2143
|
)
|
|
2108
2144
|
new_node_conf = WorkerConf(
|
|
2109
2145
|
description=f"Fallback worker for task: "
|
|
2110
|
-
f"{task.content
|
|
2146
|
+
f"{task.content}",
|
|
2111
2147
|
role="General Assistant",
|
|
2112
2148
|
sys_msg="You are a general assistant that can help "
|
|
2113
2149
|
"with various tasks.",
|
|
@@ -2117,8 +2153,7 @@ class Workforce(BaseNode):
|
|
|
2117
2153
|
response.msg.content,
|
|
2118
2154
|
schema=WorkerConf,
|
|
2119
2155
|
fallback_values={
|
|
2120
|
-
"description": f"Worker for task: "
|
|
2121
|
-
f"{task.content[:50]}...",
|
|
2156
|
+
"description": f"Worker for task: " f"{task.content}",
|
|
2122
2157
|
"role": "Task Specialist",
|
|
2123
2158
|
"sys_msg": f"You are a specialist for: {task.content}",
|
|
2124
2159
|
},
|
|
@@ -2130,7 +2165,7 @@ class Workforce(BaseNode):
|
|
|
2130
2165
|
new_node_conf = WorkerConf(**result)
|
|
2131
2166
|
else:
|
|
2132
2167
|
new_node_conf = WorkerConf(
|
|
2133
|
-
description=f"Worker for task: {task.content
|
|
2168
|
+
description=f"Worker for task: {task.content}",
|
|
2134
2169
|
role="Task Specialist",
|
|
2135
2170
|
sys_msg=f"You are a specialist for: {task.content}",
|
|
2136
2171
|
)
|
|
@@ -2147,7 +2182,7 @@ class Workforce(BaseNode):
|
|
|
2147
2182
|
# Create a fallback worker configuration
|
|
2148
2183
|
new_node_conf = WorkerConf(
|
|
2149
2184
|
description=f"Fallback worker for "
|
|
2150
|
-
f"task: {task.content
|
|
2185
|
+
f"task: {task.content}",
|
|
2151
2186
|
role="General Assistant",
|
|
2152
2187
|
sys_msg="You are a general assistant that can help "
|
|
2153
2188
|
"with various tasks.",
|
|
@@ -2160,7 +2195,7 @@ class Workforce(BaseNode):
|
|
|
2160
2195
|
logger.error(
|
|
2161
2196
|
f"JSON parsing error in worker creation: Invalid "
|
|
2162
2197
|
f"response format - {e}. Response content: "
|
|
2163
|
-
f"{response.msg.content
|
|
2198
|
+
f"{response.msg.content}"
|
|
2164
2199
|
)
|
|
2165
2200
|
raise RuntimeError(
|
|
2166
2201
|
f"Failed to create worker for task {task.id}: "
|
|
@@ -2364,7 +2399,7 @@ class Workforce(BaseNode):
|
|
|
2364
2399
|
f"Task {task.id} has exceeded maximum retry attempts "
|
|
2365
2400
|
f"({MAX_TASK_RETRIES}). Final failure "
|
|
2366
2401
|
f"reason: {detailed_error}. "
|
|
2367
|
-
f"Task content: '{task.content
|
|
2402
|
+
f"Task content: '{task.content}'"
|
|
2368
2403
|
)
|
|
2369
2404
|
self._cleanup_task_tracking(task.id)
|
|
2370
2405
|
# Mark task as completed for dependency tracking before halting
|
|
@@ -2793,7 +2828,7 @@ class Workforce(BaseNode):
|
|
|
2793
2828
|
# useful results
|
|
2794
2829
|
if is_task_result_insufficient(returned_task):
|
|
2795
2830
|
result_preview = (
|
|
2796
|
-
returned_task.result
|
|
2831
|
+
returned_task.result
|
|
2797
2832
|
if returned_task.result
|
|
2798
2833
|
else "No result"
|
|
2799
2834
|
)
|
camel/tasks/task.py
CHANGED
|
@@ -99,7 +99,7 @@ def validate_task_content(
|
|
|
99
99
|
logger.warning(
|
|
100
100
|
f"Task {task_id}: Content too short ({len(stripped_content)} "
|
|
101
101
|
f"chars < {min_length} minimum). Content preview: "
|
|
102
|
-
f"'{stripped_content
|
|
102
|
+
f"'{stripped_content}'"
|
|
103
103
|
)
|
|
104
104
|
return False
|
|
105
105
|
|
|
@@ -124,7 +124,7 @@ def validate_task_content(
|
|
|
124
124
|
if any(indicator in content_lower for indicator in failure_indicators):
|
|
125
125
|
logger.warning(
|
|
126
126
|
f"Task {task_id}: Failure indicator detected in result. "
|
|
127
|
-
f"Content preview: '{stripped_content
|
|
127
|
+
f"Content preview: '{stripped_content}'"
|
|
128
128
|
)
|
|
129
129
|
return False
|
|
130
130
|
|
|
@@ -132,7 +132,7 @@ def validate_task_content(
|
|
|
132
132
|
if content_lower.startswith(("error", "failed", "cannot", "unable")):
|
|
133
133
|
logger.warning(
|
|
134
134
|
f"Task {task_id}: Error/refusal pattern detected at start. "
|
|
135
|
-
f"Content preview: '{stripped_content
|
|
135
|
+
f"Content preview: '{stripped_content}'"
|
|
136
136
|
)
|
|
137
137
|
return False
|
|
138
138
|
|
|
@@ -195,7 +195,7 @@ def parse_response(
|
|
|
195
195
|
logger.warning(
|
|
196
196
|
f"Skipping invalid subtask {task_id}.{i} "
|
|
197
197
|
f"during decomposition: "
|
|
198
|
-
f"Content '{stripped_content
|
|
198
|
+
f"Content '{stripped_content}' failed validation"
|
|
199
199
|
)
|
|
200
200
|
return tasks
|
|
201
201
|
|
|
@@ -233,6 +233,8 @@ class Task(BaseModel):
|
|
|
233
233
|
(default: :obj:`0`)
|
|
234
234
|
assigned_worker_id (Optional[str]): The ID of the worker assigned to
|
|
235
235
|
this task. (default: :obj:`None`)
|
|
236
|
+
dependencies (List[Task]): The dependencies for the task.
|
|
237
|
+
(default: :obj:`[]`)
|
|
236
238
|
additional_info (Optional[Dict[str, Any]]): Additional information for
|
|
237
239
|
the task. (default: :obj:`None`)
|
|
238
240
|
image_list (Optional[List[Image.Image]]): Optional list of PIL Image
|
|
@@ -265,6 +267,8 @@ class Task(BaseModel):
|
|
|
265
267
|
|
|
266
268
|
assigned_worker_id: Optional[str] = None
|
|
267
269
|
|
|
270
|
+
dependencies: List["Task"] = []
|
|
271
|
+
|
|
268
272
|
additional_info: Optional[Dict[str, Any]] = None
|
|
269
273
|
|
|
270
274
|
image_list: Optional[List[Image.Image]] = None
|
|
@@ -530,7 +534,7 @@ class Task(BaseModel):
|
|
|
530
534
|
logger.warning(
|
|
531
535
|
f"Skipping invalid subtask {task_id}.{i} "
|
|
532
536
|
f"during streaming decomposition: "
|
|
533
|
-
f"Content '{stripped_content
|
|
537
|
+
f"Content '{stripped_content}' failed validation"
|
|
534
538
|
)
|
|
535
539
|
return tasks
|
|
536
540
|
|
camel/toolkits/search_toolkit.py
CHANGED
|
@@ -32,6 +32,23 @@ class SearchToolkit(BaseToolkit):
|
|
|
32
32
|
search engines like Google, DuckDuckGo, Wikipedia and Wolfram Alpha, Brave.
|
|
33
33
|
"""
|
|
34
34
|
|
|
35
|
+
def __init__(
|
|
36
|
+
self,
|
|
37
|
+
timeout: Optional[float] = None,
|
|
38
|
+
number_of_result_pages: int = 10,
|
|
39
|
+
):
|
|
40
|
+
r"""Initializes the RedditToolkit with the specified number of retries
|
|
41
|
+
and delay.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
timeout (float): Timeout for API requests in seconds.
|
|
45
|
+
(default: :obj:`None`)
|
|
46
|
+
number_of_result_pages (int): The number of result pages to
|
|
47
|
+
retrieve. (default: :obj:`10`)
|
|
48
|
+
"""
|
|
49
|
+
super().__init__(timeout=timeout)
|
|
50
|
+
self.number_of_result_pages = number_of_result_pages
|
|
51
|
+
|
|
35
52
|
@dependencies_required("wikipedia")
|
|
36
53
|
def search_wiki(self, entity: str) -> str:
|
|
37
54
|
r"""Search the entity in WikiPedia and return the summary of the
|
|
@@ -144,7 +161,7 @@ class SearchToolkit(BaseToolkit):
|
|
|
144
161
|
|
|
145
162
|
@dependencies_required("duckduckgo_search")
|
|
146
163
|
def search_duckduckgo(
|
|
147
|
-
self, query: str, source: str = "text"
|
|
164
|
+
self, query: str, source: str = "text"
|
|
148
165
|
) -> List[Dict[str, Any]]:
|
|
149
166
|
r"""Use DuckDuckGo search engine to search information for
|
|
150
167
|
the given query.
|
|
@@ -157,7 +174,6 @@ class SearchToolkit(BaseToolkit):
|
|
|
157
174
|
query (str): The query to be searched.
|
|
158
175
|
source (str): The type of information to query (e.g., "text",
|
|
159
176
|
"images", "videos"). Defaults to "text".
|
|
160
|
-
max_results (int): Max number of results, defaults to `5`.
|
|
161
177
|
|
|
162
178
|
Returns:
|
|
163
179
|
List[Dict[str, Any]]: A list of dictionaries where each dictionary
|
|
@@ -171,7 +187,9 @@ class SearchToolkit(BaseToolkit):
|
|
|
171
187
|
|
|
172
188
|
if source == "text":
|
|
173
189
|
try:
|
|
174
|
-
results = ddgs.text(
|
|
190
|
+
results = ddgs.text(
|
|
191
|
+
keywords=query, max_results=self.number_of_result_pages
|
|
192
|
+
)
|
|
175
193
|
except RequestException as e:
|
|
176
194
|
# Handle specific exceptions or general request exceptions
|
|
177
195
|
responses.append({"error": f"duckduckgo search failed.{e}"})
|
|
@@ -189,7 +207,9 @@ class SearchToolkit(BaseToolkit):
|
|
|
189
207
|
|
|
190
208
|
elif source == "images":
|
|
191
209
|
try:
|
|
192
|
-
results = ddgs.images(
|
|
210
|
+
results = ddgs.images(
|
|
211
|
+
keywords=query, max_results=self.number_of_result_pages
|
|
212
|
+
)
|
|
193
213
|
except RequestException as e:
|
|
194
214
|
# Handle specific exceptions or general request exceptions
|
|
195
215
|
responses.append({"error": f"duckduckgo search failed.{e}"})
|
|
@@ -208,7 +228,9 @@ class SearchToolkit(BaseToolkit):
|
|
|
208
228
|
|
|
209
229
|
elif source == "videos":
|
|
210
230
|
try:
|
|
211
|
-
results = ddgs.videos(
|
|
231
|
+
results = ddgs.videos(
|
|
232
|
+
keywords=query, max_results=self.number_of_result_pages
|
|
233
|
+
)
|
|
212
234
|
except RequestException as e:
|
|
213
235
|
# Handle specific exceptions or general request exceptions
|
|
214
236
|
responses.append({"error": f"duckduckgo search failed.{e}"})
|
|
@@ -241,7 +263,6 @@ class SearchToolkit(BaseToolkit):
|
|
|
241
263
|
country: str = "US",
|
|
242
264
|
search_lang: str = "en",
|
|
243
265
|
ui_lang: str = "en-US",
|
|
244
|
-
count: int = 20,
|
|
245
266
|
offset: int = 0,
|
|
246
267
|
safesearch: str = "moderate",
|
|
247
268
|
freshness: Optional[str] = None,
|
|
@@ -277,10 +298,6 @@ class SearchToolkit(BaseToolkit):
|
|
|
277
298
|
Format: '<language_code>-<country_code>'. Common examples:
|
|
278
299
|
'en-US', 'en-GB', 'jp-JP', 'zh-hans-CN', 'zh-hant-TW',
|
|
279
300
|
'de-DE', 'fr-FR', 'es-ES', 'pt-BR', 'ru-RU', 'ko-KR'.
|
|
280
|
-
count (int): The number of search results returned in response.
|
|
281
|
-
The maximum is 20. The actual number delivered may be less than
|
|
282
|
-
requested. Combine this parameter with offset to paginate
|
|
283
|
-
search results.
|
|
284
301
|
offset (int): The zero based offset that indicates number of search
|
|
285
302
|
results per page (count) to skip before returning the result.
|
|
286
303
|
The maximum is 9. The actual number delivered may be less than
|
|
@@ -368,7 +385,7 @@ class SearchToolkit(BaseToolkit):
|
|
|
368
385
|
"country": country,
|
|
369
386
|
"search_lang": search_lang,
|
|
370
387
|
"ui_lang": ui_lang,
|
|
371
|
-
"count":
|
|
388
|
+
"count": self.number_of_result_pages,
|
|
372
389
|
"offset": offset,
|
|
373
390
|
"safesearch": safesearch,
|
|
374
391
|
"freshness": freshness,
|
|
@@ -417,14 +434,11 @@ class SearchToolkit(BaseToolkit):
|
|
|
417
434
|
(None, 'SEARCH_ENGINE_ID'),
|
|
418
435
|
]
|
|
419
436
|
)
|
|
420
|
-
def search_google(
|
|
421
|
-
self, query: str, num_result_pages: int = 5
|
|
422
|
-
) -> List[Dict[str, Any]]:
|
|
437
|
+
def search_google(self, query: str) -> List[Dict[str, Any]]:
|
|
423
438
|
r"""Use Google search engine to search information for the given query.
|
|
424
439
|
|
|
425
440
|
Args:
|
|
426
441
|
query (str): The query to be searched.
|
|
427
|
-
num_result_pages (int): The number of result pages to retrieve.
|
|
428
442
|
|
|
429
443
|
Returns:
|
|
430
444
|
List[Dict[str, Any]]: A list of dictionaries where each dictionary
|
|
@@ -461,14 +475,12 @@ class SearchToolkit(BaseToolkit):
|
|
|
461
475
|
start_page_idx = 1
|
|
462
476
|
# Different language may get different result
|
|
463
477
|
search_language = "en"
|
|
464
|
-
# How many pages to return
|
|
465
|
-
num_result_pages = num_result_pages
|
|
466
478
|
# Constructing the URL
|
|
467
479
|
# Doc: https://developers.google.com/custom-search/v1/using_rest
|
|
468
480
|
url = (
|
|
469
481
|
f"https://www.googleapis.com/customsearch/v1?"
|
|
470
482
|
f"key={GOOGLE_API_KEY}&cx={SEARCH_ENGINE_ID}&q={query}&start="
|
|
471
|
-
f"{start_page_idx}&lr={search_language}&num={
|
|
483
|
+
f"{start_page_idx}&lr={search_language}&num={self.number_of_result_pages}"
|
|
472
484
|
)
|
|
473
485
|
|
|
474
486
|
responses = []
|
|
@@ -529,15 +541,11 @@ class SearchToolkit(BaseToolkit):
|
|
|
529
541
|
responses.append({"error": f"google search failed: {e!s}"})
|
|
530
542
|
return responses
|
|
531
543
|
|
|
532
|
-
def tavily_search(
|
|
533
|
-
self, query: str, num_results: int = 5, **kwargs
|
|
534
|
-
) -> List[Dict[str, Any]]:
|
|
544
|
+
def tavily_search(self, query: str, **kwargs) -> List[Dict[str, Any]]:
|
|
535
545
|
r"""Use Tavily Search API to search information for the given query.
|
|
536
546
|
|
|
537
547
|
Args:
|
|
538
548
|
query (str): The query to be searched.
|
|
539
|
-
num_results (int): The number of search results to retrieve
|
|
540
|
-
(default is `5`).
|
|
541
549
|
**kwargs: Additional optional parameters supported by Tavily's API:
|
|
542
550
|
- search_depth (str): "basic" or "advanced" search depth.
|
|
543
551
|
- topic (str): The search category, e.g., "general" or "news."
|
|
@@ -573,7 +581,9 @@ class SearchToolkit(BaseToolkit):
|
|
|
573
581
|
client = TavilyClient(Tavily_API_KEY)
|
|
574
582
|
|
|
575
583
|
try:
|
|
576
|
-
results = client.search(
|
|
584
|
+
results = client.search(
|
|
585
|
+
query, max_results=self.number_of_result_pages, **kwargs
|
|
586
|
+
)
|
|
577
587
|
return results
|
|
578
588
|
except Exception as e:
|
|
579
589
|
return [{"error": f"An unexpected error occurred: {e!s}"}]
|
|
@@ -584,7 +594,6 @@ class SearchToolkit(BaseToolkit):
|
|
|
584
594
|
query: str,
|
|
585
595
|
freshness: str = "noLimit",
|
|
586
596
|
summary: bool = False,
|
|
587
|
-
count: int = 10,
|
|
588
597
|
page: int = 1,
|
|
589
598
|
) -> Dict[str, Any]:
|
|
590
599
|
r"""Query the Bocha AI search API and return search results.
|
|
@@ -600,7 +609,6 @@ class SearchToolkit(BaseToolkit):
|
|
|
600
609
|
- 'oneYear': past year.
|
|
601
610
|
summary (bool): Whether to include text summaries in results.
|
|
602
611
|
Default is False.
|
|
603
|
-
count (int): Number of results to return (1-50). Default is 10.
|
|
604
612
|
page (int): Page number of results. Default is 1.
|
|
605
613
|
|
|
606
614
|
Returns:
|
|
@@ -623,7 +631,7 @@ class SearchToolkit(BaseToolkit):
|
|
|
623
631
|
"query": query,
|
|
624
632
|
"freshness": freshness,
|
|
625
633
|
"summary": summary,
|
|
626
|
-
"count":
|
|
634
|
+
"count": self.number_of_result_pages,
|
|
627
635
|
"page": page,
|
|
628
636
|
},
|
|
629
637
|
ensure_ascii=False,
|
|
@@ -641,15 +649,13 @@ class SearchToolkit(BaseToolkit):
|
|
|
641
649
|
except requests.exceptions.RequestException as e:
|
|
642
650
|
return {"error": f"Bocha AI search failed: {e!s}"}
|
|
643
651
|
|
|
644
|
-
def search_baidu(self, query: str
|
|
652
|
+
def search_baidu(self, query: str) -> Dict[str, Any]:
|
|
645
653
|
r"""Search Baidu using web scraping to retrieve relevant search
|
|
646
654
|
results. This method queries Baidu's search engine and extracts search
|
|
647
655
|
results including titles, descriptions, and URLs.
|
|
648
656
|
|
|
649
657
|
Args:
|
|
650
658
|
query (str): Search query string to submit to Baidu.
|
|
651
|
-
max_results (int): Maximum number of results to return.
|
|
652
|
-
(default: :obj:`5`)
|
|
653
659
|
|
|
654
660
|
Returns:
|
|
655
661
|
Dict[str, Any]: A dictionary containing search results or error
|
|
@@ -667,7 +673,7 @@ class SearchToolkit(BaseToolkit):
|
|
|
667
673
|
),
|
|
668
674
|
"Referer": "https://www.baidu.com",
|
|
669
675
|
}
|
|
670
|
-
params = {"wd": query, "rn": str(
|
|
676
|
+
params = {"wd": query, "rn": str(self.number_of_result_pages)}
|
|
671
677
|
|
|
672
678
|
response = requests.get(url, headers=headers, params=params)
|
|
673
679
|
response.encoding = "utf-8"
|
|
@@ -696,7 +702,7 @@ class SearchToolkit(BaseToolkit):
|
|
|
696
702
|
"url": link,
|
|
697
703
|
}
|
|
698
704
|
)
|
|
699
|
-
if len(results) >=
|
|
705
|
+
if len(results) >= self.number_of_result_pages:
|
|
700
706
|
break
|
|
701
707
|
|
|
702
708
|
if not results:
|
|
@@ -710,7 +716,7 @@ class SearchToolkit(BaseToolkit):
|
|
|
710
716
|
except Exception as e:
|
|
711
717
|
return {"error": f"Baidu scraping error: {e!s}"}
|
|
712
718
|
|
|
713
|
-
def search_bing(self, query: str
|
|
719
|
+
def search_bing(self, query: str) -> Dict[str, Any]:
|
|
714
720
|
r"""Use Bing search engine to search information for the given query.
|
|
715
721
|
|
|
716
722
|
This function queries the Chinese version of Bing search engine (cn.
|
|
@@ -722,8 +728,6 @@ class SearchToolkit(BaseToolkit):
|
|
|
722
728
|
Args:
|
|
723
729
|
query (str): The search query string to submit to Bing. Works best
|
|
724
730
|
with Chinese queries or when Chinese results are preferred.
|
|
725
|
-
max_results (int): Maximum number of results to return.
|
|
726
|
-
(default: :obj:`5`)
|
|
727
731
|
|
|
728
732
|
Returns:
|
|
729
733
|
Dict ([str, Any]): A dictionary containing either:
|
|
@@ -773,7 +777,9 @@ class SearchToolkit(BaseToolkit):
|
|
|
773
777
|
result_items = b_results_tag.find_all("li")
|
|
774
778
|
|
|
775
779
|
results: List[Dict[str, Any]] = []
|
|
776
|
-
for i in range(
|
|
780
|
+
for i in range(
|
|
781
|
+
min(len(result_items), self.number_of_result_pages)
|
|
782
|
+
):
|
|
777
783
|
row = result_items[i]
|
|
778
784
|
if not isinstance(row, Tag):
|
|
779
785
|
continue
|
|
@@ -838,7 +844,6 @@ class SearchToolkit(BaseToolkit):
|
|
|
838
844
|
"financial report",
|
|
839
845
|
]
|
|
840
846
|
] = None,
|
|
841
|
-
num_results: int = 10,
|
|
842
847
|
include_text: Optional[List[str]] = None,
|
|
843
848
|
exclude_text: Optional[List[str]] = None,
|
|
844
849
|
use_autoprompt: bool = True,
|
|
@@ -854,8 +859,6 @@ class SearchToolkit(BaseToolkit):
|
|
|
854
859
|
and neural search. (default: :obj:`"auto"`)
|
|
855
860
|
category (Optional[Literal]): Category to focus the search on, such
|
|
856
861
|
as "research paper" or "news". (default: :obj:`None`)
|
|
857
|
-
num_results (int): Number of results to return (max 100).
|
|
858
|
-
(default: :obj:`10`)
|
|
859
862
|
include_text (Optional[List[str]]): Strings that must be present in
|
|
860
863
|
webpage text. Limited to 1 string of up to 5 words.
|
|
861
864
|
(default: :obj:`None`)
|
|
@@ -884,7 +887,10 @@ class SearchToolkit(BaseToolkit):
|
|
|
884
887
|
try:
|
|
885
888
|
exa = Exa(EXA_API_KEY)
|
|
886
889
|
|
|
887
|
-
if
|
|
890
|
+
if (
|
|
891
|
+
self.number_of_result_pages is not None
|
|
892
|
+
and not 0 < self.number_of_result_pages <= 100
|
|
893
|
+
):
|
|
888
894
|
raise ValueError("num_results must be between 1 and 100")
|
|
889
895
|
|
|
890
896
|
if include_text is not None:
|
|
@@ -911,7 +917,7 @@ class SearchToolkit(BaseToolkit):
|
|
|
911
917
|
query=query,
|
|
912
918
|
type=search_type,
|
|
913
919
|
category=category,
|
|
914
|
-
num_results=
|
|
920
|
+
num_results=self.number_of_result_pages,
|
|
915
921
|
include_text=include_text,
|
|
916
922
|
exclude_text=exclude_text,
|
|
917
923
|
use_autoprompt=use_autoprompt,
|
|
@@ -925,7 +931,7 @@ class SearchToolkit(BaseToolkit):
|
|
|
925
931
|
query=query,
|
|
926
932
|
type=search_type,
|
|
927
933
|
category=category,
|
|
928
|
-
num_results=
|
|
934
|
+
num_results=self.number_of_result_pages,
|
|
929
935
|
include_text=include_text,
|
|
930
936
|
exclude_text=exclude_text,
|
|
931
937
|
use_autoprompt=use_autoprompt,
|
|
@@ -955,7 +961,6 @@ class SearchToolkit(BaseToolkit):
|
|
|
955
961
|
"news_center",
|
|
956
962
|
]
|
|
957
963
|
] = None,
|
|
958
|
-
page: int = 1,
|
|
959
964
|
return_main_text: bool = False,
|
|
960
965
|
return_markdown_text: bool = True,
|
|
961
966
|
enable_rerank: bool = True,
|
|
@@ -980,8 +985,6 @@ class SearchToolkit(BaseToolkit):
|
|
|
980
985
|
results from sites in the specified industries. Multiple
|
|
981
986
|
industries can be comma-separated.
|
|
982
987
|
(default: :obj:`None`)
|
|
983
|
-
page (int): Page number for results pagination.
|
|
984
|
-
(default: :obj:`1`)
|
|
985
988
|
return_main_text (bool): Whether to include the main text of the
|
|
986
989
|
webpage in results. (default: :obj:`True`)
|
|
987
990
|
return_markdown_text (bool): Whether to include markdown formatted
|
|
@@ -1014,7 +1017,7 @@ class SearchToolkit(BaseToolkit):
|
|
|
1014
1017
|
params: Dict[str, Union[str, int]] = {
|
|
1015
1018
|
"query": query,
|
|
1016
1019
|
"timeRange": time_range,
|
|
1017
|
-
"page":
|
|
1020
|
+
"page": self.number_of_result_pages,
|
|
1018
1021
|
"returnMainText": str(return_main_text).lower(),
|
|
1019
1022
|
"returnMarkdownText": str(return_markdown_text).lower(),
|
|
1020
1023
|
"enableRerank": str(enable_rerank).lower(),
|
camel/utils/tool_result.py
CHANGED
|
@@ -41,4 +41,4 @@ class ToolResult:
|
|
|
41
41
|
def __repr__(self) -> str:
|
|
42
42
|
r"""Return a detailed representation of the result."""
|
|
43
43
|
img_count = len(self.images) if self.images else 0
|
|
44
|
-
return f"ToolResult(text='{self.text
|
|
44
|
+
return f"ToolResult(text='{self.text}', images={img_count})"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
camel/__init__.py,sha256=
|
|
1
|
+
camel/__init__.py,sha256=oUT4aFlY7oLE0uiLwy27soTCR0nroQM7pxRzeU3iGKQ,902
|
|
2
2
|
camel/generators.py,sha256=JRqj9_m1PF4qT6UtybzTQ-KBT9MJQt18OAAYvQ_fr2o,13844
|
|
3
3
|
camel/human.py,sha256=Xg8x1cS5KK4bQ1SDByiHZnzsRpvRP-KZViNvmu38xo4,5475
|
|
4
4
|
camel/logger.py,sha256=WgEwael_eT6D-lVAKHpKIpwXSTjvLbny5jbV1Ab8lnA,5760
|
|
@@ -7,7 +7,7 @@ camel/agents/__init__.py,sha256=64weKqdvmpZcGWyVkO-OKASAmVUdrQjv60JApgPk_SA,1644
|
|
|
7
7
|
camel/agents/_types.py,sha256=MeFZzay2kJA6evALQ-MbBTKW-0lu_0wBuKsxzH_4gWI,1552
|
|
8
8
|
camel/agents/_utils.py,sha256=AR7Qqgbkmn4X2edYUQf1rdksGUyV5hm3iK1z-Dn0Mcg,6266
|
|
9
9
|
camel/agents/base.py,sha256=c4bJYL3G3Z41SaFdMPMn8ZjLdFiFaVOFO6EQIfuCVR8,1124
|
|
10
|
-
camel/agents/chat_agent.py,sha256=
|
|
10
|
+
camel/agents/chat_agent.py,sha256=gF-Wq1YSL5C4_9pp9SN4jdfLrzF-d3xi51PnskQyi7k,159299
|
|
11
11
|
camel/agents/critic_agent.py,sha256=L6cTbYjyZB0DCa51tQ6LZLA6my8kHLC4nktHySH78H4,10433
|
|
12
12
|
camel/agents/deductive_reasoner_agent.py,sha256=6BZGaq1hR6hKJuQtOfoYQnk_AkZpw_Mr7mUy2MspQgs,13540
|
|
13
13
|
camel/agents/embodied_agent.py,sha256=XBxBu5ZMmSJ4B2U3Z7SMwvLlgp6yNpaBe8HNQmY9CZA,7536
|
|
@@ -273,14 +273,14 @@ camel/societies/babyagi_playing.py,sha256=KbTdpHfZ2V8AripVck0bNTOyF-RSaMPCRARz3D
|
|
|
273
273
|
camel/societies/role_playing.py,sha256=0XScr3WfxX1QOC71RhBLmrcS5y2c7DMQB_mAFOHU34M,31421
|
|
274
274
|
camel/societies/workforce/__init__.py,sha256=bkTI-PE-MSK9AQ2V2gR6cR2WY-R7Jqy_NmXRtAoqo8o,920
|
|
275
275
|
camel/societies/workforce/base.py,sha256=z2DmbTP5LL5-aCAAqglznQqCLfPmnyM5zD3w6jjtsb8,2175
|
|
276
|
-
camel/societies/workforce/prompts.py,sha256=
|
|
277
|
-
camel/societies/workforce/role_playing_worker.py,sha256=
|
|
276
|
+
camel/societies/workforce/prompts.py,sha256=CYTkUJOYr3lcQAVAUAeKa_R-oyQHl5aECOkriMcXmjM,16518
|
|
277
|
+
camel/societies/workforce/role_playing_worker.py,sha256=Zm89lZTlV0T3o9C-DJ0HAV68Iq2Kdg8QqJRWs1TV9_A,10320
|
|
278
278
|
camel/societies/workforce/single_agent_worker.py,sha256=fXgAEkDMhvTd-nbwy5Gw3BOaRAiPsL8mf3AW1aaNqKU,19342
|
|
279
279
|
camel/societies/workforce/structured_output_handler.py,sha256=xr8szFN86hg3jQ825aEkJTjkSFQnTlbinVg4j1vZJVI,17870
|
|
280
280
|
camel/societies/workforce/task_channel.py,sha256=GWHaGQBpjTzdKbWoBYAQzzAiLKRKRXa6beqtc4cg-Is,7611
|
|
281
281
|
camel/societies/workforce/utils.py,sha256=THgNHSeZsNVnjTzQTur3qCJhi72MrDS8X2gPET174cI,8434
|
|
282
|
-
camel/societies/workforce/worker.py,sha256=
|
|
283
|
-
camel/societies/workforce/workforce.py,sha256=
|
|
282
|
+
camel/societies/workforce/worker.py,sha256=MtUqYkTC9V-PIIRwSkKiB9w_YSu92iOpoha2rktEiQ0,6248
|
|
283
|
+
camel/societies/workforce/workforce.py,sha256=bu6RAtDRM50C1mu5P6qeAPAsMmKI9bp8082NzYSC11s,139558
|
|
284
284
|
camel/societies/workforce/workforce_logger.py,sha256=0YT__ys48Bgn0IICKIZBmSWhON-eA1KShebjCdn5ppE,24525
|
|
285
285
|
camel/storages/__init__.py,sha256=RwpEyvxpMbJzVDZJJygeBg4AzyYMkTjjkfB53hTuqGo,2141
|
|
286
286
|
camel/storages/graph_storages/__init__.py,sha256=G29BNn651C0WTOpjCl4QnVM-4B9tcNh8DdmsCiONH8Y,948
|
|
@@ -310,7 +310,7 @@ camel/storages/vectordb_storages/qdrant.py,sha256=a_cT0buSCHQ2CPZy852-mdvMDwy5zo
|
|
|
310
310
|
camel/storages/vectordb_storages/tidb.py,sha256=w83bxgKgso43MtHqlpf2EMSpn1_Nz6ZZtY4fPw_-vgs,11192
|
|
311
311
|
camel/storages/vectordb_storages/weaviate.py,sha256=wDUE4KvfmOl3DqHFU4uF0VKbHu-q9vKhZDe8FZ6QXsk,27888
|
|
312
312
|
camel/tasks/__init__.py,sha256=MuHwkw5GRQc8NOCzj8tjtBrr2Xg9KrcKp-ed_-2ZGIM,906
|
|
313
|
-
camel/tasks/task.py,sha256=
|
|
313
|
+
camel/tasks/task.py,sha256=TZ0h9L_yKuJ3lxs8c8YUNVCZLWJChoy03Z8WXy1i6pc,24212
|
|
314
314
|
camel/tasks/task_prompt.py,sha256=3KZmKYKUPcTKe8EAZOZBN3G05JHRVt7oHY9ORzLVu1g,2150
|
|
315
315
|
camel/terminators/__init__.py,sha256=t8uqrkUnXEOYMXQDgaBkMFJ0EXFKI0kmx4cUimli3Ls,991
|
|
316
316
|
camel/terminators/base.py,sha256=xmJzERX7GdSXcxZjAHHODa0rOxRChMSRboDCNHWSscs,1511
|
|
@@ -366,7 +366,7 @@ camel/toolkits/pulse_mcp_search_toolkit.py,sha256=uLUpm19uC_4xLJow0gGVS9f-5T5EW2
|
|
|
366
366
|
camel/toolkits/pyautogui_toolkit.py,sha256=Q810fm8cFvElRory7B74aqS2YV6BOpdRE6jkewoM8xc,16093
|
|
367
367
|
camel/toolkits/reddit_toolkit.py,sha256=x0XAT1zQJVNHUr1R1HwWCgIlkamU-kPmbfb_H1WIv-w,8036
|
|
368
368
|
camel/toolkits/retrieval_toolkit.py,sha256=BKjEyOqW3cGEPTS5yHPYb-Qg795iNNPIs1wjowfuq3U,3825
|
|
369
|
-
camel/toolkits/search_toolkit.py,sha256=
|
|
369
|
+
camel/toolkits/search_toolkit.py,sha256=FyIL85qfeTiDCmDD-9H8tnhiRY1ZmnGlkZiW5uRcSR4,44884
|
|
370
370
|
camel/toolkits/searxng_toolkit.py,sha256=a2GtE4FGSrmaIVvX6Yide-abBYD1wsHqitnDlx9fdVg,7664
|
|
371
371
|
camel/toolkits/semantic_scholar_toolkit.py,sha256=Rh7eA_YPxV5pvPIzhjjvpr3vtlaCniJicrqzkPWW9_I,11634
|
|
372
372
|
camel/toolkits/slack_toolkit.py,sha256=ZT6Ndlce2qjGsyZaNMfQ54nSEi7DOC9Ro7YqtK-u5O4,11651
|
|
@@ -435,7 +435,7 @@ camel/utils/mcp_client.py,sha256=-EIUj6v2hXB75Xvj2FyEedwUMEpUUVXzXWNLLYGrJfE,373
|
|
|
435
435
|
camel/utils/message_summarizer.py,sha256=7AvPDlevle5uU3mXtfvSFS--nDjp9yqfrf546qTe9rE,5939
|
|
436
436
|
camel/utils/response_format.py,sha256=xZcx6xBxeg3A0e7R0JCMJdNm2oQ1-diqVLs0JsiCkZU,5319
|
|
437
437
|
camel/utils/token_counting.py,sha256=apkERzNoVc4sgvJvWVosvepX3KH8pVypVjrL4AA7RB4,17521
|
|
438
|
-
camel/utils/tool_result.py,sha256=
|
|
438
|
+
camel/utils/tool_result.py,sha256=0dKMb22cwuxnjeO4K9wbM4gwwPHV1yfoSJquLTUJVXs,1813
|
|
439
439
|
camel/utils/chunker/__init__.py,sha256=6iN6HL6sblIjDuJTILk-9qKcHBZ97t8b6tZCWPZ0OYI,899
|
|
440
440
|
camel/utils/chunker/base.py,sha256=9CuqymFCRncyAdEST-IcRonB732YAPhusznqH-RES3E,960
|
|
441
441
|
camel/utils/chunker/code_chunker.py,sha256=9h4rd39H9ngbOWAjd_12xt-EzVMh0e_fZnC4my8h_Jg,6823
|
|
@@ -446,7 +446,7 @@ camel/verifiers/math_verifier.py,sha256=tA1D4S0sm8nsWISevxSN0hvSVtIUpqmJhzqfbuMo
|
|
|
446
446
|
camel/verifiers/models.py,sha256=GdxYPr7UxNrR1577yW4kyroRcLGfd-H1GXgv8potDWU,2471
|
|
447
447
|
camel/verifiers/physics_verifier.py,sha256=c1grrRddcrVN7szkxhv2QirwY9viIRSITWeWFF5HmLs,30187
|
|
448
448
|
camel/verifiers/python_verifier.py,sha256=ogTz77wODfEcDN4tMVtiSkRQyoiZbHPY2fKybn59lHw,20558
|
|
449
|
-
camel_ai-0.2.
|
|
450
|
-
camel_ai-0.2.
|
|
451
|
-
camel_ai-0.2.
|
|
452
|
-
camel_ai-0.2.
|
|
449
|
+
camel_ai-0.2.71a12.dist-info/METADATA,sha256=mzylMnRqVIeUBQcBvV7jR6CYS3zVtdkOus7lv-_pU9k,49999
|
|
450
|
+
camel_ai-0.2.71a12.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
451
|
+
camel_ai-0.2.71a12.dist-info/licenses/LICENSE,sha256=id0nB2my5kG0xXeimIu5zZrbHLS6EQvxvkKkzIHaT2k,11343
|
|
452
|
+
camel_ai-0.2.71a12.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|