lionagi 0.17.10__py3-none-any.whl → 0.18.0__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 (164) hide show
  1. lionagi/__init__.py +1 -2
  2. lionagi/_class_registry.py +1 -2
  3. lionagi/_errors.py +1 -2
  4. lionagi/adapters/async_postgres_adapter.py +2 -10
  5. lionagi/config.py +1 -2
  6. lionagi/fields/action.py +1 -2
  7. lionagi/fields/base.py +3 -0
  8. lionagi/fields/code.py +3 -0
  9. lionagi/fields/file.py +3 -0
  10. lionagi/fields/instruct.py +1 -2
  11. lionagi/fields/reason.py +1 -2
  12. lionagi/fields/research.py +3 -0
  13. lionagi/libs/__init__.py +1 -2
  14. lionagi/libs/file/__init__.py +1 -2
  15. lionagi/libs/file/chunk.py +1 -2
  16. lionagi/libs/file/process.py +1 -2
  17. lionagi/libs/schema/__init__.py +1 -2
  18. lionagi/libs/schema/as_readable.py +1 -2
  19. lionagi/libs/schema/extract_code_block.py +1 -2
  20. lionagi/libs/schema/extract_docstring.py +1 -2
  21. lionagi/libs/schema/function_to_schema.py +1 -2
  22. lionagi/libs/schema/load_pydantic_model_from_schema.py +1 -2
  23. lionagi/libs/schema/minimal_yaml.py +98 -0
  24. lionagi/libs/validate/__init__.py +1 -2
  25. lionagi/libs/validate/common_field_validators.py +1 -2
  26. lionagi/libs/validate/validate_boolean.py +1 -2
  27. lionagi/ln/fuzzy/_string_similarity.py +1 -2
  28. lionagi/ln/types.py +32 -5
  29. lionagi/models/__init__.py +1 -2
  30. lionagi/models/field_model.py +9 -1
  31. lionagi/models/hashable_model.py +4 -2
  32. lionagi/models/model_params.py +1 -2
  33. lionagi/models/operable_model.py +1 -2
  34. lionagi/models/schema_model.py +1 -2
  35. lionagi/operations/ReAct/ReAct.py +475 -239
  36. lionagi/operations/ReAct/__init__.py +1 -2
  37. lionagi/operations/ReAct/utils.py +4 -2
  38. lionagi/operations/__init__.py +1 -2
  39. lionagi/operations/act/__init__.py +2 -0
  40. lionagi/operations/act/act.py +206 -0
  41. lionagi/operations/brainstorm/__init__.py +1 -2
  42. lionagi/operations/brainstorm/brainstorm.py +1 -2
  43. lionagi/operations/brainstorm/prompt.py +1 -2
  44. lionagi/operations/builder.py +1 -2
  45. lionagi/operations/chat/__init__.py +1 -2
  46. lionagi/operations/chat/chat.py +131 -116
  47. lionagi/operations/communicate/communicate.py +102 -44
  48. lionagi/operations/flow.py +5 -6
  49. lionagi/operations/instruct/__init__.py +1 -2
  50. lionagi/operations/instruct/instruct.py +1 -2
  51. lionagi/operations/interpret/__init__.py +1 -2
  52. lionagi/operations/interpret/interpret.py +66 -22
  53. lionagi/operations/operate/__init__.py +1 -2
  54. lionagi/operations/operate/operate.py +213 -108
  55. lionagi/operations/parse/__init__.py +1 -2
  56. lionagi/operations/parse/parse.py +171 -144
  57. lionagi/operations/plan/__init__.py +1 -2
  58. lionagi/operations/plan/plan.py +1 -2
  59. lionagi/operations/plan/prompt.py +1 -2
  60. lionagi/operations/select/__init__.py +1 -2
  61. lionagi/operations/select/select.py +79 -19
  62. lionagi/operations/select/utils.py +2 -3
  63. lionagi/operations/types.py +120 -25
  64. lionagi/operations/utils.py +1 -2
  65. lionagi/protocols/__init__.py +1 -2
  66. lionagi/protocols/_concepts.py +1 -2
  67. lionagi/protocols/action/__init__.py +1 -2
  68. lionagi/protocols/action/function_calling.py +3 -20
  69. lionagi/protocols/action/manager.py +34 -4
  70. lionagi/protocols/action/tool.py +1 -2
  71. lionagi/protocols/contracts.py +1 -2
  72. lionagi/protocols/forms/__init__.py +1 -2
  73. lionagi/protocols/forms/base.py +1 -2
  74. lionagi/protocols/forms/flow.py +1 -2
  75. lionagi/protocols/forms/form.py +1 -2
  76. lionagi/protocols/forms/report.py +1 -2
  77. lionagi/protocols/generic/__init__.py +1 -2
  78. lionagi/protocols/generic/element.py +17 -65
  79. lionagi/protocols/generic/event.py +1 -2
  80. lionagi/protocols/generic/log.py +17 -14
  81. lionagi/protocols/generic/pile.py +3 -4
  82. lionagi/protocols/generic/processor.py +1 -2
  83. lionagi/protocols/generic/progression.py +1 -2
  84. lionagi/protocols/graph/__init__.py +1 -2
  85. lionagi/protocols/graph/edge.py +1 -2
  86. lionagi/protocols/graph/graph.py +1 -2
  87. lionagi/protocols/graph/node.py +1 -2
  88. lionagi/protocols/ids.py +1 -2
  89. lionagi/protocols/mail/__init__.py +1 -2
  90. lionagi/protocols/mail/exchange.py +1 -2
  91. lionagi/protocols/mail/mail.py +1 -2
  92. lionagi/protocols/mail/mailbox.py +1 -2
  93. lionagi/protocols/mail/manager.py +1 -2
  94. lionagi/protocols/mail/package.py +1 -2
  95. lionagi/protocols/messages/__init__.py +28 -2
  96. lionagi/protocols/messages/action_request.py +87 -186
  97. lionagi/protocols/messages/action_response.py +74 -133
  98. lionagi/protocols/messages/assistant_response.py +131 -161
  99. lionagi/protocols/messages/base.py +27 -20
  100. lionagi/protocols/messages/instruction.py +281 -626
  101. lionagi/protocols/messages/manager.py +113 -64
  102. lionagi/protocols/messages/message.py +88 -199
  103. lionagi/protocols/messages/system.py +53 -125
  104. lionagi/protocols/operatives/__init__.py +1 -2
  105. lionagi/protocols/operatives/operative.py +1 -2
  106. lionagi/protocols/operatives/step.py +1 -2
  107. lionagi/protocols/types.py +1 -4
  108. lionagi/service/connections/__init__.py +1 -2
  109. lionagi/service/connections/api_calling.py +1 -2
  110. lionagi/service/connections/endpoint.py +1 -10
  111. lionagi/service/connections/endpoint_config.py +1 -2
  112. lionagi/service/connections/header_factory.py +1 -2
  113. lionagi/service/connections/match_endpoint.py +1 -2
  114. lionagi/service/connections/mcp/__init__.py +1 -2
  115. lionagi/service/connections/mcp/wrapper.py +1 -2
  116. lionagi/service/connections/providers/__init__.py +1 -2
  117. lionagi/service/connections/providers/anthropic_.py +1 -2
  118. lionagi/service/connections/providers/claude_code_cli.py +1 -2
  119. lionagi/service/connections/providers/exa_.py +1 -2
  120. lionagi/service/connections/providers/nvidia_nim_.py +2 -27
  121. lionagi/service/connections/providers/oai_.py +30 -96
  122. lionagi/service/connections/providers/ollama_.py +4 -4
  123. lionagi/service/connections/providers/perplexity_.py +1 -2
  124. lionagi/service/hooks/__init__.py +1 -1
  125. lionagi/service/hooks/_types.py +1 -1
  126. lionagi/service/hooks/_utils.py +1 -1
  127. lionagi/service/hooks/hook_event.py +1 -1
  128. lionagi/service/hooks/hook_registry.py +1 -1
  129. lionagi/service/hooks/hooked_event.py +3 -4
  130. lionagi/service/imodel.py +1 -2
  131. lionagi/service/manager.py +1 -2
  132. lionagi/service/rate_limited_processor.py +1 -2
  133. lionagi/service/resilience.py +1 -2
  134. lionagi/service/third_party/anthropic_models.py +1 -2
  135. lionagi/service/third_party/claude_code.py +4 -4
  136. lionagi/service/third_party/openai_models.py +433 -0
  137. lionagi/service/token_calculator.py +1 -2
  138. lionagi/session/__init__.py +1 -2
  139. lionagi/session/branch.py +171 -180
  140. lionagi/session/session.py +4 -11
  141. lionagi/tools/__init__.py +1 -2
  142. lionagi/tools/base.py +1 -2
  143. lionagi/tools/file/__init__.py +1 -2
  144. lionagi/tools/file/reader.py +3 -4
  145. lionagi/tools/types.py +1 -2
  146. lionagi/utils.py +1 -2
  147. lionagi/version.py +1 -1
  148. {lionagi-0.17.10.dist-info → lionagi-0.18.0.dist-info}/METADATA +1 -2
  149. lionagi-0.18.0.dist-info/RECORD +191 -0
  150. lionagi/operations/_act/__init__.py +0 -3
  151. lionagi/operations/_act/act.py +0 -87
  152. lionagi/protocols/messages/templates/README.md +0 -28
  153. lionagi/protocols/messages/templates/action_request.jinja2 +0 -5
  154. lionagi/protocols/messages/templates/action_response.jinja2 +0 -9
  155. lionagi/protocols/messages/templates/assistant_response.jinja2 +0 -6
  156. lionagi/protocols/messages/templates/instruction_message.jinja2 +0 -61
  157. lionagi/protocols/messages/templates/system_message.jinja2 +0 -11
  158. lionagi/protocols/messages/templates/tool_schemas.jinja2 +0 -7
  159. lionagi/service/connections/providers/types.py +0 -28
  160. lionagi/service/third_party/openai_model_names.py +0 -198
  161. lionagi/service/types.py +0 -59
  162. lionagi-0.17.10.dist-info/RECORD +0 -199
  163. {lionagi-0.17.10.dist-info → lionagi-0.18.0.dist-info}/WHEEL +0 -0
  164. {lionagi-0.17.10.dist-info → lionagi-0.18.0.dist-info}/licenses/LICENSE +0 -0
