lionagi 0.12.3__tar.gz → 0.12.5__tar.gz

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 (292) hide show
  1. {lionagi-0.12.3 → lionagi-0.12.5}/.github/workflows/ci.yml +1 -1
  2. {lionagi-0.12.3 → lionagi-0.12.5}/.github/workflows/release.yml +1 -1
  3. {lionagi-0.12.3 → lionagi-0.12.5}/.gitignore +4 -1
  4. {lionagi-0.12.3 → lionagi-0.12.5}/PKG-INFO +17 -19
  5. {lionagi-0.12.3 → lionagi-0.12.5}/README.md +5 -5
  6. lionagi-0.12.5/lionagi/config.py +123 -0
  7. lionagi-0.12.5/lionagi/libs/schema/load_pydantic_model_from_schema.py +259 -0
  8. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/token_transform/perplexity.py +2 -4
  9. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/token_transform/synthlang_/translate_to_synthlang.py +1 -1
  10. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/chat/chat.py +2 -2
  11. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/communicate/communicate.py +20 -5
  12. lionagi-0.12.5/lionagi/operations/parse/parse.py +187 -0
  13. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/generic/pile.py +94 -33
  14. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/graph/node.py +25 -19
  15. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/messages/assistant_response.py +20 -1
  16. lionagi-0.12.5/lionagi/service/connections/__init__.py +15 -0
  17. lionagi-0.12.5/lionagi/service/connections/api_calling.py +230 -0
  18. lionagi-0.12.5/lionagi/service/connections/endpoint.py +410 -0
  19. lionagi-0.12.5/lionagi/service/connections/endpoint_config.py +137 -0
  20. lionagi-0.12.5/lionagi/service/connections/header_factory.py +56 -0
  21. lionagi-0.12.5/lionagi/service/connections/match_endpoint.py +49 -0
  22. lionagi-0.12.5/lionagi/service/connections/providers/__init__.py +3 -0
  23. lionagi-0.12.5/lionagi/service/connections/providers/anthropic_.py +87 -0
  24. lionagi-0.12.5/lionagi/service/connections/providers/exa_.py +33 -0
  25. lionagi-0.12.5/lionagi/service/connections/providers/oai_.py +166 -0
  26. lionagi-0.12.5/lionagi/service/connections/providers/ollama_.py +122 -0
  27. lionagi-0.12.5/lionagi/service/connections/providers/perplexity_.py +29 -0
  28. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/service/imodel.py +36 -144
  29. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/service/manager.py +1 -7
  30. {lionagi-0.12.3/lionagi/service/endpoints → lionagi-0.12.5/lionagi/service}/rate_limited_processor.py +4 -2
  31. lionagi-0.12.5/lionagi/service/resilience.py +545 -0
  32. lionagi-0.12.5/lionagi/service/third_party/README.md +71 -0
  33. lionagi-0.12.5/lionagi/service/third_party/anthropic_models.py +159 -0
  34. lionagi-0.12.3/lionagi/service/providers/exa_/models.py → lionagi-0.12.5/lionagi/service/third_party/exa_models.py +18 -13
  35. lionagi-0.12.5/lionagi/service/third_party/openai_models.py +18241 -0
  36. lionagi-0.12.5/lionagi/service/third_party/pplx_models.py +156 -0
  37. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/service/types.py +5 -4
  38. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/session/branch.py +12 -7
  39. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/tools/file/reader.py +1 -1
  40. lionagi-0.12.5/lionagi/tools/memory/tools.py +497 -0
  41. lionagi-0.12.5/lionagi/version.py +1 -0
  42. {lionagi-0.12.3 → lionagi-0.12.5}/pyproject.toml +33 -14
  43. {lionagi-0.12.3 → lionagi-0.12.5}/uv.lock +279 -229
  44. lionagi-0.12.3/lionagi/adapters/__init__.py +0 -1
  45. lionagi-0.12.3/lionagi/adapters/adapter.py +0 -120
  46. lionagi-0.12.3/lionagi/adapters/json_adapter.py +0 -181
  47. lionagi-0.12.3/lionagi/adapters/pandas_/csv_adapter.py +0 -94
  48. lionagi-0.12.3/lionagi/adapters/pandas_/excel_adapter.py +0 -94
  49. lionagi-0.12.3/lionagi/adapters/pandas_/pd_dataframe_adapter.py +0 -81
  50. lionagi-0.12.3/lionagi/adapters/pandas_/pd_series_adapter.py +0 -57
  51. lionagi-0.12.3/lionagi/adapters/toml_adapter.py +0 -204
  52. lionagi-0.12.3/lionagi/adapters/types.py +0 -21
  53. lionagi-0.12.3/lionagi/operations/parse/parse.py +0 -99
  54. lionagi-0.12.3/lionagi/service/endpoints/base.py +0 -706
  55. lionagi-0.12.3/lionagi/service/endpoints/chat_completion.py +0 -116
  56. lionagi-0.12.3/lionagi/service/endpoints/match_endpoint.py +0 -72
  57. lionagi-0.12.3/lionagi/service/providers/anthropic_/messages.py +0 -99
  58. lionagi-0.12.3/lionagi/service/providers/exa_/search.py +0 -80
  59. lionagi-0.12.3/lionagi/service/providers/exa_/types.py +0 -7
  60. lionagi-0.12.3/lionagi/service/providers/groq_/__init__.py +0 -3
  61. lionagi-0.12.3/lionagi/service/providers/groq_/chat_completions.py +0 -56
  62. lionagi-0.12.3/lionagi/service/providers/ollama_/__init__.py +0 -3
  63. lionagi-0.12.3/lionagi/service/providers/ollama_/chat_completions.py +0 -134
  64. lionagi-0.12.3/lionagi/service/providers/openai_/__init__.py +0 -3
  65. lionagi-0.12.3/lionagi/service/providers/openai_/chat_completions.py +0 -101
  66. lionagi-0.12.3/lionagi/service/providers/openai_/spec.py +0 -14
  67. lionagi-0.12.3/lionagi/service/providers/openrouter_/__init__.py +0 -3
  68. lionagi-0.12.3/lionagi/service/providers/openrouter_/chat_completions.py +0 -62
  69. lionagi-0.12.3/lionagi/service/providers/perplexity_/__init__.py +0 -3
  70. lionagi-0.12.3/lionagi/service/providers/perplexity_/chat_completions.py +0 -44
  71. lionagi-0.12.3/lionagi/service/providers/perplexity_/models.py +0 -144
  72. lionagi-0.12.3/lionagi/service/providers/types.py +0 -17
  73. lionagi-0.12.3/lionagi/session/__init__.py +0 -3
  74. lionagi-0.12.3/lionagi/tools/__init__.py +0 -3
  75. lionagi-0.12.3/lionagi/tools/file/__init__.py +0 -3
  76. lionagi-0.12.3/lionagi/version.py +0 -1
  77. {lionagi-0.12.3 → lionagi-0.12.5}/.coveragerc +0 -0
  78. {lionagi-0.12.3 → lionagi-0.12.5}/.env.example +0 -0
  79. {lionagi-0.12.3 → lionagi-0.12.5}/.github/FUNDING.yml +0 -0
  80. {lionagi-0.12.3 → lionagi-0.12.5}/.github/dependabot.yml +0 -0
  81. {lionagi-0.12.3 → lionagi-0.12.5}/.github/workflows/codeql.yml +0 -0
  82. {lionagi-0.12.3 → lionagi-0.12.5}/.github/workflows/docs.yml +0 -0
  83. {lionagi-0.12.3 → lionagi-0.12.5}/.pre-commit-config.yaml +0 -0
  84. {lionagi-0.12.3 → lionagi-0.12.5}/.python-version +0 -0
  85. {lionagi-0.12.3 → lionagi-0.12.5}/CODE_OF_CONDUCT.md +0 -0
  86. {lionagi-0.12.3 → lionagi-0.12.5}/CONTRIBUTING.md +0 -0
  87. {lionagi-0.12.3 → lionagi-0.12.5}/LICENSE +0 -0
  88. {lionagi-0.12.3 → lionagi-0.12.5}/cookbooks/ch01_get_started.md +0 -0
  89. {lionagi-0.12.3 → lionagi-0.12.5}/cookbooks/ch02_concepts.md +0 -0
  90. {lionagi-0.12.3 → lionagi-0.12.5}/docs/Makefile +0 -0
  91. {lionagi-0.12.3 → lionagi-0.12.5}/docs/_static/custom.css +0 -0
  92. {lionagi-0.12.3 → lionagi-0.12.5}/docs/_templates/layout.html +0 -0
  93. {lionagi-0.12.3 → lionagi-0.12.5}/docs/conf.py +0 -0
  94. {lionagi-0.12.3 → lionagi-0.12.5}/docs/index.rst +0 -0
  95. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/action.rst +0 -0
  96. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/adapter.rst +0 -0
  97. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/branch.rst +0 -0
  98. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/branch_operations.rst +0 -0
  99. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/concepts.rst +0 -0
  100. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/element_id.rst +0 -0
  101. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/event.rst +0 -0
  102. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/form.rst +0 -0
  103. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/graph.rst +0 -0
  104. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/index.rst +0 -0
  105. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/instruct.rst +0 -0
  106. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/lib_file.rst +0 -0
  107. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/lib_nested.rst +0 -0
  108. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/lib_package.rst +0 -0
  109. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/lib_schema.rst +0 -0
  110. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/lib_validate.rst +0 -0
  111. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/log.rst +0 -0
  112. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/mail.rst +0 -0
  113. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/message.rst +0 -0
  114. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/models.rst +0 -0
  115. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/operative_step.rst +0 -0
  116. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/pile.rst +0 -0
  117. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/processor.rst +0 -0
  118. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/progression.rst +0 -0
  119. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/service.rst +0 -0
  120. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/session.rst +0 -0
  121. {lionagi-0.12.3 → lionagi-0.12.5}/docs/modules/utils.rst +0 -0
  122. {lionagi-0.12.3 → lionagi-0.12.5}/docs/tutorials/get_started.rst +0 -0
  123. {lionagi-0.12.3 → lionagi-0.12.5}/docs/tutorials/get_started_pt2.rst +0 -0
  124. {lionagi-0.12.3 → lionagi-0.12.5}/docs/tutorials/get_started_pt3.rst +0 -0
  125. {lionagi-0.12.3 → lionagi-0.12.5}/docs/tutorials/index.rst +0 -0
  126. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/__init__.py +0 -0
  127. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/_class_registry.py +0 -0
  128. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/_errors.py +0 -0
  129. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/_types.py +0 -0
  130. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/fields/__init__.py +0 -0
  131. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/fields/action.py +0 -0
  132. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/fields/base.py +0 -0
  133. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/fields/code.py +0 -0
  134. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/fields/file.py +0 -0
  135. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/fields/instruct.py +0 -0
  136. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/fields/reason.py +0 -0
  137. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/fields/research.py +0 -0
  138. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/__init__.py +0 -0
  139. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/file/__init__.py +0 -0
  140. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/file/chunk.py +0 -0
  141. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/file/concat.py +0 -0
  142. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/file/concat_files.py +0 -0
  143. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/file/file_ops.py +0 -0
  144. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/file/params.py +0 -0
  145. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/file/process.py +0 -0
  146. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/file/save.py +0 -0
  147. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/nested/__init__.py +0 -0
  148. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/nested/flatten.py +0 -0
  149. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/nested/nfilter.py +0 -0
  150. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/nested/nget.py +0 -0
  151. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/nested/ninsert.py +0 -0
  152. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/nested/nmerge.py +0 -0
  153. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/nested/npop.py +0 -0
  154. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/nested/nset.py +0 -0
  155. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/nested/unflatten.py +0 -0
  156. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/nested/utils.py +0 -0
  157. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/package/__init__.py +0 -0
  158. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/package/imports.py +0 -0
  159. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/package/management.py +0 -0
  160. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/package/params.py +0 -0
  161. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/package/system.py +0 -0
  162. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/parse.py +0 -0
  163. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/schema/__init__.py +0 -0
  164. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/schema/as_readable.py +0 -0
  165. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/schema/extract_code_block.py +0 -0
  166. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/schema/extract_docstring.py +0 -0
  167. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/schema/function_to_schema.py +0 -0
  168. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/schema/json_schema.py +0 -0
  169. {lionagi-0.12.3/lionagi/adapters/pandas_ → lionagi-0.12.5/lionagi/libs/token_transform}/__init__.py +0 -0
  170. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/token_transform/base.py +0 -0
  171. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/token_transform/llmlingua.py +0 -0
  172. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/token_transform/symbolic_compress_context.py +0 -0
  173. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/token_transform/synthlang.py +0 -0
  174. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/token_transform/synthlang_/base.py +0 -0
  175. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/token_transform/synthlang_/resources/frameworks/abstract_algebra.toml +0 -0
  176. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/token_transform/synthlang_/resources/frameworks/category_theory.toml +0 -0
  177. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/token_transform/synthlang_/resources/frameworks/complex_analysis.toml +0 -0
  178. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/token_transform/synthlang_/resources/frameworks/framework_options.json +0 -0
  179. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/token_transform/synthlang_/resources/frameworks/group_theory.toml +0 -0
  180. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/token_transform/synthlang_/resources/frameworks/math_logic.toml +0 -0
  181. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/token_transform/synthlang_/resources/frameworks/reflective_patterns.toml +0 -0
  182. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/token_transform/synthlang_/resources/frameworks/set_theory.toml +0 -0
  183. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/token_transform/synthlang_/resources/frameworks/topology_fundamentals.toml +0 -0
  184. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/token_transform/synthlang_/resources/mapping/lion_emoji_mapping.toml +0 -0
  185. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/token_transform/synthlang_/resources/mapping/python_math_mapping.toml +0 -0
  186. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/token_transform/synthlang_/resources/mapping/rust_chinese_mapping.toml +0 -0
  187. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/token_transform/synthlang_/resources/utility/base_synthlang_system_prompt.toml +0 -0
  188. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/token_transform/types.py +0 -0
  189. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/validate/__init__.py +0 -0
  190. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/validate/common_field_validators.py +0 -0
  191. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/validate/fuzzy_match_keys.py +0 -0
  192. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/validate/fuzzy_validate_mapping.py +0 -0
  193. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/validate/string_similarity.py +0 -0
  194. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/libs/validate/validate_boolean.py +0 -0
  195. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/models/__init__.py +0 -0
  196. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/models/field_model.py +0 -0
  197. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/models/hashable_model.py +0 -0
  198. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/models/model_params.py +0 -0
  199. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/models/note.py +0 -0
  200. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/models/operable_model.py +0 -0
  201. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/models/schema_model.py +0 -0
  202. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/ReAct/ReAct.py +0 -0
  203. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/ReAct/__init__.py +0 -0
  204. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/ReAct/utils.py +0 -0
  205. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/__init__.py +0 -0
  206. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/_act/__init__.py +0 -0
  207. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/_act/act.py +0 -0
  208. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/brainstorm/__init__.py +0 -0
  209. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/brainstorm/brainstorm.py +0 -0
  210. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/brainstorm/prompt.py +0 -0
  211. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/chat/__init__.py +0 -0
  212. {lionagi-0.12.3/lionagi/libs/token_transform → lionagi-0.12.5/lionagi/operations/communicate}/__init__.py +0 -0
  213. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/instruct/__init__.py +0 -0
  214. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/instruct/instruct.py +0 -0
  215. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/interpret/__init__.py +0 -0
  216. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/interpret/interpret.py +0 -0
  217. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/manager.py +0 -0
  218. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/operate/__init__.py +0 -0
  219. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/operate/operate.py +0 -0
  220. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/parse/__init__.py +0 -0
  221. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/plan/__init__.py +0 -0
  222. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/plan/plan.py +0 -0
  223. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/plan/prompt.py +0 -0
  224. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/select/__init__.py +0 -0
  225. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/select/select.py +0 -0
  226. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/select/utils.py +0 -0
  227. {lionagi-0.12.3/lionagi/operations/communicate → lionagi-0.12.5/lionagi/operations/translate}/__init__.py +0 -0
  228. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/translate/translate.py +0 -0
  229. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/types.py +0 -0
  230. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/operations/utils.py +0 -0
  231. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/__init__.py +0 -0
  232. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/_concepts.py +0 -0
  233. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/action/__init__.py +0 -0
  234. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/action/function_calling.py +0 -0
  235. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/action/manager.py +0 -0
  236. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/action/tool.py +0 -0
  237. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/forms/__init__.py +0 -0
  238. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/forms/base.py +0 -0
  239. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/forms/flow.py +0 -0
  240. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/forms/form.py +0 -0
  241. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/forms/report.py +0 -0
  242. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/generic/__init__.py +0 -0
  243. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/generic/element.py +0 -0
  244. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/generic/event.py +0 -0
  245. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/generic/log.py +0 -0
  246. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/generic/processor.py +0 -0
  247. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/generic/progression.py +0 -0
  248. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/graph/__init__.py +0 -0
  249. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/graph/edge.py +0 -0
  250. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/graph/graph.py +0 -0
  251. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/mail/__init__.py +0 -0
  252. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/mail/exchange.py +0 -0
  253. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/mail/mail.py +0 -0
  254. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/mail/mailbox.py +0 -0
  255. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/mail/manager.py +0 -0
  256. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/mail/package.py +0 -0
  257. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/messages/__init__.py +0 -0
  258. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/messages/action_request.py +0 -0
  259. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/messages/action_response.py +0 -0
  260. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/messages/base.py +0 -0
  261. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/messages/instruction.py +0 -0
  262. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/messages/manager.py +0 -0
  263. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/messages/message.py +0 -0
  264. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/messages/system.py +0 -0
  265. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/messages/templates/README.md +0 -0
  266. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/messages/templates/action_request.jinja2 +0 -0
  267. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/messages/templates/action_response.jinja2 +0 -0
  268. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/messages/templates/assistant_response.jinja2 +0 -0
  269. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/messages/templates/instruction_message.jinja2 +0 -0
  270. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/messages/templates/system_message.jinja2 +0 -0
  271. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/messages/templates/tool_schemas.jinja2 +0 -0
  272. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/operatives/__init__.py +0 -0
  273. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/operatives/operative.py +0 -0
  274. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/operatives/step.py +0 -0
  275. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/protocols/types.py +0 -0
  276. /lionagi-0.12.3/lionagi/operations/translate/__init__.py → /lionagi-0.12.5/lionagi/py.typed +0 -0
  277. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/service/__init__.py +0 -0
  278. {lionagi-0.12.3/lionagi/service/providers/exa_ → lionagi-0.12.5/lionagi/service/third_party}/__init__.py +0 -0
  279. {lionagi-0.12.3/lionagi/service/endpoints → lionagi-0.12.5/lionagi/service}/token_calculator.py +0 -0
  280. {lionagi-0.12.3/lionagi/service/endpoints → lionagi-0.12.5/lionagi/session}/__init__.py +0 -0
  281. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/session/prompts.py +0 -0
  282. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/session/session.py +0 -0
  283. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/settings.py +0 -0
  284. {lionagi-0.12.3/lionagi/service/providers → lionagi-0.12.5/lionagi/tools}/__init__.py +0 -0
  285. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/tools/base.py +0 -0
  286. {lionagi-0.12.3/lionagi/service/providers/anthropic_ → lionagi-0.12.5/lionagi/tools/file}/__init__.py +0 -0
  287. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/tools/types.py +0 -0
  288. {lionagi-0.12.3 → lionagi-0.12.5}/lionagi/utils.py +0 -0
  289. {lionagi-0.12.3 → lionagi-0.12.5}/main.py +0 -0
  290. {lionagi-0.12.3 → lionagi-0.12.5}/scripts/README.md +0 -0
  291. {lionagi-0.12.3 → lionagi-0.12.5}/scripts/concat.py +0 -0
  292. {lionagi-0.12.3 → lionagi-0.12.5}/scripts/config.py +0 -0
