praisonaiagents 0.0.19__tar.gz → 0.0.20__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/PKG-INFO +1 -1
  2. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents/__init__.py +4 -2
  3. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents/main.py +79 -83
  4. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents.egg-info/PKG-INFO +1 -1
  5. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/pyproject.toml +1 -1
  6. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents/agent/__init__.py +0 -0
  7. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents/agent/agent.py +0 -0
  8. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents/agents/__init__.py +0 -0
  9. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents/agents/agents.py +0 -0
  10. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents/build/lib/praisonaiagents/__init__.py +0 -0
  11. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents/build/lib/praisonaiagents/agent/__init__.py +0 -0
  12. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents/build/lib/praisonaiagents/agent/agent.py +0 -0
  13. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents/build/lib/praisonaiagents/agents/__init__.py +0 -0
  14. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents/build/lib/praisonaiagents/agents/agents.py +0 -0
  15. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents/build/lib/praisonaiagents/main.py +0 -0
  16. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents/build/lib/praisonaiagents/task/__init__.py +0 -0
  17. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents/build/lib/praisonaiagents/task/task.py +0 -0
  18. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents/process/__init__.py +0 -0
  19. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents/process/process.py +0 -0
  20. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents/task/__init__.py +0 -0
  21. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents/task/task.py +0 -0
  22. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents.egg-info/SOURCES.txt +0 -0
  23. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents.egg-info/dependency_links.txt +0 -0
  24. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents.egg-info/requires.txt +0 -0
  25. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/praisonaiagents.egg-info/top_level.txt +0 -0
  26. {praisonaiagents-0.0.19 → praisonaiagents-0.0.20}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: praisonaiagents
3
- Version: 0.0.19
3
+ Version: 0.0.20
4
4
  Summary: Praison AI agents for completing complex tasks with Self Reflection Agents
5
5
  Author: Mervin Praison
6
6
  Requires-Dist: pydantic
@@ -17,7 +17,8 @@ from .main import (
17
17
  clean_triple_backticks,
18
18
  error_logs,
19
19
  register_display_callback,
20
- display_callbacks,
20
+ sync_display_callbacks,
21
+ async_display_callbacks,
21
22
  )
22
23
 
