lionagi 0.6.1__py3-none-any.whl → 0.7.1__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.
Files changed (78) hide show
  1. lionagi/libs/token_transform/__init__.py +0 -0
  2. lionagi/libs/token_transform/llmlingua.py +1 -0
  3. lionagi/libs/token_transform/perplexity.py +439 -0
  4. lionagi/libs/token_transform/synthlang.py +409 -0
  5. lionagi/operations/ReAct/ReAct.py +126 -0
  6. lionagi/operations/ReAct/utils.py +28 -0
  7. lionagi/operations/__init__.py +1 -9
  8. lionagi/operations/_act/act.py +73 -0
  9. lionagi/operations/chat/__init__.py +3 -0
  10. lionagi/operations/chat/chat.py +173 -0
  11. lionagi/operations/communicate/__init__.py +0 -0
  12. lionagi/operations/communicate/communicate.py +108 -0
  13. lionagi/operations/instruct/__init__.py +3 -0
  14. lionagi/operations/instruct/instruct.py +29 -0
  15. lionagi/operations/interpret/__init__.py +3 -0
  16. lionagi/operations/interpret/interpret.py +39 -0
  17. lionagi/operations/operate/__init__.py +3 -0
  18. lionagi/operations/operate/operate.py +194 -0
  19. lionagi/operations/parse/__init__.py +3 -0
  20. lionagi/operations/parse/parse.py +89 -0
  21. lionagi/operations/plan/plan.py +3 -3
  22. lionagi/operations/select/__init__.py +0 -4
  23. lionagi/operations/select/select.py +11 -30
  24. lionagi/operations/select/utils.py +13 -2
  25. lionagi/operations/translate/__init__.py +0 -0
  26. lionagi/operations/translate/translate.py +47 -0
  27. lionagi/operations/types.py +16 -0
  28. lionagi/operatives/action/manager.py +115 -93
  29. lionagi/operatives/action/request_response_model.py +31 -0
  30. lionagi/operatives/action/tool.py +50 -20
  31. lionagi/operatives/strategies/__init__.py +3 -0
  32. lionagi/protocols/_concepts.py +1 -1
  33. lionagi/protocols/adapters/adapter.py +25 -0
  34. lionagi/protocols/adapters/json_adapter.py +107 -27
  35. lionagi/protocols/adapters/pandas_/csv_adapter.py +55 -11
  36. lionagi/protocols/adapters/pandas_/excel_adapter.py +52 -10
  37. lionagi/protocols/adapters/pandas_/pd_dataframe_adapter.py +54 -4
  38. lionagi/protocols/adapters/pandas_/pd_series_adapter.py +40 -0
  39. lionagi/protocols/generic/element.py +1 -1
  40. lionagi/protocols/generic/pile.py +5 -8
  41. lionagi/protocols/graph/edge.py +1 -1
  42. lionagi/protocols/graph/graph.py +16 -8
  43. lionagi/protocols/graph/node.py +1 -1
  44. lionagi/protocols/mail/exchange.py +126 -15
  45. lionagi/protocols/mail/mail.py +33 -0
  46. lionagi/protocols/mail/mailbox.py +62 -0
  47. lionagi/protocols/mail/manager.py +97 -41
  48. lionagi/protocols/mail/package.py +57 -3
  49. lionagi/protocols/messages/action_request.py +77 -26
  50. lionagi/protocols/messages/action_response.py +55 -26
  51. lionagi/protocols/messages/assistant_response.py +50 -15
  52. lionagi/protocols/messages/base.py +36 -0
  53. lionagi/protocols/messages/instruction.py +175 -145
  54. lionagi/protocols/messages/manager.py +152 -56
  55. lionagi/protocols/messages/message.py +61 -25
  56. lionagi/protocols/messages/system.py +54 -19
  57. lionagi/service/imodel.py +24 -0
  58. lionagi/session/branch.py +1116 -939
  59. lionagi/utils.py +1 -0
  60. lionagi/version.py +1 -1
  61. {lionagi-0.6.1.dist-info → lionagi-0.7.1.dist-info}/METADATA +1 -1
  62. {lionagi-0.6.1.dist-info → lionagi-0.7.1.dist-info}/RECORD +75 -56
  63. lionagi/libs/compress/models.py +0 -66
  64. lionagi/libs/compress/utils.py +0 -69
  65. lionagi/operations/select/prompt.py +0 -5
  66. /lionagi/{libs/compress → operations/ReAct}/__init__.py +0 -0
  67. /lionagi/operations/{strategies → _act}/__init__.py +0 -0
  68. /lionagi/{operations → operatives}/strategies/base.py +0 -0
  69. /lionagi/{operations → operatives}/strategies/concurrent.py +0 -0
  70. /lionagi/{operations → operatives}/strategies/concurrent_chunk.py +0 -0
  71. /lionagi/{operations → operatives}/strategies/concurrent_sequential_chunk.py +0 -0
  72. /lionagi/{operations → operatives}/strategies/params.py +0 -0
  73. /lionagi/{operations → operatives}/strategies/sequential.py +0 -0
  74. /lionagi/{operations → operatives}/strategies/sequential_chunk.py +0 -0
  75. /lionagi/{operations → operatives}/strategies/sequential_concurrent_chunk.py +0 -0
  76. /lionagi/{operations → operatives}/strategies/utils.py +0 -0
  77. {lionagi-0.6.1.dist-info → lionagi-0.7.1.dist-info}/WHEEL +0 -0
  78. {lionagi-0.6.1.dist-info → lionagi-0.7.1.dist-info}/licenses/LICENSE +0 -0
@@ -2,6 +2,11 @@
2
2
  #