@@ -35,7 +35,7 @@ jobs:
35
35
  if: steps.cached-uv-dependencies.outputs.cache-hit != 'true'
36
36
  run: |
37
37
  uv venv
38
- uv build
38
+ uv sync --extra all
39
39
 
40
40
  - name: Run tests
41
41
  run: |
@@ -28,7 +28,7 @@ jobs:
28
28
  - name: Install dependencies
29
29
  run: |
30
30
  uv venv
31
- uv build
31
+ uv sync --extra all
32
32
 
33
33
  - name: Run tests
34
34
  run: |
@@ -3,6 +3,9 @@ __pycache__/
3
3
  *.py[cod]
4
4
  *$py.class
5
5
 
6
+ # Development notes
7
+ CLAUDE.md
8
+
6
9
  # Byte-compiled / optimized / DLL files
7
10
  __pycache__/
8
11
  *.py[cod]
@@ -170,4 +173,4 @@ cython_debug/
170
173
  .roomodes
171
174
  .khive/
172
175
  .roo/
173
- data/logs/
176
+ *logs/
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lionagi
3
- Version: 0.12.3
3
+ Version: 0.12.5
4
4
  Summary: An Intelligence Operating System.
5
5
  Author-email: HaiyangLi <quantocean.li@gmail.com>, Liangbingyan Luo <llby_luo@outlook.com>