lionagi/session/branch.py CHANGED
@@ -1,5 +1,4 @@
1
- # Copyright (c) 2023 - 2025, HaiyangLi <quantocean.li at gmail dot com>
2
- #
1
+ # Copyright (c) 2023-2025, HaiyangLi <quantocean.li at gmail dot com>
3
2
  # SPDX-License-Identifier: Apache-2.0
4
3
 
5
4
  from collections.abc import AsyncGenerator, Callable
@@ -8,6 +7,7 @@ from typing import TYPE_CHECKING, Any, Literal, Optional
8
7
  from pydantic import BaseModel, Field, JsonValue, PrivateAttr, field_serializer
9
8
 
10
9
  from lionagi.config import settings
10
+ from lionagi.fields import Instruct
11
11
  from lionagi.ln.types import Unset
12
12
  from lionagi.models.field_model import FieldModel
13
13
  from lionagi.operations.flow import AlcallParams
@@ -39,8 +39,7 @@ from lionagi.protocols.types import (
39
39
  SenderRecipient,
40
40
  System,
41
41
  )
42
- from lionagi.service.connections.endpoint import Endpoint
43
- from lionagi.service.types import iModel, iModelManager
42
+ from lionagi.service import Endpoint, iModel, iModelManager
44
43
  from lionagi.tools.base import LionTool
