praisonaiagents 0.0.17__py3-none-any.whl → 0.0.18__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.
@@ -16,6 +16,8 @@ from .main import (
16
16
  display_generating,
17
17
  clean_triple_backticks,
18
18
  error_logs,
19
+ register_display_callback,
20
+ display_callbacks,
19
21
  )
20
22
 
21
23
  __all__ = [
@@ -32,4 +34,6 @@ __all__ = [
32
34
  'display_generating',
33
35
  'clean_triple_backticks',
34
36
  'error_logs',
37
+ 'register_display_callback',
38
+ 'display_callbacks',
35
39
  ]
praisonaiagents/main.py CHANGED
@@ -25,6 +25,13 @@ logging.basicConfig(
25
25
  # Global list to store error logs
26
26
  error_logs = []
27
27
 
28
+ # Global callback registry
29
+ display_callbacks = {}
30
+
31
+ def register_display_callback(display_type: str, callback_fn):
32
+ """Register a callback function for a specific display type."""
33
+ display_callbacks[display_type] = callback_fn
34
+
28
35
  def _clean_display_content(content: str, max_length: int = 20000) -> str:
29
36
  """Helper function to clean and truncate content for display."""
30
37
  if not content or not str(content).strip():
@@ -49,18 +56,28 @@ def display_interaction(message, response, markdown=True, generation_time=None,
49
56
  """Display the interaction between user and assistant."""
50
57
  if console is None:
51
58
  console = Console()
52
- if generation_time:
53
- console.print(Text(f"Response generated in {generation_time:.1f}s", style="dim"))
54
-
59
+
55
60
  # Handle multimodal content (list)
56
61
  if isinstance(message, list):
57
- # Extract just the text content from the multimodal message
58
62
  text_content = next((item["text"] for item in message if item["type"] == "text"), "")
59
63
  message = text_content
60
64
 
61
65
  message = _clean_display_content(str(message))
62
66
  response = _clean_display_content(str(response))
63
67
 
68
+ # Execute callback if registered
69
+ if 'interaction' in display_callbacks:
70
+ display_callbacks['interaction'](
71
+ message=message,
72
+ response=response,
73
+ markdown=markdown,
74
+ generation_time=generation_time
75
+ )
76
+
77
+ # Existing display logic...
78
+ if generation_time:
79
+ console.print(Text(f"Response generated in {generation_time:.1f}s", style="dim"))
80
+
64
81
  if markdown:
65
82
  console.print(Panel.fit(Markdown(message), title="Message", border_style="cyan"))
66
83
  console.print(Panel.fit(Markdown(response), title="Response", border_style="cyan"))
@@ -74,6 +91,11 @@ def display_self_reflection(message: str, console=None):
74
91
  if console is None:
75
92
  console = Console()
76
93
  message = _clean_display_content(str(message))
94
+
95
+ # Execute callback if registered
96
+ if 'self_reflection' in display_callbacks:
97
+ display_callbacks['self_reflection'](message=message)
98
+
77
99
  console.print(Panel.fit(Text(message, style="bold yellow"), title="Self Reflection", border_style="magenta"))
78
100
 
79
101
  def display_instruction(message: str, console=None):
@@ -82,6 +104,11 @@ def display_instruction(message: str, console=None):
82
104
  if console is None:
83
105
  console = Console()
84
106
  message = _clean_display_content(str(message))
107
+
108
+ # Execute callback if registered
109
+ if 'instruction' in display_callbacks:
110
+ display_callbacks['instruction'](message=message)
111
+
85
112
  console.print(Panel.fit(Text(message, style="bold blue"), title="Instruction", border_style="cyan"))
86
113
 
87
114
  def display_tool_call(message: str, console=None):
@@ -90,6 +117,11 @@ def display_tool_call(message: str, console=None):
90
117
  if console is None:
91
118
  console = Console()
92
119
  message = _clean_display_content(str(message))
120
+
121
+ # Execute callback if registered
122
+ if 'tool_call' in display_callbacks:
123
+ display_callbacks['tool_call'](message=message)
124
+
93
125
  console.print(Panel.fit(Text(message, style="bold cyan"), title="Tool Call", border_style="green"))
94
126
 
95
127
  def display_error(message: str, console=None):
@@ -98,19 +130,32 @@ def display_error(message: str, console=None):
98
130
  if console is None:
99
131
  console = Console()
100
132
  message = _clean_display_content(str(message))
133
+
134
+ # Execute callback if registered
135
+ if 'error' in display_callbacks:
136
+ display_callbacks['error'](message=message)
137
+
101
138
  console.print(Panel.fit(Text(message, style="bold red"), title="Error", border_style="red"))
102
- # Store errors
103
139
  error_logs.append(message)
104
140
 
105
141
  def display_generating(content: str = "", start_time: Optional[float] = None):
106
142
  if not content or not str(content).strip():
107
- return Panel("", title="", border_style="green") # Return empty panel when no content
143
+ return Panel("", title="", border_style="green")
144
+
108
145
  elapsed_str = ""
109
146
  if start_time is not None:
110
147
  elapsed = time.time() - start_time
111
148
  elapsed_str = f" {elapsed:.1f}s"
112
149
 
113
150
  content = _clean_display_content(str(content))
151
+
152
+ # Execute callback if registered
153
+ if 'generating' in display_callbacks:
154
+ display_callbacks['generating'](
155
+ content=content,
156
+ elapsed_time=elapsed_str.strip() if elapsed_str else None
157
+ )
158
+
114
159
  return Panel(Markdown(content), title=f"Generating...{elapsed_str}", border_style="green")
115
160
 
116
161
  def clean_triple_backticks(text: str) -> str:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: praisonaiagents
3
- Version: 0.0.17
3
+ Version: 0.0.18
4
4
  Summary: Praison AI agents for completing complex tasks with Self Reflection Agents
5
5
  Author: Mervin Praison
6
6
  Requires-Dist: pydantic
@@ -1,5 +1,5 @@
1
- praisonaiagents/__init__.py,sha256=gI8vEabBTRPsE_E8GA5sBMi4sTtJI-YokPrH2Nor-k0,741
2
- praisonaiagents/main.py,sha256=K2OxVKPmo4dNJbSWIsXDi_hm9CRx5O4km_74UGcszhk,5744
1
+ praisonaiagents/__init__.py,sha256=bXQwi56S1iZOXs_TyXs3doxVxAeRAyqKVyZEIoBOipM,853
2
+ praisonaiagents/main.py,sha256=QP45NxcrVs4PboVWcVkvLcsqiU7EzgE1ukH13jcYKfo,6985
3
3
  praisonaiagents/agent/__init__.py,sha256=sKO8wGEXvtCrvV1e834r1Okv0XAqAxqZCqz6hKLiTvA,79
4
4
  praisonaiagents/agent/agent.py,sha256=_UmUWGbZjd3tApPX2T6RPB5Pll3Gos97XBhhg_zmfn8,30662
5
5
  praisonaiagents/agents/__init__.py,sha256=7RDeQNSqZg5uBjD4M_0p_F6YgfWuDuxPFydPU50kDYc,120
@@ -16,7 +16,7 @@ praisonaiagents/process/__init__.py,sha256=lkYbL7Hn5a0ldvJtkdH23vfIIZLIcanK-65C0
16
16
  praisonaiagents/process/process.py,sha256=4qXdrCDQPH5MtvHvdJVURXKNgSl6ae3OYTiqAF_A2ZU,24295
17
17
  praisonaiagents/task/__init__.py,sha256=VL5hXVmyGjINb34AalxpBMl-YW9m5EDcRkMTKkSSl7c,80
18
18
  praisonaiagents/task/task.py,sha256=UiiWgLDOdX_w0opP8h8-u-leVZlq1CkpGUmf7L2qyJs,3110
19
- praisonaiagents-0.0.17.dist-info/METADATA,sha256=oh0bnTHpGDwnn15L-t8v4kdApFBwOZ_BKj24mGnJUqA,233
20
- praisonaiagents-0.0.17.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
21
- praisonaiagents-0.0.17.dist-info/top_level.txt,sha256=_HsRddrJ23iDx5TTqVUVvXG2HeHBL5voshncAMDGjtA,16
22
- praisonaiagents-0.0.17.dist-info/RECORD,,
19
+ praisonaiagents-0.0.18.dist-info/METADATA,sha256=JtO_vQUfxUb2EM2x_PSt1HqTf3biR65fyz4tg0_PF0Q,233
20
+ praisonaiagents-0.0.18.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
21
+ praisonaiagents-0.0.18.dist-info/top_level.txt,sha256=_HsRddrJ23iDx5TTqVUVvXG2HeHBL5voshncAMDGjtA,16
22
+ praisonaiagents-0.0.18.dist-info/RECORD,,