6
6
  License: Apache License
@@ -220,19 +220,18 @@ Classifier: Programming Language :: Python :: 3.12
220
220
  Classifier: Programming Language :: Python :: 3.13
221
221
  Requires-Python: >=3.10
222
222
  Requires-Dist: aiocache>=0.12.0
223
- Requires-Dist: aiohttp>=3.10.0
224
- Requires-Dist: jinja2>=3.0.0
225
- Requires-Dist: pandas>=2.0.0
226
- Requires-Dist: pillow>=10.0.0
227
- Requires-Dist: pydantic>2.0.0
223
+ Requires-Dist: aiohttp>=3.12.0
224
+ Requires-Dist: backoff>=2.2.1
225
+ Requires-Dist: jinja2>=3.1.0
226
+ Requires-Dist: pillow>=11.0.0
227
+ Requires-Dist: pydantic-settings>=2.8.0
228
+ Requires-Dist: pydapter[pandas]>=0.3.0
228
229
  Requires-Dist: python-dotenv>=1.1.0
229
230
  Requires-Dist: tiktoken>=0.8.0
230
231
  Requires-Dist: toml>=0.9.0
231
232
  Provides-Extra: all
232
233
  Requires-Dist: docling>=2.15.1; extra == 'all'
233
- Requires-Dist: litellm>=1.59.5; extra == 'all'
234
- Requires-Dist: ollama>=0.4.7; extra == 'all'
235
- Requires-Dist: openai>=1.60.0; extra == 'all'
234
+ Requires-Dist: ollama>=0.5.0; extra == 'all'
236
235
  Provides-Extra: docs