45
44
  from lionagi.utils import copy
46
45
 
@@ -195,11 +194,11 @@ class Branch(Element, Communicatable, Relational):
195
194
  system = f"Developer Prompt: {str(system)}" if system else ""
196
195
  system = (LION_SYSTEM_MESSAGE + "\n\n" + system).strip()
197
196
 
197
+ # Note: system_template and system_template_context are deprecated
198
+ # Template rendering has been removed from the message system
198
199
  self._message_manager.add_message(
199
200
  system=system,
200
201
  system_datetime=system_datetime,
201
- template=system_template,
202
- template_context=system_template_context,
203
202
  recipient=self.id,
204
203
  sender=system_sender or self.user or MessageRole.SYSTEM,
205
204
  )
@@ -503,7 +502,7 @@ class Branch(Element, Communicatable, Relational):
503
502
  raise ValueError(
504
503
  "Invalid message package: The item must be a `RoledMessage`."
505
504
  )
506
- new_message = mail.package.item.clone()
505
+ new_message = mail.package.item.model_copy(deep=True)
507
506
  new_message.sender = mail.sender
508
507
  new_message.recipient = self.id
509
508
  self.msgs.messages.include(new_message)
@@ -633,7 +632,7 @@ class Branch(Element, Communicatable, Relational):
633
632
  async def _connect(**kwargs):
634
633
  """connect to an api endpoint"""
635
634
  api_call = await imodel.invoke(**kwargs)
636
- self._log_manager.log(Log.create(api_call))
635
+ self._log_manager.log(api_call)
637
636
  return api_call.response
638
637
 
639
638
  _connect.__name__ = name or imodel.endpoint.name