3
3
  # SPDX-License-Identifier: Apache-2.0
4
4
 
5
+ """
6
+ Defines the `System` class, representing system-level instructions or
7
+ settings that guide the AI's behavior from a privileged role.
8
+ """
9
+
5
10
  from datetime import datetime
6
11
  from typing import Any, NoReturn, Self
7
12
 
@@ -19,14 +24,16 @@ def format_system_content(
19
24
  system_message: str,
20
25
  ) -> dict:
21
26
  """
22
- Format system message content with optional datetime information.
27
+ Insert optional datetime string into the system message content.
23
28
 
24
29
  Args:
25
- system_datetime: Flag or string for datetime inclusion
26
- system_message: The system message content
30
+ system_datetime (bool|str|None):
31
+ If True, embed current time. If str, use as time. If None, omit.
32
+ system_message (str):
33
+ The main system message text.
27
34
 
28
35
  Returns:
29
- Note: Formatted system content
36
+ dict: The combined system content.
30
37
  """
31
38
  content: dict = {"system_message": system_message}
32
39
  if system_datetime:
@@ -40,6 +47,11 @@ def format_system_content(
40
47
 
41
48
 
42
49
  class System(RoledMessage):
50
+ """
51
+ A specialized message that sets a *system-level* context or policy.
52
+ Usually the first in a conversation, instructing the AI about general
53
+ constraints or identity.
54
+ """
43
55
 
44
56
  template: str | Template | None = jinja_env.get_template(
45
57
  "system_message.jinja2"
@@ -58,14 +70,26 @@ class System(RoledMessage):
58
70
  **kwargs,
59
71
  ) -> Self:
60
72
  """
61
- Create a new system message.
73
+ Construct a system message with optional datetime annotation.
62
74
 
63
75
  Args:
64
- system_message: The system message content
65
- system_datetime: Optional datetime flag or string
76
+ system_message (str):
77
+ The main text instructing the AI about behavior/identity.
78
+ system_datetime (bool|str, optional):
79
+ If True or str, embed a time reference. If str, it is used directly.
80
+ sender (SenderRecipient, optional):
81
+ Typically `MessageRole.SYSTEM`.
82
+ recipient (SenderRecipient, optional):
83
+ Typically `MessageRole.ASSISTANT`.
84
+ template (Template|str|None):
85
+ An optional custom template for rendering.
86
+ system (Any):
87
+ Alias for `system_message` (deprecated).
88
+ **kwargs:
89
+ Additional content merged into the final dict.
66
90
 
67
91
  Returns:
68
- System: The new system message
92
+ System: A newly created system-level message.
69
93
  """
70
94
  if system and system_message:
71
95
  raise ValueError(
@@ -78,14 +102,14 @@ class System(RoledMessage):
78
102
  system_datetime=system_datetime, system_message=system_message
79
103
  )
80
104
  content.update(kwargs)
81
- params = {}
82
- params["role"] = MessageRole.SYSTEM
83
- params["content"] = content
84
- params["sender"] = sender or MessageRole.SYSTEM
85
- params["recipient"] = recipient or MessageRole.ASSISTANT
105
+ params = {
106
+ "role": MessageRole.SYSTEM,
107
+ "content": content,
108
+ "sender": sender or MessageRole.SYSTEM,
109
+ "recipient": recipient or MessageRole.ASSISTANT,
110
+ }
86
111
  if template:
87
112
  params["template"] = template
88
-
89
113
  return cls(**params)
90
114
 
91
115
  def update(
@@ -98,13 +122,21 @@ class System(RoledMessage):
98
122
  **kwargs,
99
123
  ) -> NoReturn:
100
124
  """
101
- Update the system message components.
125
+ Adjust fields of this system message.
102
126
 
103
127
  Args:
104
- system: New system message content
105
- sender: New sender
106
- recipient: New recipient
107
- system_datetime: New datetime flag or string
128
+ system_message (JsonValue):
129
+ New system message text.
130
+ sender (SenderRecipient):
131
+ Updated sender or role.
132
+ recipient (SenderRecipient):
133
+ Updated recipient or role.
134
+ system_datetime (bool|str):
135
+ If set, embed new datetime info.
136
+ template (Template|str|None):
137
+ New template override.
138
+ **kwargs:
139
+ Additional fields for self.content.
108
140
  """
109
141
  if any([system_message, system_message]):
110
142
  self.content = format_system_content(
@@ -113,3 +145,6 @@ class System(RoledMessage):
113
145
  super().update(
114
146
  sender=sender, recipient=recipient, template=template, **kwargs
115
147
  )
148
+
149
+
150
+ # File: lionagi/protocols/messages/system.py
lionagi/service/imodel.py CHANGED
@@ -295,3 +295,27 @@ class iModel:
295
295
  **data,
296
296
  **processor_config,
297
297
  )
298
+
299
+ async def compress_text(
300
+ self,
301
+ text: str,
302
+ system_msg: str = None,
303
+ target_ratio: float = 0.2,
304
+ n_samples: int = 5,
305
+ max_tokens_per_sample=80,
306
+ verbose=True,
307
+ ) -> str:
308
+ """
309
+ Convenience function that instantiates LLMCompressor and compresses text.
310
+ """
311
+ from lionagi.libs.token_transform.perplexity import LLMCompressor
312
+
313
+ compressor = LLMCompressor(
314
+ chat_model=self,
315
+ system_msg=system_msg,
316
+ target_ratio=target_ratio,
317
+ n_samples=n_samples,
318
+ max_tokens_per_sample=max_tokens_per_sample,
319
+ verbose=verbose,
320
+ )
321
+ return await compressor.compress(text)