237
236
  Requires-Dist: furo>=2024.8.6; extra == 'docs'
238
237
  Requires-Dist: sphinx-autobuild>=2024.10.3; extra == 'docs'
@@ -241,13 +240,12 @@ Provides-Extra: lint
241
240
  Requires-Dist: black[jupyter]>=24.10.0; extra == 'lint'
242
241
  Requires-Dist: isort>=5.13.2; extra == 'lint'
243
242
  Requires-Dist: pre-commit>=4.0.1; extra == 'lint'
244
- Provides-Extra: llms
245
- Requires-Dist: litellm>=1.59.5; extra == 'llms'
246
243
  Provides-Extra: ollama
247
- Requires-Dist: ollama>=0.4.7; extra == 'ollama'
248
- Requires-Dist: openai>=1.60.0; extra == 'ollama'
244
+ Requires-Dist: ollama>=0.5.0; extra == 'ollama'
245
+ Provides-Extra: reader
246
+ Requires-Dist: docling>=2.15.1; extra == 'reader'
249
247
  Provides-Extra: test
250
- Requires-Dist: pytest-asyncio>=0.25.0; extra == 'test'
248
+ Requires-Dist: pytest-asyncio>=1.0.0; extra == 'test'
251
249
  Requires-Dist: pytest>=8.3.4; extra == 'test'