@@ -761,6 +760,7 @@ class Branch(Element, Communicatable, Relational):
761
760
  image_detail: Literal["low", "high", "auto"] = None,
762
761
  plain_content: str = None,
763
762
  return_ins_res_message: bool = False,
763
+ include_token_usage_to_model: bool = False,
764
764
  **kwargs,
765
765
  ) -> tuple[Instruction, AssistantResponse]:
766
766
  """
@@ -810,25 +810,27 @@ class Branch(Element, Communicatable, Relational):
810
810
  tuple[Instruction, AssistantResponse]:
811
811
  The `Instruction` object and the final `AssistantResponse`.
812
812
  """
813
- from lionagi.operations.chat.chat import chat
813
+ from lionagi.operations.chat.chat import ChatParam, chat
814
814
 
815
815
  return await chat(
816
816
  self,
817
817
  instruction=instruction,
818
- guidance=guidance,
819
- context=context,
820
- sender=sender,
821
- recipient=recipient,
822
- request_fields=request_fields,
823
- response_format=response_format,
824
- progression=progression,
825
- imodel=imodel or kwargs.pop("chat_model", None) or self.chat_model,
826
- tool_schemas=tool_schemas,
827
- images=images,
828
- image_detail=image_detail,
829
- plain_content=plain_content,
818
+ chat_param=ChatParam(
819
+ guidance=guidance,
820
+ context=context,
821
+ sender=sender or self.user or "user",
822
+ recipient=recipient or self.id,
823
+ response_format=response_format or request_fields,
824
+ progression=progression,
825
+ tool_schemas=tool_schemas or [],
826
+ images=images or [],
827
+ image_detail=image_detail or "auto",
828
+ plain_content=plain_content or "",
829
+ include_token_usage_to_model=include_token_usage_to_model,
830
+ imodel=imodel or self.chat_model,
831
+ imodel_kw=kwargs,
832
+ ),
830
833
  return_ins_res_message=return_ins_res_message,
831
- **kwargs,
832
834
  )
833
835
 
