praisonaiagents 0.0.100__py3-none-any.whl → 0.0.102__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.
@@ -12,6 +12,7 @@ from .knowledge.knowledge import Knowledge
12
12
  from .knowledge.chunking import Chunking
13
13
  from .mcp.mcp import MCP
14
14
  from .session import Session
15
+ from .memory.memory import Memory
15
16
  from .guardrails import GuardrailResult, LLMGuardrail
16
17
  from .main import (
17
18
  TaskOutput,
@@ -43,6 +44,7 @@ __all__ = [
43
44
  'ReflectionOutput',
44
45
  'AutoAgents',
45
46
  'Session',
47
+ 'Memory',
46
48
  'display_interaction',
47
49
  'display_self_reflection',
48
50
  'display_instruction',
@@ -29,6 +29,12 @@ try:
29
29
  except ImportError:
30
30
  OPENAI_AVAILABLE = False
31
31
 
32
+ try:
33
+ import litellm
34
+ LITELLM_AVAILABLE = True
35
+ except ImportError:
36
+ LITELLM_AVAILABLE = False
37
+
32
38
 
33
39
 
34
40
 
@@ -340,14 +346,28 @@ class Memory:
340
346
 
341
347
  elif self.use_rag and hasattr(self, "chroma_col"):
342
348
  try:
343
- from openai import OpenAI
344
- client = OpenAI()
345
-
346
- response = client.embeddings.create(
347
- input=query,
348
- model="text-embedding-3-small"
349
- )
350
- query_embedding = response.data[0].embedding
349
+ if LITELLM_AVAILABLE:
350
+ # Use LiteLLM for consistency with the rest of the codebase
351
+ import litellm
352
+
353
+ response = litellm.embedding(
354
+ model="text-embedding-3-small",
355
+ input=query
356
+ )
357
+ query_embedding = response.data[0]["embedding"]
358
+ elif OPENAI_AVAILABLE:
359
+ # Fallback to OpenAI client
360
+ from openai import OpenAI
361
+ client = OpenAI()
362
+
363
+ response = client.embeddings.create(
364
+ input=query,
365
+ model="text-embedding-3-small"
366
+ )
367
+ query_embedding = response.data[0].embedding
368
+ else:
369
+ self._log_verbose("Neither litellm nor openai available for embeddings", logging.WARNING)
370
+ return []
351
371
 
352
372
  resp = self.chroma_col.query(
353
373
  query_embeddings=[query_embedding],
@@ -464,19 +484,39 @@ class Memory:
464
484
  # Store in vector database if enabled
465
485
  if self.use_rag and hasattr(self, "chroma_col"):
466
486
  try:
467
- from openai import OpenAI
468
- client = OpenAI(api_key=os.getenv("OPENAI_API_KEY")) # Ensure API key is correctly set
469
-
470
- logger.info("Getting embeddings from OpenAI...")
471
- logger.debug(f"Embedding input text: {text}") # Log the input text
472
-
473
- response = client.embeddings.create(
474
- input=text,
475
- model="text-embedding-3-small"
476
- )
477
- embedding = response.data[0].embedding
478
- logger.info("Successfully got embeddings")
479
- logger.debug(f"Received embedding of length: {len(embedding)}") # Log embedding details
487
+ if LITELLM_AVAILABLE:
488
+ # Use LiteLLM for consistency with the rest of the codebase
489
+ import litellm
490
+
491
+ logger.info("Getting embeddings from LiteLLM...")
492
+ logger.debug(f"Embedding input text: {text}")
493
+
494
+ response = litellm.embedding(
495
+ model="text-embedding-3-small",
496
+ input=text
497
+ )
498
+ embedding = response.data[0]["embedding"]
499
+ logger.info("Successfully got embeddings from LiteLLM")
500
+ logger.debug(f"Received embedding of length: {len(embedding)}")
501
+
502
+ elif OPENAI_AVAILABLE:
503
+ # Fallback to OpenAI client
504
+ from openai import OpenAI
505
+ client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
506
+
507
+ logger.info("Getting embeddings from OpenAI...")
508
+ logger.debug(f"Embedding input text: {text}")
509
+
510
+ response = client.embeddings.create(
511
+ input=text,
512
+ model="text-embedding-3-small"
513
+ )
514
+ embedding = response.data[0].embedding
515
+ logger.info("Successfully got embeddings from OpenAI")
516
+ logger.debug(f"Received embedding of length: {len(embedding)}")
517
+ else:
518
+ logger.warning("Neither litellm nor openai available for embeddings")
519
+ return
480
520
 
481
521
  # Sanitize metadata for ChromaDB
482
522
  sanitized_metadata = self._sanitize_metadata(metadata)
@@ -527,15 +567,28 @@ class Memory:
527
567
 
528
568
  elif self.use_rag and hasattr(self, "chroma_col"):
529
569
  try:
530
- from openai import OpenAI
531
- client = OpenAI()
532
-
533
- # Get query embedding
534
- response = client.embeddings.create(
535
- input=query,
536
- model="text-embedding-3-small" # Using consistent model
537
- )
538
- query_embedding = response.data[0].embedding
570
+ if LITELLM_AVAILABLE:
571
+ # Use LiteLLM for consistency with the rest of the codebase
572
+ import litellm
573
+
574
+ response = litellm.embedding(
575
+ model="text-embedding-3-small",
576
+ input=query
577
+ )
578
+ query_embedding = response.data[0]["embedding"]
579
+ elif OPENAI_AVAILABLE:
580
+ # Fallback to OpenAI client
581
+ from openai import OpenAI
582
+ client = OpenAI()
583
+
584
+ response = client.embeddings.create(
585
+ input=query,
586
+ model="text-embedding-3-small"
587
+ )
588
+ query_embedding = response.data[0].embedding
589
+ else:
590
+ self._log_verbose("Neither litellm nor openai available for embeddings", logging.WARNING)
591
+ return []
539
592
 
540
593
  # Search ChromaDB with embedding
541
594
  resp = self.chroma_col.query(
@@ -910,21 +963,44 @@ class Memory:
910
963
  """
911
964
 
912
965
  try:
913
- # Use LiteLLM for consistency with the rest of the codebase
914
- import litellm
915
-
916
- # Convert model name if it's in litellm format
917
- model_name = llm or "gpt-4o-mini"
918
-
919
- response = litellm.completion(
920
- model=model_name,
921
- messages=[{
922
- "role": "user",
923
- "content": custom_prompt or default_prompt
924
- }],
925
- response_format={"type": "json_object"},
926
- temperature=0.3
927
- )
966
+ if LITELLM_AVAILABLE:
967
+ # Use LiteLLM for consistency with the rest of the codebase
968
+ import litellm
969
+
970
+ # Convert model name if it's in litellm format
971
+ model_name = llm or "gpt-4o-mini"
972
+
973
+ response = litellm.completion(
974
+ model=model_name,
975
+ messages=[{
976
+ "role": "user",
977
+ "content": custom_prompt or default_prompt
978
+ }],
979
+ response_format={"type": "json_object"},
980
+ temperature=0.3
981
+ )
982
+ elif OPENAI_AVAILABLE:
983
+ # Fallback to OpenAI client
984
+ from openai import OpenAI
985
+ client = OpenAI()
986
+
987
+ response = client.chat.completions.create(
988
+ model=llm or "gpt-4o-mini",
989
+ messages=[{
990
+ "role": "user",
991
+ "content": custom_prompt or default_prompt
992
+ }],
993
+ response_format={"type": "json_object"},
994
+ temperature=0.3
995
+ )
996
+ else:
997
+ logger.error("Neither litellm nor openai available for quality calculation")
998
+ return {
999
+ "completeness": 0.0,
1000
+ "relevance": 0.0,
1001
+ "clarity": 0.0,
1002
+ "accuracy": 0.0
1003
+ }
928
1004
 
929
1005
  metrics = json.loads(response.choices[0].message.content)
930
1006
 
@@ -0,0 +1,155 @@
1
+ # PraisonAI Tools Guide
2
+
3
+ Welcome to the PraisonAI Tools directory! This guide will help you understand how our tools work and how to create new ones, whether you're a beginner or an experienced programmer.
4
+
5
+ ## What is a Tool?
6
+
7
+ A tool is a piece of code that helps our AI agents perform specific tasks. Think of tools as special abilities that we give to our agents. For example:
8
+ - An internet search tool lets agents search the web
9
+ - A stock market tool lets agents check stock prices
10
+ - A weather tool lets agents check the weather
11
+
12
+ ## Creating New Tools: The Two Approaches
13
+
14
+ ### 1. Function-Based Approach (Simple Tools)
15
+
16
+ Best for simple tools that do one specific thing. Like a calculator that just adds numbers.
17
+
18
+ **When to use:**
19
+ - Tool does one simple task
20
+ - Doesn't need to remember information between uses
21
+ - Doesn't need to share information with other tools
22
+ - Quick, one-time operations
23
+
24
+ **Example:**
25
+ ```python
26
+ def internet_search(query: str):
27
+ # Search the internet and return results
28
+ return search_results
29
+ ```
30
+
31
+ **Usage:**
32
+ ```python
33
+ from praisonaiagents.tools import internet_search
34
+
35
+ results = internet_search("AI news")
36
+ ```
37
+
38
+ ### 2. Class-Based Approach (Complex Tools)
39
+
40
+ Best for tools that do multiple related things or need to remember information. Like a smart calculator that remembers your previous calculations and can do many different math operations.
41
+
42
+ **When to use:**
43
+ - Tool has multiple related functions
44
+ - Needs to remember or share information
45
+ - Needs to manage resources efficiently
46
+ - Has complex setup requirements
47
+
48
+ **Example:**
49
+ ```python
50
+ class StockTools:
51
+ def get_stock_price(self, symbol):
52
+ # Get current stock price
53
+ return price
54
+
55
+ def get_stock_info(self, symbol):
56
+ # Get detailed stock information
57
+ return info
58
+ ```
59
+
60
+ **Usage:**
61
+ ```python
62
+ from praisonaiagents.tools import get_stock_price, get_stock_info
63
+
64
+ price = get_stock_price("AAPL")
65
+ info = get_stock_info("AAPL")
66
+ ```
67
+
68
+ ## How to Choose Your Approach
69
+
70
+ Ask yourself these questions:
71
+
72
+ 1. **Is your tool doing one simple thing?**
73
+ - Yes → Use Function-Based Approach
74
+ - No → Consider Class-Based Approach
75
+
76
+ 2. **Does your tool need to remember information?**
77
+ - Yes → Use Class-Based Approach
78
+ - No → Use Function-Based Approach
79
+
80
+ 3. **Are your tool's operations related to each other?**
81
+ - Yes → Use Class-Based Approach
82
+ - No → Use Function-Based Approach
83
+
84
+ 4. **Does your tool need to manage resources efficiently?**
85
+ - Yes → Use Class-Based Approach
86
+ - No → Use Function-Based Approach
87
+
88
+ ## Real-World Examples
89
+
90
+ ### Internet Search Tool (Function-Based)
91
+ - Does one thing: searches the internet
92
+ - Doesn't need to remember previous searches
93
+ - Each search is independent
94
+ - Simple input/output operation
95
+
96
+ ### SearxNG Search Tool (Function-Based)
97
+ - Privacy-focused web search using local SearxNG instance
98
+ - Simple search operation with customizable parameters
99
+ - Each search is independent and secure
100
+ - Alternative to traditional search engines for privacy
101
+
102
+ ### Stock Market Tool (Class-Based)
103
+ - Does multiple things: check prices, get company info, get historical data
104
+ - Remembers stock information to avoid repeated downloads
105
+ - Operations are related (all about stocks)
106
+ - Manages connections efficiently
107
+
108
+ ## Getting Started
109
+
110
+ 1. **Choose Your Approach** based on the guidelines above
111
+
112
+ 2. **Create Your Tool File**:
113
+ - Name it descriptively (e.g., `weather_tools.py`)
114
+ - Place it in the `praisonaiagents/tools` directory
115
+
116
+ 3. **Write Your Tool**:
117
+ - Add clear documentation
118
+ - Include type hints for better understanding
119
+ - Handle errors gracefully
120
+
121
+ 4. **Test Your Tool**:
122
+ - Make sure it works as expected
123
+ - Test error cases
124
+ - Check performance
125
+
126
+ ## Best Practices
127
+
128
+ 1. **Documentation**:
129
+ - Explain what your tool does
130
+ - Provide examples
131
+ - List any requirements
132
+
133
+ 2. **Error Handling**:
134
+ - Always handle possible errors
135
+ - Return helpful error messages
136
+ - Don't let your tool crash
137
+
138
+ 3. **Performance**:
139
+ - Keep it efficient
140
+ - Don't waste resources
141
+ - Cache when helpful
142
+
143
+ 4. **User-Friendly**:
144
+ - Make it easy to use
145
+ - Use clear function/method names
146
+ - Keep it simple
147
+
148
+ ## Need Help?
149
+
150
+ - Check existing tools for examples
151
+ - Ask in our community
152
+ - Read the documentation
153
+ - Don't hesitate to ask questions!
154
+
155
+ Remember: The goal is to make tools that are easy to use and maintain. Choose the approach that makes the most sense for your specific tool's needs.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: praisonaiagents
3
- Version: 0.0.100
3
+ Version: 0.0.102
4
4
  Summary: Praison AI agents for completing complex tasks with Self Reflection Agents
5
5
  Author: Mervin Praison
6
6
  Requires-Python: >=3.10
@@ -14,6 +14,7 @@ Requires-Dist: fastapi>=0.115.0; extra == "mcp"
14
14
  Requires-Dist: uvicorn>=0.34.0; extra == "mcp"
15
15
  Provides-Extra: memory
16
16
  Requires-Dist: chromadb>=1.0.0; extra == "memory"
17
+ Requires-Dist: litellm>=1.50.0; extra == "memory"
17
18
  Provides-Extra: knowledge
18
19
  Requires-Dist: mem0ai>=0.1.0; extra == "knowledge"
19
20
  Requires-Dist: chromadb>=1.0.0; extra == "knowledge"
@@ -1,4 +1,4 @@
1
- praisonaiagents/__init__.py,sha256=GmTiMNta4iwmfarh_6cTUpry50hpqFE8YqolrYfZ_7U,1465
1
+ praisonaiagents/__init__.py,sha256=0CZDONk4HFIEpij6WwAC2dqwBZ3cdjp0G_CwS98yYk8,1513
2
2
  praisonaiagents/approval.py,sha256=UJ4OhfihpFGR5CAaMphqpSvqdZCHi5w2MGw1MByZ1FQ,9813
3
3
  praisonaiagents/main.py,sha256=_-XE7_Y7ChvtLQMivfNFrrnAhv4wSSDhH9WJMWlkS0w,16315
4
4
  praisonaiagents/session.py,sha256=CI-ffCiOfmgB-1zFFik9daKCB5Sm41Q9ZOaq1-oSLW8,9250
@@ -20,11 +20,12 @@ praisonaiagents/mcp/__init__.py,sha256=ibbqe3_7XB7VrIcUcetkZiUZS1fTVvyMy_AqCSFG8
20
20
  praisonaiagents/mcp/mcp.py,sha256=_gfp8hrSVT9aPqEDDfU8MiCdg0-3dVQpEQUE6AbrJlo,17243
21
21
  praisonaiagents/mcp/mcp_sse.py,sha256=DLh3F_aoVRM1X-7hgIOWOw4FQ1nGmn9YNbQTesykzn4,6792
22
22
  praisonaiagents/memory/__init__.py,sha256=aEFdhgtTqDdMhc_JCWM-f4XI9cZIj7Wz5g_MUa-0amg,397
23
- praisonaiagents/memory/memory.py,sha256=x6CEMYhgzvlJH6SGKHPLRDt6kF0DVFFSUQbgr1OK3JM,38729
23
+ praisonaiagents/memory/memory.py,sha256=W0WwHAXag_vmGXjLBGntXmGqEkZ_AFNrUK2WwR0NEXs,42045
24
24
  praisonaiagents/process/__init__.py,sha256=lkYbL7Hn5a0ldvJtkdH23vfIIZLIcanK-65C0MwaorY,52
25
25
  praisonaiagents/process/process.py,sha256=gxhMXG3s4CzaREyuwE5zxCMx2Wp_b_Wd53tDfkj8Qk8,66567
26
26
  praisonaiagents/task/__init__.py,sha256=VL5hXVmyGjINb34AalxpBMl-YW9m5EDcRkMTKkSSl7c,80
27
27
  praisonaiagents/task/task.py,sha256=imqJ8wzZzVyUSym2EyF2tC-vAsV1UdfI_P3YM5mqAiw,20786
28
+ praisonaiagents/tools/README.md,sha256=bIQGTSqQbC8l_UvTAnKbnh1TxrybSFGbCqxnhvDwkE4,4450
28
29
  praisonaiagents/tools/__init__.py,sha256=Rrgi7_3-yLHpfBB81WUi0-wD_wb_BsukwHVdjDYAF-0,9316
29
30
  praisonaiagents/tools/arxiv_tools.py,sha256=1stb31zTjLTon4jCnpZG5de9rKc9QWgC0leLegvPXWo,10528
30
31
  praisonaiagents/tools/calculator_tools.py,sha256=S1xPT74Geurvjm52QMMIG29zDXVEWJmM6nmyY7yF298,9571
@@ -47,7 +48,7 @@ praisonaiagents/tools/xml_tools.py,sha256=iYTMBEk5l3L3ryQ1fkUnNVYK-Nnua2Kx2S0dxN
47
48
  praisonaiagents/tools/yaml_tools.py,sha256=uogAZrhXV9O7xvspAtcTfpKSQYL2nlOTvCQXN94-G9A,14215
48
49
  praisonaiagents/tools/yfinance_tools.py,sha256=s2PBj_1v7oQnOobo2fDbQBACEHl61ftG4beG6Z979ZE,8529
49
50
  praisonaiagents/tools/train/data/generatecot.py,sha256=H6bNh-E2hqL5MW6kX3hqZ05g9ETKN2-kudSjiuU_SD8,19403
50
- praisonaiagents-0.0.100.dist-info/METADATA,sha256=sP3J1zX6-LWPWRdLHRmy-Ca-ADgUxL3GR1-qsaiFO4Y,1453
51
- praisonaiagents-0.0.100.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
52
- praisonaiagents-0.0.100.dist-info/top_level.txt,sha256=_HsRddrJ23iDx5TTqVUVvXG2HeHBL5voshncAMDGjtA,16
53
- praisonaiagents-0.0.100.dist-info/RECORD,,
51
+ praisonaiagents-0.0.102.dist-info/METADATA,sha256=XHOa7_oIgLEwegZxOJCVEvDg8Yi6BEpJbX9jxtKhZR8,1503
52
+ praisonaiagents-0.0.102.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
53
+ praisonaiagents-0.0.102.dist-info/top_level.txt,sha256=_HsRddrJ23iDx5TTqVUVvXG2HeHBL5voshncAMDGjtA,16
54
+ praisonaiagents-0.0.102.dist-info/RECORD,,