252
250
  Provides-Extra: tools
253
251
  Requires-Dist: docling>=2.15.1; extra == 'tools'
@@ -285,9 +283,6 @@ integrations, and custom validations in a single coherent pipeline.
285
283
  pip install lionagi
286
284
  ```
287
285
 
288
- Dependencies: • aiocahce • aiohttp • jinja2 • pandas • pillow • pydantic
289
- • python-dotenv • tiktoken
290
-
291
286
  ## Quick Start
292
287
 
293
288
  ```python
@@ -339,6 +334,10 @@ With fiery claws, dragons hide their laughter flaws!
339
334
  LionAGI supports advanced multi-step reasoning with ReAct. Tools let the LLM
340
335
  invoke external actions:
341
336
 
337
+ ```
338
+ pip install "lionagi[reader]"
339
+ ```
340
+
342
341
  ```python
343
342
  from lionagi.tools.types import ReaderTool
344
343
 
@@ -393,8 +392,7 @@ Seamlessly route to different models in the same workflow.
393
392
  ### optional dependencies
394
393
 
395
394
  ```
396
- pip install "lionagi[tools]"
397
- pip install "lionagi[llms]"
395
+ pip install "lionagi[reader]"
398
396
  pip install "lionagi[ollama]"
399
397
  ```
400
398
 
@@ -30,9 +30,6 @@ integrations, and custom validations in a single coherent pipeline.
30
30
  pip install lionagi
31
31
  ```
32
32
 
33
- Dependencies: • aiocahce • aiohttp • jinja2 • pandas • pillow • pydantic
34
- • python-dotenv • tiktoken
35
-
36
33
  ## Quick Start
37
34
 
38
35
  ```python
@@ -84,6 +81,10 @@ With fiery claws, dragons hide their laughter flaws!
84
81
  LionAGI supports advanced multi-step reasoning with ReAct. Tools let the LLM
85
82
  invoke external actions:
86
83
 
84
+ ```
85
+ pip install "lionagi[reader]"
86
+ ```
87
+
87
88
  ```python
88
89
  from lionagi.tools.types import ReaderTool
89
90
 
@@ -138,8 +139,7 @@ Seamlessly route to different models in the same workflow.
138
139
  ### optional dependencies
139
140
 
140
141
  ```
141
- pip install "lionagi[tools]"
142
- pip install "lionagi[llms]"
142
+ pip install "lionagi[reader]"
143
143
  pip install "lionagi[ollama]"
144
144
  ```
145
145
 