834
836
  async def parse(
@@ -890,25 +892,14 @@ class Branch(Element, Communicatable, Relational):
890
892
  BaseModel | dict | str | None:
891
893
  Parsed model instance, or a fallback based on `handle_validation`.
892
894
  """
893
- from lionagi.operations.parse.parse import parse
895
+ from lionagi.operations.parse.parse import parse, prepare_parse_kws
894
896
 
895
- return await parse(
896
- self,
897
- text=text,
898
- handle_validation=handle_validation,
899
- max_retries=max_retries,
900
- request_type=request_type,
901
- operative=operative,
902
- similarity_algo=similarity_algo,
903
- similarity_threshold=similarity_threshold,
904
- fuzzy_match=fuzzy_match,
905
- handle_unmatched=handle_unmatched,
906
- fill_value=fill_value,
907
- fill_mapping=fill_mapping,
908
- strict=strict,
909
- suppress_conversion_errors=suppress_conversion_errors,
910
- response_format=response_format,
911
- )
897
+ _pms = {
898
+ k: v
899
+ for k, v in locals().items()
900
+ if k not in ("self", "_pms") and v is not None
901
+ }
902
+ return await parse(self, **prepare_parse_kws(self, **_pms))
912
903
 
913
904
  async def operate(
914
905
  self,
@@ -1027,39 +1018,18 @@ class Branch(Element, Communicatable, Relational):
1027
1018
  - If both `operative_model` and `response_format` or `request_model` are given.
1028
1019
  - If the LLM's response cannot be parsed into the expected format and `handle_validation='raise'`.
1029
1020
  """
1030
- from lionagi.operations.operate.operate import operate
1031
-
1032
- return await operate(
1033
- self,
1034
- instruct=instruct,
1035
- instruction=instruction,
1036
- guidance=guidance,
1037
- context=context,
1038
- sender=sender,
1039
- recipient=recipient,
1040
- progression=progression,
1041
- chat_model=chat_model,
1042
- invoke_actions=invoke_actions,
1043
- tool_schemas=tool_schemas,
1044
- images=images,
1045
- image_detail=image_detail,
1046
- parse_model=parse_model,
1047
- skip_validation=skip_validation,
1048
- tools=tools,
1049
- operative=operative,
1050
- response_format=response_format,
1051
- actions=actions,
1052
- reason=reason,
1053
- call_params=call_params,
1054
- action_strategy=action_strategy,
1055
- verbose_action=verbose_action,
1056
- field_models=field_models,
1057
- exclude_fields=exclude_fields,
1058
- handle_validation=handle_validation,
1059
- include_token_usage_to_model=include_token_usage_to_model,
1060
- **kwargs,
1021
+ _pms = {
1022
+ k: v
1023
+ for k, v in locals().items()
1024
+ if k not in ("self", "_pms") and v is not None
1025
+ }
1026
+ from lionagi.operations.operate.operate import (
1027
+ operate,
1028
+ prepare_operate_kw,
1061
1029
  )
1062
1030
 
1031
+ return await operate(self, **prepare_operate_kw(self, **_pms))
1032
+
1063
1033
  async def communicate(
1064
1034
  self,
1065
1035
  instruction: Instruction | JsonValue = None,
@@ -1133,44 +1103,19 @@ class Branch(Element, Communicatable, Relational):
1133
1103
  - A dict of the requested fields,
1134
1104
  - or `None` if parsing fails and `handle_validation='return_none'`.
1135
1105
  """
1136
- from lionagi.operations.communicate.communicate import communicate
1106
+ _pms = {
1107
+ k: v
1108
+ for k, v in locals().items()
1109
+ if k not in ("self", "_pms", "kwargs") and v is not None
1110
+ }
1111
+ _pms.update(kwargs)
1137
1112
 
1138
- return await communicate(
1139
- self,
1140
- instruction=instruction,
1141
- guidance=guidance,
1142
- context=context,
1143
- plain_content=plain_content,
1144
- sender=sender,
1145
- recipient=recipient,
1146
- progression=progression,
1147
- response_format=response_format,
1148
- request_fields=request_fields,
1149
- chat_model=chat_model,
1150
- parse_model=parse_model,
1151
- skip_validation=skip_validation,
1152
- images=images,
1153
- image_detail=image_detail,
1154
- num_parse_retries=num_parse_retries,
1155
- clear_messages=clear_messages,
1156
- include_token_usage_to_model=include_token_usage_to_model,
1157
- **kwargs,
1113
+ from lionagi.operations.communicate.communicate import (
1114
+ communicate,
1115
+ prepare_communicate_kw,
1158
1116
  )
1159
1117
 
1160
- async def _act(
1161
- self,
1162
- action_request: ActionRequest | BaseModel | dict,
1163
- suppress_errors: bool,
1164
- verbose_action: bool,
1165
- ) -> ActionResponse:
1166
- from lionagi.operations._act.act import _act
1167
-
1168
- return await _act(
1169
- branch=self,
1170
- action_request=action_request,
1171
- suppress_errors=suppress_errors,
1172
- verbose_action=verbose_action,
1173
- )
1118
+ return await communicate(self, **prepare_communicate_kw(self, **_pms))
1174
1119
 
1175
1120
  async def act(
1176
1121
  self,
@@ -1181,54 +1126,15 @@ class Branch(Element, Communicatable, Relational):
1181
1126
  suppress_errors: bool = True,
1182
1127
  call_params: AlcallParams = None,
1183
1128
  ) -> list[ActionResponse]:
1184
- global _DEFAULT_ALCALL_PARAMS
1185
- if call_params is None:
1186
- if _DEFAULT_ALCALL_PARAMS is None:
1187
- _DEFAULT_ALCALL_PARAMS = AlcallParams(output_dropna=True)
1188
- call_params = _DEFAULT_ALCALL_PARAMS
1189
-
1190
- kw = {
1191
- "suppress_errors": suppress_errors,
1192
- "verbose_action": verbose_action,
1193
- }
1194
-
1195
- match strategy:
1196
- case "concurrent":
1197
- return await self._concurrent_act(
1198
- action_request, call_params, **kw
1199
- )
1200
- case "sequential":
1201
- return await self._sequential_act(action_request, **kw)
1202
- case _:
1203
- raise ValueError(
1204
- "Invalid strategy. Choose 'concurrent' or 'sequential'."
1205
- )
1206
1129
 
1207
- async def _concurrent_act(
1208
- self,
1209
- action_request: ActionRequest | BaseModel | dict,
1210
- call_params: AlcallParams = None,
1211
- **kwargs,
1212
- ) -> list:
1213
- return await call_params(action_request, self._act, **kwargs)
1130
+ _pms = {
1131
+ k: v
1132
+ for k, v in locals().items()
1133
+ if k not in ("self", "_pms") and v is not None
1134
+ }
1135
+ from lionagi.operations.act.act import act, prepare_act_kw
1214
1136
 
1215
- async def _sequential_act(
1216
- self,
1217
- action_request: ActionRequest | BaseModel | dict,
1218
- suppress_errors: bool = True,
1219
- verbose_action: bool = False,
1220
- ) -> list:
1221
- action_request = (
1222
- action_request
1223
- if isinstance(action_request, list)
1224
- else [action_request]
1225
- )
1226
- results = []
1227
- for req in action_request:
1228
- results.append(
1229
- await self._act(req, verbose_action, suppress_errors)
1230
- )
1231
- return results
1137
+ return await act(self, **prepare_act_kw(self, **_pms))
1232
1138
 
1233
1139
  async def interpret(
1234
1140
  self,
@@ -1276,17 +1182,21 @@ class Branch(Element, Communicatable, Relational):
1276
1182
  # refined might be "Explain step-by-step how to set up a marketing analytics
1277
1183
  # pipeline to track campaign performance..."
1278
1184
  """
1279
- from lionagi.operations.interpret.interpret import interpret
1280
1185
 
1281
- return await interpret(
1282
- self,
1283
- text=text,
1284
- domain=domain,
1285
- style=style,
1286
- interpret_model=interpret_model,
1287
- **kwargs,
1186
+ _pms = {
1187
+ k: v
1188
+ for k, v in locals().items()
1189
+ if k not in ("self", "_pms", "kwargs") and v is not None
1190
+ }
1191
+ _pms.update(kwargs)
1192
+
1193
+ from lionagi.operations.interpret.interpret import (
1194
+ interpret,
1195
+ prepare_interpret_kw,
1288
1196
  )
1289
1197
 
1198
+ return await interpret(self, **prepare_interpret_kw(self, **_pms))
1199
+
1290
1200
  async def instruct(
1291
1201
  self,
1292
1202
  instruct: "Instruct",
@@ -1414,6 +1324,13 @@ class Branch(Element, Communicatable, Relational):
1414
1324
  """
1415
1325
  from lionagi.operations.ReAct.ReAct import ReAct
1416
1326
 
1327
+ # Remove potential duplicate parameters from kwargs
1328
+ kwargs_filtered = {
1329
+ k: v
1330
+ for k, v in kwargs.items()
1331
+ if k not in {"verbose_analysis", "verbose_action"}
1332
+ }
1333
+
1417
1334
  return await ReAct(
1418
1335
  self,
1419
1336
  instruct,
@@ -1439,7 +1356,7 @@ class Branch(Element, Communicatable, Relational):
1439
1356
  reasoning_effort=reasoning_effort,
1440
1357
  display_as=display_as,
1441
1358
  include_token_usage_to_model=include_token_usage_to_model,
1442
- **kwargs,
1359
+ **kwargs_filtered,
1443
1360
  )
1444
1361
 
1445
1362
  async def ReActStream(
@@ -1467,40 +1384,114 @@ class Branch(Element, Communicatable, Relational):
1467
1384
  include_token_usage_to_model: bool = True,
1468
1385
  **kwargs,
1469
1386
  ) -> AsyncGenerator:
1387
+ from lionagi.ln.fuzzy import FuzzyMatchKeysParams
1470
1388
  from lionagi.operations.ReAct.ReAct import ReActStream
1389
+ from lionagi.operations.ReAct.utils import ReActAnalysis
1390
+ from lionagi.operations.types import (
1391
+ ActionParam,
1392
+ ChatParam,
1393
+ InterpretParam,
1394
+ ParseParam,
1395
+ )
1396
+
1397
+ # Convert Instruct to dict if needed
1398
+ instruct_dict = (
1399
+ instruct.to_dict()
1400
+ if isinstance(instruct, Instruct)
1401
+ else dict(instruct)
1402
+ )
1403
+
1404
+ # Build InterpretContext if interpretation requested
1405
+ intp_param = None
1406
+ if interpret:
1407
+ intp_param = InterpretParam(
1408
+ domain=interpret_domain or "general",
1409
+ style=interpret_style or "concise",
1410
+ sample_writing=interpret_sample or "",
1411
+ imodel=interpret_model or analysis_model or self.chat_model,
1412
+ imodel_kw=interpret_kwargs or {},
1413
+ )
1414
+
1415
+ # Build ChatContext
1416
+ chat_param = ChatParam(
1417
+ guidance=instruct_dict.get("guidance"),
1418
+ context=instruct_dict.get("context"),
1419
+ sender=self.user or "user",
1420
+ recipient=self.id,
1421
+ response_format=None,
1422
+ progression=None,
1423
+ tool_schemas=tool_schemas or [],
1424
+ images=[],
1425
+ image_detail="auto",
1426
+ plain_content="",
1427
+ include_token_usage_to_model=include_token_usage_to_model,
1428
+ imodel=analysis_model or self.chat_model,
1429
+ imodel_kw=kwargs,
1430
+ )
1431
+
1432
+ # Build ActionContext
1433
+ action_param = None
1434
+ if tools is not None or tool_schemas is not None:
1435
+ from lionagi.operations.act.act import _get_default_call_params
1436
+
1437
+ action_param = ActionParam(
1438
+ action_call_params=_get_default_call_params(),
1439
+ tools=tools or True,
1440
+ strategy="concurrent",
1441
+ suppress_errors=True,
1442
+ verbose_action=False,
1443
+ )
1444
+
1445
+ # Build ParseContext
1446
+ from lionagi.operations.parse.parse import get_default_call
1447
+
1448
+ parse_param = ParseParam(
1449
+ response_format=ReActAnalysis,
1450
+ fuzzy_match_params=FuzzyMatchKeysParams(),
1451
+ handle_validation="return_value",
1452
+ alcall_params=get_default_call(),
1453
+ imodel=analysis_model or self.chat_model,
1454
+ imodel_kw={},
1455
+ )
1456
+
1457
+ # Response context for final answer
1458
+ resp_ctx = response_kwargs or {}
1459
+ if response_format:
1460
+ resp_ctx["response_format"] = response_format
1471
1461
 
1472
1462
  async for result in ReActStream(
1473
1463
  self,
1474
- instruct,
1475
- interpret=interpret,
1476
- interpret_domain=interpret_domain,
1477
- interpret_style=interpret_style,
1478
- interpret_sample=interpret_sample,
1479
- interpret_model=interpret_model,
1480
- interpret_kwargs=interpret_kwargs,
1481
- tools=tools,
1482
- tool_schemas=tool_schemas,
1483
- response_format=response_format,
1464
+ instruction=instruct_dict.get("instruction", str(instruct)),
1465
+ chat_param=chat_param,
1466
+ action_param=action_param,
1467
+ parse_param=parse_param,
1468
+ intp_param=intp_param,
1469
+ resp_ctx=resp_ctx,
1470
+ reasoning_effort=reasoning_effort,
1471
+ reason=True,
1472
+ field_models=None,
1473
+ handle_validation="return_value",
1474
+ invoke_actions=True,
1475
+ clear_messages=False,
1484
1476
  intermediate_response_options=intermediate_response_options,
1485
1477
  intermediate_listable=intermediate_listable,
1486
- reasoning_effort=reasoning_effort,
1487
- extension_allowed=extension_allowed,
1478
+ intermediate_nullable=False,
1488
1479
  max_extensions=max_extensions,
1489
- response_kwargs=response_kwargs,
1490
- analysis_model=analysis_model,
1491
- verbose_analysis=True,
1480
+ extension_allowed=extension_allowed,
1481
+ verbose_analysis=verbose,
1492
1482
  display_as=display_as,
1493
1483
  verbose_length=verbose_length,
1494
- include_token_usage_to_model=include_token_usage_to_model,
1495
- **kwargs,
1484
+ continue_after_failed_response=False,
1496
1485
  ):
1497
- analysis, str_ = result
1498
1486
  if verbose:
1487
+ analysis, str_ = result
1499
1488
  from lionagi.libs.schema.as_readable import as_readable
1500
1489
 
1501
1490
  str_ += "\n---------\n"
1502
1491
  as_readable(str_, md=True, display_str=True)
1503
- yield analysis
1492
+ yield analysis
1493
+ else:
1494
+ yield result
1504
1495
 
1505
1496
 
1506
1497
  # File: lionagi/session/branch.py
@@ -1,5 +1,4 @@
1
- # Copyright (c) 2023 - 2025, HaiyangLi <quantocean.li at gmail dot com>
2
- #
1
+ # Copyright (c) 2023-2025, HaiyangLi <quantocean.li at gmail dot com>
3
2
  # SPDX-License-Identifier: Apache-2.0
4
3
 
5
4
  import contextlib
@@ -23,7 +22,6 @@ from lionagi.protocols.types import (
23
22
  Graph,
24
23
  IDType,
25
24
  MailManager,
26
- MessageFlag,
27
25
  Node,
28
26
  Pile,
29
27
  Progression,
@@ -274,17 +272,12 @@ class Session(Node, Communicatable, Relational):
274
272
  if any(i not in self.branches for i in branches):
275
273
  raise ValueError("Branch does not exist.")
276
274
 
277
- exclude_flag = []
278
- if exclude_clone:
279
- exclude_flag.append(MessageFlag.MESSAGE_CLONE)
280
- if exclude_load:
281
- exclude_flag.append(MessageFlag.MESSAGE_LOAD)
275
+ # Note: exclude_clone and exclude_load parameters are deprecated
276
+ # and currently have no effect. They are kept for API compatibility.
282
277
 
283
278
  messages = lcall(
284
279
  branches,
285
- lambda x: [
286
- i for i in self.branches[x].messages if i not in exclude_flag
287
- ],
280
+ lambda x: list(self.branches[x].messages),
288
281
  input_unique=True,
289
282
  input_flatten=True,
290
283
  input_dropna=True,
lionagi/tools/__init__.py CHANGED
@@ -1,3 +1,2 @@
1
- # Copyright (c) 2023 - 2025, HaiyangLi <quantocean.li at gmail dot com>
2
- #
1
+ # Copyright (c) 2023-2025, HaiyangLi <quantocean.li at gmail dot com>
3
2
  # SPDX-License-Identifier: Apache-2.0
lionagi/tools/base.py CHANGED
@@ -1,5 +1,4 @@
1
- # Copyright (c) 2023 - 2025, HaiyangLi <quantocean.li at gmail dot com>
2
- #
1
+ # Copyright (c) 2023-2025, HaiyangLi <quantocean.li at gmail dot com>
3
2
  # SPDX-License-Identifier: Apache-2.0
4
3
 
5
4
  from abc import ABC, abstractmethod
@@ -1,3 +1,2 @@
1
- # Copyright (c) 2023 - 2025, HaiyangLi <quantocean.li at gmail dot com>
2
- #
1
+ # Copyright (c) 2023-2025, HaiyangLi <quantocean.li at gmail dot com>
3
2
  # SPDX-License-Identifier: Apache-2.0
@@ -1,5 +1,4 @@
1
- # Copyright (c) 2023 - 2025, HaiyangLi <quantocean.li at gmail dot com>
2
- #
1
+ # Copyright (c) 2023-2025, HaiyangLi <quantocean.li at gmail dot com>
3
2
  # SPDX-License-Identifier: Apache-2.0
4
3
 
5
4
  import tempfile
@@ -80,8 +79,8 @@ class ReaderRequest(BaseModel):
80
79
  ),
81
80
  )
82
81
 
83
- recursive: bool = Field(
84
- False,
82
+ recursive: bool | None = Field(
83
+ None,
85
84
  description=(
86
85
  "Whether to recursively list files in subdirectories. Defaults to False."
87
86
  "Only used if action='list_dir'."
lionagi/tools/types.py CHANGED
@@ -1,5 +1,4 @@
1
- # Copyright (c) 2023 - 2025, HaiyangLi <quantocean.li at gmail dot com>
2
- #
1
+ # Copyright (c) 2023-2025, HaiyangLi <quantocean.li at gmail dot com>
3
2
  # SPDX-License-Identifier: Apache-2.0
4
3
 
5
4
 
lionagi/utils.py CHANGED
@@ -1,5 +1,4 @@
1
- # Copyright (c) 2023 - 2025, HaiyangLi <quantocean.li at gmail dot com>
2
- #
1
+ # Copyright (c) 2023-2025, HaiyangLi <quantocean.li at gmail dot com>
3
2
  # SPDX-License-Identifier: Apache-2.0
4
3
 
5
4
  import copy as _copy
lionagi/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.17.10"
1
+ __version__ = "0.18.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lionagi
3
- Version: 0.17.10
3
+ Version: 0.18.0
4
4
  Summary: An Intelligence Operating System.
5
5
  Author-email: HaiyangLi <quantocean.li@gmail.com>
6
6
  License: Apache License
@@ -223,7 +223,6 @@ Requires-Dist: aiocache>=0.12.0
223
223
  Requires-Dist: aiohttp>=3.11.0
224
224
  Requires-Dist: anyio>=4.7.0
225
225
  Requires-Dist: backoff>=2.0.0
226
- Requires-Dist: jinja2>=3.0.0
227
226
  Requires-Dist: json-repair>=0.40.0
228
227
  Requires-Dist: msgspec>=0.18.0
229
228
  Requires-Dist: pydantic-settings>=2.8.0