23
24
  __all__ = [
@@ -35,5 +36,6 @@ __all__ = [
35
36
  'clean_triple_backticks',
36
37
  'error_logs',
37
38
  'register_display_callback',
38
- 'display_callbacks',
39
+ 'sync_display_callbacks',
40
+ 'async_display_callbacks',
39
41
  ]
@@ -26,12 +26,49 @@ logging.basicConfig(
26
26
  # Global list to store error logs
27
27
  error_logs = []
28
28
 
29
- # Global callback registry
30
- display_callbacks = {}
29
+ # Separate registries for sync and async callbacks
30
+ sync_display_callbacks = {}
31
+ async_display_callbacks = {}
32
+
33
+ # At the top of the file, add display_callbacks to __all__
34
+ __all__ = [
35
+ 'error_logs',
36
+ 'register_display_callback',
37
+ 'sync_display_callbacks',
38
+ 'async_display_callbacks',
39
+ # ... other exports
40
+ ]
41
+
42
+ def register_display_callback(display_type: str, callback_fn, is_async: bool = False):
43
+ """Register a synchronous or asynchronous callback function for a specific display type.
44
+
45
+ Args:
46
+ display_type (str): Type of display event ('interaction', 'self_reflection', etc.)
47
+ callback_fn: The callback function to register
48
+ is_async (bool): Whether the callback is asynchronous
49
+ """
50
+ if is_async:
51
+ async_display_callbacks[display_type] = callback_fn
52
+ else:
53
+ sync_display_callbacks[display_type] = callback_fn
31
54
 
32
- def register_display_callback(display_type: str, callback_fn):
33
- """Register a callback function for a specific display type."""
34
- display_callbacks[display_type] = callback_fn
55
+ async def execute_callback(display_type: str, **kwargs):
56
+ """Execute both sync and async callbacks for a given display type.
57
+
58
+ Args:
59
+ display_type (str): Type of display event
60
+ **kwargs: Arguments to pass to the callback functions
61
+ """
62
+ # Execute synchronous callback if registered
63
+ if display_type in sync_display_callbacks:
64
+ callback = sync_display_callbacks[display_type]
65
+ loop = asyncio.get_event_loop()
66
+ await loop.run_in_executor(None, lambda: callback(**kwargs))
67
+
68
+ # Execute asynchronous callback if registered
69
+ if display_type in async_display_callbacks:
70
+ callback = async_display_callbacks[display_type]
71
+ await callback(**kwargs)
35
72
 
36
73
  def _clean_display_content(content: str, max_length: int = 20000) -> str:
37
74
  """Helper function to clean and truncate content for display."""
@@ -54,11 +91,10 @@ def _clean_display_content(content: str, max_length: int = 20000) -> str:
54
91
  return content.strip()
55
92
 
56
93
  def display_interaction(message, response, markdown=True, generation_time=None, console=None):
57
- """Display the interaction between user and assistant."""
94
+ """Synchronous version of display_interaction."""
58
95
  if console is None:
59
96
  console = Console()
60
97
 
61
- # Handle multimodal content (list)
62
98
  if isinstance(message, list):
63
99
  text_content = next((item["text"] for item in message if item["type"] == "text"), "")
64
100
  message = text_content
@@ -66,16 +102,16 @@ def display_interaction(message, response, markdown=True, generation_time=None,
66
102
  message = _clean_display_content(str(message))
67
103
  response = _clean_display_content(str(response))
68
104
 
69
- # Execute callback if registered
70
- if 'interaction' in display_callbacks:
71
- display_callbacks['interaction'](
105
+ # Execute synchronous callback if registered
106
+ if 'interaction' in sync_display_callbacks:
107
+ sync_display_callbacks['interaction'](
72
108
  message=message,
73
109
  response=response,
74
110
  markdown=markdown,
75
111
  generation_time=generation_time
76
112
  )
77
113
 
78
- # Existing display logic...
114
+ # Rest of the display logic...
79
115
  if generation_time:
80
116
  console.print(Text(f"Response generated in {generation_time:.1f}s", style="dim"))
81
117
 
@@ -94,8 +130,8 @@ def display_self_reflection(message: str, console=None):
94
130
  message = _clean_display_content(str(message))
95
131
 
96
132
  # Execute callback if registered
97
- if 'self_reflection' in display_callbacks:
98
- display_callbacks['self_reflection'](message=message)
133
+ if 'self_reflection' in sync_display_callbacks:
134
+ sync_display_callbacks['self_reflection'](message=message)
99
135
 
100
136
  console.print(Panel.fit(Text(message, style="bold yellow"), title="Self Reflection", border_style="magenta"))
101
137
 
@@ -107,8 +143,8 @@ def display_instruction(message: str, console=None):
107
143
  message = _clean_display_content(str(message))
108
144
 
109
145
  # Execute callback if registered
110
- if 'instruction' in display_callbacks:
111
- display_callbacks['instruction'](message=message)
146
+ if 'instruction' in sync_display_callbacks:
147
+ sync_display_callbacks['instruction'](message=message)
112
148
 
113
149
  console.print(Panel.fit(Text(message, style="bold blue"), title="Instruction", border_style="cyan"))
114
150
 
@@ -120,8 +156,8 @@ def display_tool_call(message: str, console=None):
120
156
  message = _clean_display_content(str(message))
121
157
 
122
158
  # Execute callback if registered
123
- if 'tool_call' in display_callbacks:
124
- display_callbacks['tool_call'](message=message)
159
+ if 'tool_call' in sync_display_callbacks:
160
+ sync_display_callbacks['tool_call'](message=message)
125
161
 
126
162
  console.print(Panel.fit(Text(message, style="bold cyan"), title="Tool Call", border_style="green"))
127
163
 
@@ -133,8 +169,8 @@ def display_error(message: str, console=None):
133
169
  message = _clean_display_content(str(message))
134
170
 
135
171
  # Execute callback if registered
136
- if 'error' in display_callbacks:
137
- display_callbacks['error'](message=message)
172
+ if 'error' in sync_display_callbacks:
173
+ sync_display_callbacks['error'](message=message)
138
174
 
139
175
  console.print(Panel.fit(Text(message, style="bold red"), title="Error", border_style="red"))
140
176
  error_logs.append(message)
@@ -151,8 +187,8 @@ def display_generating(content: str = "", start_time: Optional[float] = None):
151
187
  content = _clean_display_content(str(content))
152
188
 
153
189
  # Execute callback if registered
154
- if 'generating' in display_callbacks:
155
- display_callbacks['generating'](
190
+ if 'generating' in sync_display_callbacks:
191
+ sync_display_callbacks['generating'](
156
192
  content=content,
157
193
  elapsed_time=elapsed_str.strip() if elapsed_str else None
158
194
  )
@@ -172,26 +208,16 @@ async def adisplay_interaction(message, response, markdown=True, generation_time
172
208
  message = _clean_display_content(str(message))
173
209
  response = _clean_display_content(str(response))
174
210
 
175
- if 'interaction' in display_callbacks:
176
- callback = display_callbacks['interaction']
177
- if asyncio.iscoroutinefunction(callback):
178
- await callback(
179
- message=message,
180
- response=response,
181
- markdown=markdown,
182
- generation_time=generation_time
183
- )
184
- else:
185
- loop = asyncio.get_event_loop()
186
- await loop.run_in_executor(
187
- None,
188
- callback,
189
- message,
190
- response,
191
- markdown,
192
- generation_time
193
- )
211
+ # Execute callbacks
212
+ await execute_callback(
213
+ 'interaction',
214
+ message=message,
215
+ response=response,
216
+ markdown=markdown,
217
+ generation_time=generation_time
218
+ )
194
219
 
220
+ # Rest of the display logic...
195
221
  if generation_time:
196
222
  console.print(Text(f"Response generated in {generation_time:.1f}s", style="dim"))
197
223
 
@@ -210,13 +236,8 @@ async def adisplay_self_reflection(message: str, console=None):
210
236
  console = Console()
211
237
  message = _clean_display_content(str(message))
212
238
 
213
- if 'self_reflection' in display_callbacks:
214
- callback = display_callbacks['self_reflection']
215
- if asyncio.iscoroutinefunction(callback):
216
- await callback(message=message)
217
- else:
218
- loop = asyncio.get_event_loop()
219
- await loop.run_in_executor(None, callback, message)
239
+ if 'self_reflection' in async_display_callbacks:
240
+ await async_display_callbacks['self_reflection'](message=message)
220
241
 
221
242
  console.print(Panel.fit(Text(message, style="bold yellow"), title="Self Reflection", border_style="magenta"))
222
243
 
@@ -228,13 +249,8 @@ async def adisplay_instruction(message: str, console=None):
228
249
  console = Console()
229
250
  message = _clean_display_content(str(message))
230
251
 
231
- if 'instruction' in display_callbacks:
232
- callback = display_callbacks['instruction']
233
- if asyncio.iscoroutinefunction(callback):
234
- await callback(message=message)
235
- else:
236
- loop = asyncio.get_event_loop()
237
- await loop.run_in_executor(None, callback, message)
252
+ if 'instruction' in async_display_callbacks:
253
+ await async_display_callbacks['instruction'](message=message)
238
254
 
239
255
  console.print(Panel.fit(Text(message, style="bold blue"), title="Instruction", border_style="cyan"))
240
256
 
@@ -246,13 +262,8 @@ async def adisplay_tool_call(message: str, console=None):
246
262
  console = Console()
247
263
  message = _clean_display_content(str(message))
248
264
 
249
- if 'tool_call' in display_callbacks:
250
- callback = display_callbacks['tool_call']
251
- if asyncio.iscoroutinefunction(callback):
252
- await callback(message=message)
253
- else:
254
- loop = asyncio.get_event_loop()
255
- await loop.run_in_executor(None, callback, message)
265
+ if 'tool_call' in async_display_callbacks:
266
+ await async_display_callbacks['tool_call'](message=message)
256
267
 
257
268
  console.print(Panel.fit(Text(message, style="bold cyan"), title="Tool Call", border_style="green"))
258
269
 
@@ -264,13 +275,8 @@ async def adisplay_error(message: str, console=None):
264
275
  console = Console()
265
276
  message = _clean_display_content(str(message))
266
277
 
267
- if 'error' in display_callbacks:
268
- callback = display_callbacks['error']
269
- if asyncio.iscoroutinefunction(callback):
270
- await callback(message=message)
271
- else:
272
- loop = asyncio.get_event_loop()
273
- await loop.run_in_executor(None, callback, message)
278
+ if 'error' in async_display_callbacks:
279
+ await async_display_callbacks['error'](message=message)
274
280
 
275
281
  console.print(Panel.fit(Text(message, style="bold red"), title="Error", border_style="red"))
276
282
  error_logs.append(message)
@@ -287,21 +293,11 @@ async def adisplay_generating(content: str = "", start_time: Optional[float] = N
287
293
 
288
294
  content = _clean_display_content(str(content))
289
295
 
290
- if 'generating' in display_callbacks:
291
- callback = display_callbacks['generating']
292
- if asyncio.iscoroutinefunction(callback):
293
- await callback(
294
- content=content,
295
- elapsed_time=elapsed_str.strip() if elapsed_str else None
296
- )
297
- else:
298
- loop = asyncio.get_event_loop()
299
- await loop.run_in_executor(
300
- None,
301
- callback,
302
- content,
303
- elapsed_str.strip() if elapsed_str else None
304
- )
296
+ if 'generating' in async_display_callbacks:
297
+ await async_display_callbacks['generating'](
298
+ content=content,
299
+ elapsed_time=elapsed_str.strip() if elapsed_str else None
300
+ )
305
301
 
306
302
  return Panel(Markdown(content), title=f"Generating...{elapsed_str}", border_style="green")
307
303
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: praisonaiagents
3
- Version: 0.0.19
3
+ Version: 0.0.20
4
4
  Summary: Praison AI agents for completing complex tasks with Self Reflection Agents
5
5
  Author: Mervin Praison
6
6
  Requires-Dist: pydantic
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "praisonaiagents"
7
- version = "0.0.19"
7
+ version = "0.0.20"
8
8
  description = "Praison AI agents for completing complex tasks with Self Reflection Agents"
9
9
  authors = [
10
10
  { name="Mervin Praison" }