@@ -0,0 +1,123 @@
1
+ # Copyright (c) 2025, HaiyangLi <quantocean.li at gmail dot com>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ from typing import Any, ClassVar
6
+
7
+ from pydantic import BaseModel, Field, SecretStr
8
+ from pydantic_settings import BaseSettings, SettingsConfigDict
9
+
10
+
11
+ class CacheConfig(BaseModel):
12
+ """Configuration for aiocache."""
13
+
14
+ ttl: int = 300
15
+ key: str | None = None
16
+ namespace: str | None = None
17
+ key_builder: Any = None
18
+ skip_cache_func: Any = lambda _: False
19
+ serializer: dict[str, Any] | None = None
20
+ plugins: Any = None
21
+ alias: str | None = None
22
+ noself: Any = lambda _: False
23
+
24
+ def as_kwargs(self) -> dict[str, Any]:
25
+ """Convert config to kwargs dict for @cached decorator.
26
+
27
+ Removes unserialisable callables that aiocache can't pickle.
28
+ """
29
+ raw = self.model_dump(exclude_none=True)
30
+ # Remove all unserialisable callables
31
+ unserialisable_keys = (
32
+ "key_builder",
33
+ "skip_cache_func",
34
+ "noself",
35
+ "serializer",
36
+ "plugins",
37
+ )
38
+ for key in unserialisable_keys:
39
+ raw.pop(key, None)
40
+ return raw
41
+
42
+
43
+ class AppSettings(BaseSettings, frozen=True):
44
+ """Application settings with environment variable support."""
45
+
46
+ model_config = SettingsConfigDict(
47
+ env_file=(".env", ".env.local", ".secrets.env"),
48
+ env_file_encoding="utf-8",
49
+ case_sensitive=False,
50
+ extra="ignore",
51
+ )
52
+
53
+ aiocache_config: CacheConfig = Field(
54
+ default_factory=CacheConfig, description="Cache settings for aiocache"
55
+ )
56
+
57
+ # secrets
58
+ OPENAI_API_KEY: SecretStr | None = None
59
+ OPENROUTER_API_KEY: SecretStr | None = None
60
+ OLLAMA_API_KEY: SecretStr | None = None
61
+ EXA_API_KEY: SecretStr | None = None
62
+ PERPLEXITY_API_KEY: SecretStr | None = None
63
+ GROQ_API_KEY: SecretStr | None = None
64
+ ANTHROPIC_API_KEY: SecretStr | None = None
65
+
66
+ # defaults models
67
+ LIONAGI_EMBEDDING_PROVIDER: str = "openai"
68
+ LIONAGI_EMBEDDING_MODEL: str = "text-embedding-3-small"
69
+
70
+ LIONAGI_CHAT_PROVIDER: str = "openai"
71
+ LIONAGI_CHAT_MODEL: str = "gpt-4o"
72
+
73
+ # default storage
74
+ LIONAGI_AUTO_STORE_EVENT: bool = False
75
+ LIONAGI_STORAGE_PROVIDER: str = "async_qdrant"
76
+
77
+ LIONAGI_AUTO_EMBED_LOG: bool = False
78
+
79
+ # specific storage
80
+ LIONAGI_QDRANT_URL: str = "http://localhost:6333"
81
+ LIONAGI_DEFAULT_QDRANT_COLLECTION: str = "event_logs"
82
+
83
+ # Class variable to store the singleton instance
84
+ _instance: ClassVar[Any] = None
85
+
86
+ def get_secret(self, key_name: str) -> str:
87
+ """
88
+ Get the secret value for a given key name.
89
+
90
+ Args:
91
+ key_name: The name of the secret key (e.g., "OPENAI_API_KEY")
92
+
93
+ Returns:
94
+ The secret value as a string
95
+
96
+ Raises:
97
+ AttributeError: If the key doesn't exist
98
+ ValueError: If the key exists but is None
99
+ """
100
+ if not hasattr(self, key_name):
101
+ if "ollama" in key_name.lower():
102
+ return "ollama"
103
+ raise AttributeError(
104
+ f"Secret key '{key_name}' not found in settings"
105
+ )
106
+
107
+ secret = getattr(self, key_name)
108
+ if secret is None:
109
+ # Special case for Ollama - return "ollama" even if key exists but is None
110
+ if "ollama" in key_name.lower():
111
+ return "ollama"
112
+ raise ValueError(f"Secret key '{key_name}' is not set")
113
+
114
+ if isinstance(secret, SecretStr):
115
+ return secret.get_secret_value()
116
+
117
+ return str(secret)
118
+
119
+
120
+ # Create a singleton instance
121
+ settings = AppSettings()
122
+ # Store the instance in the class variable for singleton pattern
123
+ AppSettings._instance = settings
@@ -0,0 +1,259 @@
1
+ # Copyright (c) 2025, HaiyangLi <quantocean.li at gmail dot com>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ import importlib.util
6
+ import json
7
+ import string
8
+ import tempfile
9
+ from pathlib import Path
10
+ from typing import Any, TypeVar
11
+
12
+ from pydantic import BaseModel, PydanticUserError
13
+
14
+ from lionagi.utils import is_import_installed
15
+
16
+ _HAS_DATAMODEL_CODE_GENERATOR = is_import_installed("datamodel-code-generator")
17
+
18
+ # Import at module level for easier mocking in tests
19
+ if _HAS_DATAMODEL_CODE_GENERATOR:
20
+ from datamodel_code_generator import (
21
+ DataModelType,
22
+ InputFileType,
23
+ PythonVersion,
24
+ generate,
25
+ )
26
+ else:
27
+ # Create dummy objects for when package is not installed
28
+ DataModelType = None
29
+ InputFileType = None
30
+ PythonVersion = None
31
+ generate = None
32
+
33
+
34
+ B = TypeVar("B", bound=BaseModel)
35
+
36
+
37
+ def load_pydantic_model_from_schema(
38
+ schema: str | dict[str, Any],
39
+ model_name: str = "DynamicModel",
40
+ /,
41
+ pydantic_version=None,
42
+ python_version=None,
43
+ ) -> type[BaseModel]:
44
+ """
45
+ Generates a Pydantic model class dynamically from a JSON schema string or dict,
46
+ and ensures it's fully resolved using model_rebuild() with the correct namespace.
47
+
48
+ Args:
49
+ schema: The JSON schema as a string or a Python dictionary.
50
+ model_name: The desired base name for the generated Pydantic model.
51
+ If the schema has a 'title', that will likely be used.
52
+ pydantic_version: The Pydantic model type to generate.
53
+ python_version: The target Python version for generated code syntax.
54
+
55
+ Returns:
56
+ The dynamically created and resolved Pydantic BaseModel class.
57
+
58
+ Raises:
59
+ ValueError: If the schema is invalid.
60
+ FileNotFoundError: If the generated model file is not found.
61
+ AttributeError: If the expected model class cannot be found.
62
+ RuntimeError: For errors during generation, loading, or rebuilding.
63
+ Exception: For other potential errors.
64
+ """
65
+ if not _HAS_DATAMODEL_CODE_GENERATOR:
66
+ error_msg = "`datamodel-code-generator` is not installed. Please install with `pip install datamodel-code-generator`."
67
+ raise ImportError(error_msg)
68
+
69
+ if DataModelType is not None:
70
+ pydantic_version = (
71
+ pydantic_version or DataModelType.PydanticV2BaseModel
72
+ )
73
+ python_version = python_version or PythonVersion.PY_312
74
+ else:
75
+ # These won't be used since we'll raise ImportError above
76
+ pydantic_version = None
77
+ python_version = None
78
+
79
+ schema_input_data: str
80
+ schema_dict: dict[str, Any]
81
+ resolved_model_name = (
82
+ model_name # Keep track of the potentially updated name
83
+ )
84
+
85
+ # --- 1. Prepare Schema Input ---
86
+ if isinstance(schema, dict):
87
+ try:
88
+ model_name_from_title = schema.get("title")
89
+ if model_name_from_title and isinstance(
90
+ model_name_from_title, str
91
+ ):
92
+ valid_chars = string.ascii_letters + string.digits + "_"
93
+ sanitized_title = "".join(
94
+ c
95
+ for c in model_name_from_title.replace(" ", "")
96
+ if c in valid_chars
97
+ )
98
+ if sanitized_title and sanitized_title[0].isalpha():
99
+ resolved_model_name = (
100
+ sanitized_title # Update the name to use
101
+ )
102
+ schema_dict = schema
103
+ schema_input_data = json.dumps(schema)
104
+ except TypeError as e:
105
+ error_msg = "Invalid dictionary provided for schema"
106
+ raise ValueError(error_msg) from e
107
+ elif isinstance(schema, str):
108
+ try:
109
+ schema_dict = json.loads(schema)
110
+ model_name_from_title = schema_dict.get("title")
111
+ if model_name_from_title and isinstance(
112
+ model_name_from_title, str
113
+ ):
114
+ valid_chars = string.ascii_letters + string.digits + "_"
115
+ sanitized_title = "".join(
116
+ c
117
+ for c in model_name_from_title.replace(" ", "")
118
+ if c in valid_chars
119
+ )
120
+ if sanitized_title and sanitized_title[0].isalpha():
121
+ resolved_model_name = (
122
+ sanitized_title # Update the name to use
123
+ )
124
+ schema_input_data = schema
125
+ except json.JSONDecodeError as e:
126
+ error_msg = "Invalid JSON schema string provided"
127
+ raise ValueError(error_msg) from e
128
+ else:
129
+ error_msg = "Schema must be a JSON string or a dictionary."
130
+ raise TypeError(error_msg)
131
+
132
+ # --- 2. Generate Code to Temporary File ---
133
+ with tempfile.TemporaryDirectory() as temporary_directory_name:
134
+ temporary_directory = Path(temporary_directory_name)
135
+ # Use a predictable but unique-ish filename
136
+ output_file = (
137
+ temporary_directory
138
+ / f"{resolved_model_name.lower()}_model_{hash(schema_input_data)}.py"
139
+ )
140
+ module_name = output_file.stem # e.g., "userprofile_model_12345"
141
+
142
+ try:
143
+ generate(
144
+ schema_input_data,
145
+ input_file_type=InputFileType.JsonSchema,
146
+ input_filename="schema.json",
147
+ output=output_file,
148
+ output_model_type=pydantic_version,
149
+ target_python_version=python_version,
150
+ # Ensure necessary base models are imported in the generated code
151
+ base_class="pydantic.BaseModel",
152
+ )
153
+ except Exception as e:
154
+ # Optional: Print generated code on failure for debugging
155
+ # if output_file.exists():
156
+ # print(f"--- Generated Code (Error) ---\n{output_file.read_text()}\n--------------------------")
157
+ error_msg = "Failed to generate model code"
158
+ raise RuntimeError(error_msg) from e
159
+
160
+ if not output_file.exists():
161
+ error_msg = f"Generated model file was not created: {output_file}"
162
+ raise FileNotFoundError(error_msg)
163
+
164
+ def get_modules():
165
+ spec = importlib.util.spec_from_file_location(
166
+ module_name, str(output_file)
167
+ )
168
+
169
+ if spec is None or spec.loader is None:
170
+ error_msg = f"Could not create module spec for {output_file}"
171
+ raise ImportError(error_msg)
172
+
173
+ return spec, importlib.util.module_from_spec(spec)
174
+
175
+ # --- 3. Import the Generated Module Dynamically ---
176
+ try:
177
+ spec, generated_module = get_modules()
178
+ # Important: Make pydantic available within the executed module's globals
179
+ # if it's not explicitly imported by the generated code for some reason.
180
+ # Usually, datamodel-code-generator handles imports well.
181
+ # generated_module.__dict__['BaseModel'] = BaseModel
182
+ spec.loader.exec_module(generated_module)
183
+
184
+ except Exception as e:
185
+ # Optional: Print generated code on failure for debugging
186
+ # print(f"--- Generated Code (Import Error) ---\n{output_file.read_text()}\n--------------------------")
187
+ error_msg = f"Failed to load generated module ({output_file})"
188
+ raise RuntimeError(error_msg) from e
189
+
190
+ def validate_base_model_class(m):
191
+ if not isinstance(m, type) or not issubclass(m, BaseModel):
192
+ error_msg = f"Found attribute '{resolved_model_name}' is not a Pydantic BaseModel class."
193
+ raise TypeError(error_msg)
194
+
195
+ # --- 4. Find the Model Class ---
196
+ model_class: type[BaseModel]
197
+ try:
198
+ # Use the name potentially derived from the schema title
199
+ model_class = getattr(generated_module, resolved_model_name)
200
+ validate_base_model_class(model_class)
201
+
202
+ except AttributeError:
203
+ # Fallback attempt (less likely now with title extraction)
204
+ try:
205
+ model_class = generated_module.Model # Default fallback name
206
+ validate_base_model_class(model_class)
207
+ print(
208
+ f"Warning: Model name '{resolved_model_name}' not found, falling back to 'Model'."
209
+ )
210
+ except AttributeError as e:
211
+ # List available Pydantic models found in the module for debugging
212
+ available_attrs = [
213
+ attr
214
+ for attr in dir(generated_module)
215
+ if isinstance(getattr(generated_module, attr, None), type)
216
+ and issubclass(
217
+ getattr(generated_module, attr, object), BaseModel
218
+ ) # Check inheritance safely
219
+ and getattr(generated_module, attr, None)
220
+ is not BaseModel # Exclude BaseModel itself
221
+ ]
222
+ # Optional: Print generated code on failure for debugging
223
+ # print(f"--- Generated Code (AttributeError) ---\n{output_file.read_text()}\n--------------------------")
224
+ error_msg = (
225
+ f"Could not find expected model class '{resolved_model_name}' or fallback 'Model' "
226
+ f"in the generated module {output_file}. "
227
+ f"Found Pydantic models: {available_attrs}"
228
+ )
229
+ raise AttributeError(error_msg) from e
230
+ except TypeError as e:
231
+ error_msg = (
232
+ f"Error validating found model class '{resolved_model_name}'"
233
+ )
234
+ raise TypeError(error_msg) from e
235
+
236
+ # --- 5. Rebuild the Model (Providing Namespace) ---
237
+ try:
238
+ # Pass the generated module's dictionary as the namespace
239
+ # for resolving type hints like 'Status', 'ProfileDetails', etc.
240
+ model_class.model_rebuild(
241
+ _types_namespace=generated_module.__dict__,
242
+ force=True, # Force rebuild even if Pydantic thinks it's okay
243
+ )
244
+ except (
245
+ PydanticUserError,
246
+ NameError,
247
+ ) as e: # Catch NameError explicitly here
248
+ # Optional: Print generated code on failure for debugging
249
+ # print(f"--- Generated Code (Rebuild Error) ---\n{output_file.read_text()}\n--------------------------")
250
+ error_msg = f"Error during model_rebuild for {resolved_model_name}"
251
+ raise RuntimeError(error_msg) from e
252
+ except Exception as e:
253
+ # Optional: Print generated code on failure for debugging
254
+ # print(f"--- Generated Code (Rebuild Error) ---\n{output_file.read_text()}\n--------------------------")
255
+ error_msg = f"Unexpected error during model_rebuild for {resolved_model_name}"
256
+ raise RuntimeError(error_msg) from e
257
+
258
+ # --- 6. Return the Resolved Model Class ---
259
+ return model_class
@@ -7,7 +7,7 @@ from pydantic import BaseModel
7
7
 
