praisonaiagents 0.0.39__py3-none-any.whl → 0.0.41__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.
- praisonaiagents/agent/agent.py +23 -10
- praisonaiagents/agents/agents.py +66 -19
- praisonaiagents/task/task.py +31 -2
- {praisonaiagents-0.0.39.dist-info → praisonaiagents-0.0.41.dist-info}/METADATA +1 -1
- {praisonaiagents-0.0.39.dist-info → praisonaiagents-0.0.41.dist-info}/RECORD +7 -7
- {praisonaiagents-0.0.39.dist-info → praisonaiagents-0.0.41.dist-info}/WHEEL +0 -0
- {praisonaiagents-0.0.39.dist-info → praisonaiagents-0.0.41.dist-info}/top_level.txt +0 -0
praisonaiagents/agent/agent.py
CHANGED
@@ -71,10 +71,15 @@ class Agent:
|
|
71
71
|
|
72
72
|
import inspect
|
73
73
|
# Langchain tools
|
74
|
-
if inspect.isclass(func) and hasattr(func, 'run'):
|
74
|
+
if inspect.isclass(func) and hasattr(func, 'run') and not hasattr(func, '_run'):
|
75
75
|
original_func = func
|
76
76
|
func = func.run
|
77
77
|
function_name = original_func.__name__
|
78
|
+
# CrewAI tools
|
79
|
+
elif inspect.isclass(func) and hasattr(func, '_run'):
|
80
|
+
original_func = func
|
81
|
+
func = func._run
|
82
|
+
function_name = original_func.__name__
|
78
83
|
|
79
84
|
sig = inspect.signature(func)
|
80
85
|
logging.debug(f"Function signature: {sig}")
|
@@ -313,14 +318,22 @@ Your Goal: {self.goal}
|
|
313
318
|
|
314
319
|
if func:
|
315
320
|
try:
|
316
|
-
# If it's a class with run
|
317
|
-
if inspect.isclass(func) and hasattr(func, 'run'):
|
321
|
+
# Langchain: If it's a class with run but not _run, instantiate and call run
|
322
|
+
if inspect.isclass(func) and hasattr(func, 'run') and not hasattr(func, '_run'):
|
318
323
|
instance = func()
|
319
|
-
# Extract only the parameters that run() expects
|
320
324
|
run_params = {k: v for k, v in arguments.items()
|
321
|
-
|
322
|
-
|
325
|
+
if k in inspect.signature(instance.run).parameters
|
326
|
+
and k != 'self'}
|
323
327
|
return instance.run(**run_params)
|
328
|
+
|
329
|
+
# CrewAI: If it's a class with an _run method, instantiate and call _run
|
330
|
+
elif inspect.isclass(func) and hasattr(func, '_run'):
|
331
|
+
instance = func()
|
332
|
+
run_params = {k: v for k, v in arguments.items()
|
333
|
+
if k in inspect.signature(instance._run).parameters
|
334
|
+
and k != 'self'}
|
335
|
+
return instance._run(**run_params)
|
336
|
+
|
324
337
|
# Otherwise treat as regular function
|
325
338
|
elif callable(func):
|
326
339
|
return func(**arguments)
|
@@ -472,9 +485,9 @@ Your Role: {self.role}\n
|
|
472
485
|
Your Goal: {self.goal}
|
473
486
|
"""
|
474
487
|
if output_json:
|
475
|
-
system_prompt += f"\nReturn ONLY a JSON object that matches this Pydantic model: {output_json.
|
488
|
+
system_prompt += f"\nReturn ONLY a JSON object that matches this Pydantic model: {json.dumps(output_json.model_json_schema())}"
|
476
489
|
elif output_pydantic:
|
477
|
-
system_prompt += f"\nReturn ONLY a JSON object that matches this Pydantic model: {output_pydantic.
|
490
|
+
system_prompt += f"\nReturn ONLY a JSON object that matches this Pydantic model: {json.dumps(output_pydantic.model_json_schema())}"
|
478
491
|
else:
|
479
492
|
system_prompt = None
|
480
493
|
|
@@ -664,9 +677,9 @@ Output MUST be JSON with 'reflection' and 'satisfactory'.
|
|
664
677
|
# Build system prompt
|
665
678
|
system_prompt = self.system_prompt
|
666
679
|
if output_json:
|
667
|
-
system_prompt += f"\nReturn ONLY a JSON object that matches this Pydantic model: {output_json.
|
680
|
+
system_prompt += f"\nReturn ONLY a JSON object that matches this Pydantic model: {json.dumps(output_json.model_json_schema())}"
|
668
681
|
elif output_pydantic:
|
669
|
-
system_prompt += f"\nReturn ONLY a JSON object that matches this Pydantic model: {output_pydantic.
|
682
|
+
system_prompt += f"\nReturn ONLY a JSON object that matches this Pydantic model: {json.dumps(output_pydantic.model_json_schema())}"
|
670
683
|
|
671
684
|
# Build messages
|
672
685
|
if isinstance(prompt, str):
|
praisonaiagents/agents/agents.py
CHANGED
@@ -229,15 +229,28 @@ You need to do the following task: {task.description}.
|
|
229
229
|
Expected Output: {task.expected_output}.
|
230
230
|
"""
|
231
231
|
if task.context:
|
232
|
-
context_results =
|
233
|
-
for
|
234
|
-
if
|
235
|
-
context_results
|
236
|
-
|
237
|
-
context_results
|
232
|
+
context_results = [] # Use list to avoid duplicates
|
233
|
+
for context_item in task.context:
|
234
|
+
if isinstance(context_item, str):
|
235
|
+
context_results.append(f"Input Content:\n{context_item}")
|
236
|
+
elif isinstance(context_item, list):
|
237
|
+
context_results.append(f"Input Content: {' '.join(str(x) for x in context_item)}")
|
238
|
+
elif hasattr(context_item, 'result'): # Task object
|
239
|
+
if context_item.result:
|
240
|
+
context_results.append(
|
241
|
+
f"Result of previous task {context_item.name if context_item.name else context_item.description}:\n{context_item.result.raw}"
|
242
|
+
)
|
243
|
+
else:
|
244
|
+
context_results.append(
|
245
|
+
f"Previous task {context_item.name if context_item.name else context_item.description} has no result yet."
|
246
|
+
)
|
247
|
+
|
248
|
+
# Join unique context results
|
249
|
+
unique_contexts = list(dict.fromkeys(context_results)) # Remove duplicates
|
238
250
|
task_prompt += f"""
|
239
|
-
|
240
|
-
|
251
|
+
Context:
|
252
|
+
|
253
|
+
{' '.join(unique_contexts)}
|
241
254
|
"""
|
242
255
|
task_prompt += "Please provide only the final result of your work. Do not add any conversation or extra explanation."
|
243
256
|
|
@@ -427,8 +440,16 @@ Here are the results of previous tasks that might be useful:\n
|
|
427
440
|
else:
|
428
441
|
self.run_task(task_id)
|
429
442
|
|
430
|
-
async def astart(self):
|
443
|
+
async def astart(self, content=None, **kwargs):
|
431
444
|
"""Async version of start method"""
|
445
|
+
if content:
|
446
|
+
# Add content to context of all tasks
|
447
|
+
for task in self.tasks.values():
|
448
|
+
if isinstance(content, (str, list)):
|
449
|
+
if not task.context:
|
450
|
+
task.context = []
|
451
|
+
task.context.append(content)
|
452
|
+
|
432
453
|
await self.arun_all_tasks()
|
433
454
|
return {
|
434
455
|
"task_status": self.get_all_tasks_status(),
|
@@ -485,16 +506,30 @@ You need to do the following task: {task.description}.
|
|
485
506
|
Expected Output: {task.expected_output}.
|
486
507
|
"""
|
487
508
|
if task.context:
|
488
|
-
context_results =
|
489
|
-
for
|
490
|
-
if
|
491
|
-
context_results
|
492
|
-
|
493
|
-
context_results
|
509
|
+
context_results = [] # Use list to avoid duplicates
|
510
|
+
for context_item in task.context:
|
511
|
+
if isinstance(context_item, str):
|
512
|
+
context_results.append(f"Input Content:\n{context_item}")
|
513
|
+
elif isinstance(context_item, list):
|
514
|
+
context_results.append(f"Input Content: {' '.join(str(x) for x in context_item)}")
|
515
|
+
elif hasattr(context_item, 'result'): # Task object
|
516
|
+
if context_item.result:
|
517
|
+
context_results.append(
|
518
|
+
f"Result of previous task {context_item.name if context_item.name else context_item.description}:\n{context_item.result.raw}"
|
519
|
+
)
|
520
|
+
else:
|
521
|
+
context_results.append(
|
522
|
+
f"Previous task {context_item.name if context_item.name else context_item.description} has no result yet."
|
523
|
+
)
|
524
|
+
|
525
|
+
# Join unique context results
|
526
|
+
unique_contexts = list(dict.fromkeys(context_results)) # Remove duplicates
|
494
527
|
task_prompt += f"""
|
495
|
-
|
496
|
-
|
528
|
+
Context:
|
529
|
+
|
530
|
+
{' '.join(unique_contexts)}
|
497
531
|
"""
|
532
|
+
|
498
533
|
# Add memory context if available
|
499
534
|
if task.memory:
|
500
535
|
try:
|
@@ -714,12 +749,24 @@ Here are the results of previous tasks that might be useful:\n
|
|
714
749
|
return str(agent[0])
|
715
750
|
return None
|
716
751
|
|
717
|
-
def start(self):
|
752
|
+
def start(self, content=None, **kwargs):
|
753
|
+
"""Start agent execution with optional content and config"""
|
754
|
+
if content:
|
755
|
+
# Add content to context of all tasks
|
756
|
+
for task in self.tasks.values():
|
757
|
+
if isinstance(content, (str, list)):
|
758
|
+
# If context is empty, initialize it
|
759
|
+
if not task.context:
|
760
|
+
task.context = []
|
761
|
+
# Add content to context
|
762
|
+
task.context.append(content)
|
763
|
+
|
764
|
+
# Run tasks as before
|
718
765
|
self.run_all_tasks()
|
719
766
|
return {
|
720
767
|
"task_status": self.get_all_tasks_status(),
|
721
768
|
"task_results": {task_id: self.get_task_result(task_id) for task_id in self.tasks}
|
722
|
-
}
|
769
|
+
}
|
723
770
|
|
724
771
|
def set_state(self, key: str, value: Any) -> None:
|
725
772
|
"""Set a state value"""
|
praisonaiagents/task/task.py
CHANGED
@@ -19,7 +19,7 @@ class Task:
|
|
19
19
|
agent: Optional[Agent] = None,
|
20
20
|
name: Optional[str] = None,
|
21
21
|
tools: Optional[List[Any]] = None,
|
22
|
-
context: Optional[List[
|
22
|
+
context: Optional[List[Union[str, List, 'Task']]] = None,
|
23
23
|
async_execution: Optional[bool] = False,
|
24
24
|
config: Optional[Dict[str, Any]] = None,
|
25
25
|
output_file: Optional[str] = None,
|
@@ -219,4 +219,33 @@ class Task:
|
|
219
219
|
self.callback(task_output)
|
220
220
|
except Exception as e:
|
221
221
|
logger.error(f"Task {self.id}: Failed to execute callback: {e}")
|
222
|
-
logger.exception(e)
|
222
|
+
logger.exception(e)
|
223
|
+
|
224
|
+
task_prompt = f"""
|
225
|
+
You need to do the following task: {self.description}.
|
226
|
+
Expected Output: {self.expected_output}.
|
227
|
+
"""
|
228
|
+
if self.context:
|
229
|
+
context_results = [] # Use list to avoid duplicates
|
230
|
+
for context_item in self.context:
|
231
|
+
if isinstance(context_item, str):
|
232
|
+
context_results.append(f"Input Content:\n{context_item}")
|
233
|
+
elif isinstance(context_item, list):
|
234
|
+
context_results.append(f"Input Content: {' '.join(str(x) for x in context_item)}")
|
235
|
+
elif hasattr(context_item, 'result'): # Task object
|
236
|
+
if context_item.result:
|
237
|
+
context_results.append(
|
238
|
+
f"Result of previous task {context_item.name if context_item.name else context_item.description}:\n{context_item.result.raw}"
|
239
|
+
)
|
240
|
+
else:
|
241
|
+
context_results.append(
|
242
|
+
f"Previous task {context_item.name if context_item.name else context_item.description} has no result yet."
|
243
|
+
)
|
244
|
+
|
245
|
+
# Join unique context results
|
246
|
+
unique_contexts = list(dict.fromkeys(context_results)) # Remove duplicates
|
247
|
+
task_prompt += f"""
|
248
|
+
Context:
|
249
|
+
|
250
|
+
{' '.join(unique_contexts)}
|
251
|
+
"""
|
@@ -1,9 +1,9 @@
|
|
1
1
|
praisonaiagents/__init__.py,sha256=MCgAj12hVJ0YZmVmdmZgYAAMfPdWSoNSiDlRJCvrJqA,1276
|
2
2
|
praisonaiagents/main.py,sha256=uMBdwxjnJKHLPUzr_5vXlkuhCUO6EW5O8XC0M-h47sE,13915
|
3
3
|
praisonaiagents/agent/__init__.py,sha256=sKO8wGEXvtCrvV1e834r1Okv0XAqAxqZCqz6hKLiTvA,79
|
4
|
-
praisonaiagents/agent/agent.py,sha256=
|
4
|
+
praisonaiagents/agent/agent.py,sha256=hP_I11Z3i7QvgnyQcFFEZnJTB5w_RIfimigFNq5C7Hs,37668
|
5
5
|
praisonaiagents/agents/__init__.py,sha256=_1d6Pqyk9EoBSo7E68sKyd1jDRlN1vxvVIRpoMc0Jcw,168
|
6
|
-
praisonaiagents/agents/agents.py,sha256=
|
6
|
+
praisonaiagents/agents/agents.py,sha256=oGCnbyLE22PU1AqXFhJZpzBnoW926mXXfWi-Q2hhklg,33359
|
7
7
|
praisonaiagents/agents/autoagents.py,sha256=bjC2O5oZmoJItJXIMPTWc2lsp_AJC9tMiTQOal2hwPA,13532
|
8
8
|
praisonaiagents/knowledge/__init__.py,sha256=xL1Eh-a3xsHyIcU4foOWF-JdWYIYBALJH9bge0Ujuto,246
|
9
9
|
praisonaiagents/knowledge/chunking.py,sha256=FzoNY0q8MkvG4gADqk4JcRhmH3lcEHbRdonDgitQa30,6624
|
@@ -12,7 +12,7 @@ praisonaiagents/memory/memory.py,sha256=ZxqSpOUxk9jeTKGW0ZiTifC0uZtym-EZILP3kuOO
|
|
12
12
|
praisonaiagents/process/__init__.py,sha256=lkYbL7Hn5a0ldvJtkdH23vfIIZLIcanK-65C0MwaorY,52
|
13
13
|
praisonaiagents/process/process.py,sha256=uSudOFI1ZlGM_nbT8qHD4iIP3y5Ygu8V-izLot2te70,26316
|
14
14
|
praisonaiagents/task/__init__.py,sha256=VL5hXVmyGjINb34AalxpBMl-YW9m5EDcRkMTKkSSl7c,80
|
15
|
-
praisonaiagents/task/task.py,sha256=
|
15
|
+
praisonaiagents/task/task.py,sha256=Tf3CzFNctfTBiy67wfOfT7RnopPGsBntsrHF8012BnE,11383
|
16
16
|
praisonaiagents/tools/__init__.py,sha256=-0lV5n5cG54vYW6REjXIfuJnCLKnfQIDlXsySCaPB9s,7347
|
17
17
|
praisonaiagents/tools/arxiv_tools.py,sha256=1stb31zTjLTon4jCnpZG5de9rKc9QWgC0leLegvPXWo,10528
|
18
18
|
praisonaiagents/tools/calculator_tools.py,sha256=S1xPT74Geurvjm52QMMIG29zDXVEWJmM6nmyY7yF298,9571
|
@@ -33,7 +33,7 @@ praisonaiagents/tools/wikipedia_tools.py,sha256=pGko-f33wqXgxJTv8db7TbizY5XnzBQR
|
|
33
33
|
praisonaiagents/tools/xml_tools.py,sha256=iYTMBEk5l3L3ryQ1fkUnNVYK-Nnua2Kx2S0dxNMMs1A,17122
|
34
34
|
praisonaiagents/tools/yaml_tools.py,sha256=uogAZrhXV9O7xvspAtcTfpKSQYL2nlOTvCQXN94-G9A,14215
|
35
35
|
praisonaiagents/tools/yfinance_tools.py,sha256=s2PBj_1v7oQnOobo2fDbQBACEHl61ftG4beG6Z979ZE,8529
|
36
|
-
praisonaiagents-0.0.
|
37
|
-
praisonaiagents-0.0.
|
38
|
-
praisonaiagents-0.0.
|
39
|
-
praisonaiagents-0.0.
|
36
|
+
praisonaiagents-0.0.41.dist-info/METADATA,sha256=MvJGnvkhUSu27RFe7WqT7aPPA-vqIYmoANXsggh8GZE,664
|
37
|
+
praisonaiagents-0.0.41.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
38
|
+
praisonaiagents-0.0.41.dist-info/top_level.txt,sha256=_HsRddrJ23iDx5TTqVUVvXG2HeHBL5voshncAMDGjtA,16
|
39
|
+
praisonaiagents-0.0.41.dist-info/RECORD,,
|
File without changes
|
File without changes
|