8
8
  from lionagi.protocols.generic.event import EventStatus
9
9
  from lionagi.protocols.generic.log import Log
10
- from lionagi.service.endpoints.base import APICalling
10
+ from lionagi.service.connections.api_calling import APICalling
11
11
  from lionagi.service.imodel import iModel
12
12
  from lionagi.utils import alcall, lcall, to_dict, to_list
13
13
 
@@ -208,9 +208,7 @@ class LLMCompressor:
208
208
  Tokenize text. If no custom tokenizer, use the default from lionagi.
209
209
  """
210
210
  if not self.tokenizer:
211
- from lionagi.service.endpoints.token_calculator import (
212
- TokenCalculator,
213
- )
211
+ from lionagi.service.token_calculator import TokenCalculator
214
212
 
215
213
  return TokenCalculator.tokenize(
216
214
  text,
@@ -93,7 +93,7 @@ async def translate_to_synthlang(
93
93
  else:
94
94
  branch = Branch(system=final_prompt, chat_model=chat_model)
95
95
 
96
- from lionagi.service.endpoints.token_calculator import TokenCalculator
96
+ from lionagi.service.token_calculator import TokenCalculator
97
97
 
98
98
  calculator = TokenCalculator()
99
99
 
@@ -122,8 +122,8 @@ async def chat(
122
122
  _msgs.append(i)
123
123
  messages = _msgs
124
124
 
125
- imodel = imodel or branch.chat_model
126
- if branch.msgs.system and imodel.sequential_exchange:
125
+ # All endpoints now assume sequential exchange (system message embedded in first user message)
126
+ if branch.msgs.system:
127
127
  messages = [msg for msg in messages if msg.role != "system"]
128
128
  first_instruction = None
129
129
 
@@ -91,12 +91,27 @@ async def communicate(
91
91
  return res.response
92
92
 
93
93
  if response_format is not None:
94
- return await branch.parse(
95
- text=res.response,
96
- request_type=response_format,
97
- max_retries=num_parse_retries,
94
+ # Default to raising errors unless explicitly set in fuzzy_match_kwargs
95
+ parse_kwargs = {
96
+ "handle_validation": "raise", # Default to raising errors
98
97
  **(fuzzy_match_kwargs or {}),
99
- )
98
+ }
99
+
100
+ try:
101
+ return await branch.parse(
102
+ text=res.response,
103
+ request_type=response_format,
104
+ max_retries=num_parse_retries,
105
+ **parse_kwargs,
106
+ )
107
+ except ValueError as e:
108
+ # Re-raise with more context
109
+ logging.error(
110
+ f"Failed to parse response '{res.response}' into {response_format}: {e}"
111
+ )
112
+ raise ValueError(
113
+ f"Failed to parse model response into {response_format.__name__}: {e}"
114
+ ) from e
100
115
 
101
116
  if request_fields is not None:
102
117
  _d = fuzzy_validate_mapping(