lionagi 0.17.11__py3-none-any.whl → 0.18.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 (109) hide show
  1. lionagi/_errors.py +0 -5
  2. lionagi/fields.py +83 -0
  3. lionagi/libs/schema/minimal_yaml.py +98 -0
  4. lionagi/ln/__init__.py +3 -1
  5. lionagi/ln/concurrency/primitives.py +4 -4
  6. lionagi/ln/concurrency/task.py +1 -0
  7. lionagi/ln/types.py +32 -5
  8. lionagi/models/field_model.py +21 -4
  9. lionagi/models/hashable_model.py +2 -3
  10. lionagi/operations/ReAct/ReAct.py +475 -238
  11. lionagi/operations/ReAct/utils.py +3 -0
  12. lionagi/operations/act/act.py +206 -0
  13. lionagi/operations/builder.py +5 -7
  14. lionagi/operations/chat/chat.py +130 -114
  15. lionagi/operations/communicate/communicate.py +101 -42
  16. lionagi/operations/fields.py +380 -0
  17. lionagi/operations/flow.py +8 -10
  18. lionagi/operations/interpret/interpret.py +65 -20
  19. lionagi/operations/node.py +4 -4
  20. lionagi/operations/operate/operate.py +216 -108
  21. lionagi/{protocols/operatives → operations/operate}/operative.py +4 -5
  22. lionagi/{protocols/operatives → operations/operate}/step.py +34 -39
  23. lionagi/operations/parse/parse.py +170 -142
  24. lionagi/operations/select/select.py +79 -18
  25. lionagi/operations/select/utils.py +8 -2
  26. lionagi/operations/types.py +119 -23
  27. lionagi/protocols/action/manager.py +5 -6
  28. lionagi/protocols/contracts.py +2 -2
  29. lionagi/protocols/generic/__init__.py +22 -0
  30. lionagi/protocols/generic/element.py +36 -127
  31. lionagi/protocols/generic/log.py +3 -2
  32. lionagi/protocols/generic/pile.py +9 -10
  33. lionagi/protocols/generic/progression.py +23 -22
  34. lionagi/protocols/graph/edge.py +6 -5
  35. lionagi/protocols/ids.py +6 -49
  36. lionagi/protocols/messages/__init__.py +29 -0
  37. lionagi/protocols/messages/action_request.py +86 -184
  38. lionagi/protocols/messages/action_response.py +73 -131
  39. lionagi/protocols/messages/assistant_response.py +130 -159
  40. lionagi/protocols/messages/base.py +31 -22
  41. lionagi/protocols/messages/instruction.py +280 -625
  42. lionagi/protocols/messages/manager.py +112 -62
  43. lionagi/protocols/messages/message.py +87 -197
  44. lionagi/protocols/messages/system.py +52 -123
  45. lionagi/protocols/types.py +1 -13
  46. lionagi/service/connections/__init__.py +3 -0
  47. lionagi/service/connections/endpoint.py +0 -8
  48. lionagi/service/connections/providers/claude_code_cli.py +3 -2
  49. lionagi/service/connections/providers/oai_.py +29 -94
  50. lionagi/service/connections/providers/ollama_.py +3 -2
  51. lionagi/service/hooks/_types.py +1 -1
  52. lionagi/service/hooks/_utils.py +1 -1
  53. lionagi/service/hooks/hook_event.py +3 -8
  54. lionagi/service/hooks/hook_registry.py +5 -5
  55. lionagi/service/hooks/hooked_event.py +63 -3
  56. lionagi/service/imodel.py +24 -20
  57. lionagi/service/third_party/claude_code.py +3 -3
  58. lionagi/service/third_party/openai_models.py +435 -0
  59. lionagi/service/token_calculator.py +1 -94
  60. lionagi/session/branch.py +190 -400
  61. lionagi/session/session.py +8 -99
  62. lionagi/tools/file/reader.py +2 -2
  63. lionagi/version.py +1 -1
  64. {lionagi-0.17.11.dist-info → lionagi-0.18.1.dist-info}/METADATA +6 -6
  65. lionagi-0.18.1.dist-info/RECORD +164 -0
  66. lionagi/fields/__init__.py +0 -47
  67. lionagi/fields/action.py +0 -188
  68. lionagi/fields/base.py +0 -153
  69. lionagi/fields/code.py +0 -239
  70. lionagi/fields/file.py +0 -234
  71. lionagi/fields/instruct.py +0 -135
  72. lionagi/fields/reason.py +0 -55
  73. lionagi/fields/research.py +0 -52
  74. lionagi/operations/_act/act.py +0 -86
  75. lionagi/operations/brainstorm/__init__.py +0 -2
  76. lionagi/operations/brainstorm/brainstorm.py +0 -498
  77. lionagi/operations/brainstorm/prompt.py +0 -11
  78. lionagi/operations/instruct/__init__.py +0 -2
  79. lionagi/operations/instruct/instruct.py +0 -28
  80. lionagi/operations/plan/__init__.py +0 -6
  81. lionagi/operations/plan/plan.py +0 -386
  82. lionagi/operations/plan/prompt.py +0 -25
  83. lionagi/operations/utils.py +0 -45
  84. lionagi/protocols/forms/__init__.py +0 -2
  85. lionagi/protocols/forms/base.py +0 -85
  86. lionagi/protocols/forms/flow.py +0 -79
  87. lionagi/protocols/forms/form.py +0 -86
  88. lionagi/protocols/forms/report.py +0 -48
  89. lionagi/protocols/mail/__init__.py +0 -2
  90. lionagi/protocols/mail/exchange.py +0 -220
  91. lionagi/protocols/mail/mail.py +0 -51
  92. lionagi/protocols/mail/mailbox.py +0 -103
  93. lionagi/protocols/mail/manager.py +0 -218
  94. lionagi/protocols/mail/package.py +0 -101
  95. lionagi/protocols/messages/templates/README.md +0 -28
  96. lionagi/protocols/messages/templates/action_request.jinja2 +0 -5
  97. lionagi/protocols/messages/templates/action_response.jinja2 +0 -9
  98. lionagi/protocols/messages/templates/assistant_response.jinja2 +0 -6
  99. lionagi/protocols/messages/templates/instruction_message.jinja2 +0 -61
  100. lionagi/protocols/messages/templates/system_message.jinja2 +0 -11
  101. lionagi/protocols/messages/templates/tool_schemas.jinja2 +0 -7
  102. lionagi/protocols/operatives/__init__.py +0 -2
  103. lionagi/service/connections/providers/types.py +0 -28
  104. lionagi/service/third_party/openai_model_names.py +0 -198
  105. lionagi/service/types.py +0 -58
  106. lionagi-0.17.11.dist-info/RECORD +0 -199
  107. /lionagi/operations/{_act → act}/__init__.py +0 -0
  108. {lionagi-0.17.11.dist-info → lionagi-0.18.1.dist-info}/WHEEL +0 -0
  109. {lionagi-0.17.11.dist-info → lionagi-0.18.1.dist-info}/licenses/LICENSE +0 -0
@@ -4,6 +4,7 @@
4
4
  import contextlib
5
5
  from collections.abc import Callable
6
6
  from typing import Any
7
+ from uuid import UUID
7
8
 
8
9
  from pydantic import (
9
10
  Field,
@@ -17,12 +18,7 @@ from typing_extensions import Self
17
18
  from lionagi.protocols.types import (
18
19
  ID,
19
20
  MESSAGE_FIELDS,
20
- Communicatable,
21
- Exchange,
22
21
  Graph,
23
- IDType,
24
- MailManager,
25
- MessageFlag,
26
22
  Node,
27
23
  Pile,
28
24
  Progression,
@@ -38,25 +34,19 @@ from ..service.imodel import iModel
38
34
  from .branch import ActionManager, Branch, OperationManager, Tool
39
35
 
40
36
 
41
- class Session(Node, Communicatable, Relational):
37
+ class Session(Node, Relational):
42
38
  """
43
- Manages multiple conversation branches and mail transfer in a session.
39
+ Manages multiple conversation branches in a session.
44
40
 
45
41
  Attributes:
46
42
  branches (Pile | None): Collection of conversation branches.
47
43
  default_branch (Branch | None): The default conversation branch.
48
- mail_transfer (Exchange | None): Mail transfer system.
49
- mail_manager (MailManager | None): Manages mail operations.
50
44
  """
51
45
 
52
46
  branches: Pile[Branch] = Field(
53
47
  default_factory=lambda: Pile(item_type={Branch}, strict_type=False)
54
48
  )
55
49
  default_branch: Any = Field(default=None, exclude=True)
56
- mail_transfer: Exchange = Field(default_factory=Exchange, exclude=True)
57
- mail_manager: MailManager = Field(
58
- default_factory=MailManager, exclude=True
59
- )
60
50
  name: str = Field(default="Session")
61
51
  user: SenderRecipient | None = None
62
52
  _operation_manager: OperationManager = PrivateAttr(
@@ -77,7 +67,6 @@ class Session(Node, Communicatable, Relational):
77
67
  def _take_in_branch(branch: Branch):
78
68
  if branch not in self.branches:
79
69
  self.branches.include(branch)
80
- self.mail_manager.add_sources(branch)
81
70
 
82
71
  branch.user = self.id
83
72
  branch._operation_manager = self._operation_manager
@@ -120,7 +109,7 @@ class Session(Node, Communicatable, Relational):
120
109
  return decorator
121
110
 
122
111
  @model_validator(mode="after")
123
- def _add_mail_sources(self) -> Self:
112
+ def _initialize_branches(self) -> Self:
124
113
  if self.default_branch is None:
125
114
  self.default_branch = Branch()
126
115
  if self.default_branch not in self.branches:
@@ -197,7 +186,6 @@ class Session(Node, Communicatable, Relational):
197
186
  branch: Branch = self.branches[branch]
198
187
 
199
188
  self.branches.exclude(branch)
200
- self.mail_manager.delete_source(branch.id)
201
189
 
202
190
  if self.default_branch.id == branch.id:
203
191
  if not self.branches:
@@ -273,17 +261,12 @@ class Session(Node, Communicatable, Relational):
273
261
  if any(i not in self.branches for i in branches):
274
262
  raise ValueError("Branch does not exist.")
275
263
 
276
- exclude_flag = []
277
- if exclude_clone:
278
- exclude_flag.append(MessageFlag.MESSAGE_CLONE)
279
- if exclude_load:
280
- exclude_flag.append(MessageFlag.MESSAGE_LOAD)
264
+ # Note: exclude_clone and exclude_load parameters are deprecated
265
+ # and currently have no effect. They are kept for API compatibility.
281
266
 
282
267
  messages = lcall(
283
268
  branches,
284
- lambda x: [
285
- i for i in self.branches[x].messages if i not in exclude_flag
286
- ],
269
+ lambda x: list(self.branches[x].messages),
287
270
  input_unique=True,
288
271
  input_flatten=True,
289
272
  input_dropna=True,
@@ -294,80 +277,6 @@ class Session(Node, Communicatable, Relational):
294
277
  collections=messages, item_type={RoledMessage}, strict_type=False
295
278
  )
296
279
 
297
- def send(self, to_: ID.RefSeq = None):
298
- """
299
- Send mail to specified branches.
300
-
301
- Args:
302
- to_: The branches to send mail to. If None, send to all.
303
-
304
- Raises:
305
- ValueError: If mail sending fails.
306
- """
307
- if to_ is None:
308
- self.mail_manager.send_all()
309
- else:
310
- try:
311
- lcall(
312
- to_,
313
- lambda x: self.mail_manager.send(ID.get_id(x)),
314
- input_unique=True,
315
- input_flatten=True,
316
- input_dropna=True,
317
- input_use_values=True,
318
- )
319
- except Exception as e:
320
- raise ValueError(f"Failed to send mail. Error: {e}")
321
-
322
- async def acollect_send_all(self, receive_all: bool = True):
323
- """
324
- Collect and send mail for all branches, optionally receiving all mail.
325
-
326
- Args:
327
- receive_all: If True, receive all mail for all branches.
328
- """
329
- async with self.mail_manager.sources:
330
- self.collect_send_all(receive_all)
331
-
332
- def collect_send_all(self, receive_all: bool = True):
333
- """
334
- Collect and send mail for all branches, optionally receiving all mail.
335
-
336
- Args:
337
- receive_all: If True, receive all mail for all branches.
338
- """
339
- self.collect()
340
- self.send()
341
- if receive_all:
342
- for i in self.branches:
343
- i.receive_all()
344
-
345
- def collect(self, from_: ID.RefSeq = None):
346
- """
347
- Collect mail from specified branches.
348
-
349
- Args:
350
- from_: The branches to collect mail from. If None, collect
351
- from all.
352
-
353
- Raises:
354
- ValueError: If mail collection fails.
355
- """
356
- if from_ is None:
357
- self.mail_manager.collect_all()
358
- else:
359
- try:
360
- lcall(
361
- from_,
362
- lambda x: self.mail_manager.collect(ID.get_id(x)),
363
- input_flatten=True,
364
- input_dropna=True,
365
- input_unique=True,
366
- input_use_values=True,
367
- )
368
- except Exception as e:
369
- raise ValueError(f"Failed to collect mail. Error: {e}")
370
-
371
280
  async def flow(
372
281
  self,
373
282
  graph: Graph,
@@ -401,7 +310,7 @@ class Session(Node, Communicatable, Relational):
401
310
 
402
311
  # Use specified branch or session's default
403
312
  branch = default_branch or self.default_branch
404
- if isinstance(branch, (str, IDType)):
313
+ if isinstance(branch, (str, UUID)):
405
314
  branch = self.branches[branch]
406
315
 
407
316
  return await flow(
@@ -79,8 +79,8 @@ class ReaderRequest(BaseModel):
79
79
  ),
80
80
  )
81
81
 
82
- recursive: bool = Field(
83
- False,
82
+ recursive: bool | None = Field(
83
+ None,
84
84
  description=(
85
85
  "Whether to recursively list files in subdirectories. Defaults to False."
86
86
  "Only used if action='list_dir'."
lionagi/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.17.11"
1
+ __version__ = "0.18.1"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lionagi
3
- Version: 0.17.11
3
+ Version: 0.18.1
4
4
  Summary: An Intelligence Operating System.
5
5
  Author-email: HaiyangLi <quantocean.li@gmail.com>
6
6
  License: Apache License
@@ -223,12 +223,11 @@ 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
230
229
  Requires-Dist: pydantic>=2.8.0
231
- Requires-Dist: pydapter[pandas]>=1.1.1
230
+ Requires-Dist: pydapter[pandas]>=1.2.0
232
231
  Requires-Dist: python-dotenv>=1.1.0
233
232
  Requires-Dist: tiktoken>=0.9.0
234
233
  Provides-Extra: all
@@ -241,6 +240,7 @@ Requires-Dist: networkx>=3.0.0; extra == 'all'
241
240
  Requires-Dist: ollama>=0.4.0; extra == 'all'
242
241
  Requires-Dist: pydapter[postgres]; extra == 'all'
243
242
  Requires-Dist: rich>=13.0.0; extra == 'all'
243
+ Requires-Dist: xmltodict>=0.12.0; extra == 'all'
244
244
  Provides-Extra: graph
245
245
  Requires-Dist: matplotlib>=3.7.0; extra == 'graph'
246
246
  Requires-Dist: networkx>=3.0.0; extra == 'graph'
@@ -466,13 +466,13 @@ from lionagi.fields import LIST_INSTRUCT_FIELD_MODEL, Instruct
466
466
  response3 = await orchestrator.operate(
467
467
  instruct=Instruct(
468
468
  instruction="create 4 research questions for parallel discovery",
469
- guidance="put into `instruct_models` field as part of your structured result message",
469
+ guidance="put into `instruct_model` field as part of your structured result message",
470
470
  context="I'd like to create an orchestration system for AI agents using lionagi"
471
471
  ),
472
472
  field_models=[LIST_INSTRUCT_FIELD_MODEL],
473
473
  )
474
474
 
475
- len(response3.instruct_models) # should be 4
475
+ len(response3.instruct_model) # should be 4
476
476
 
477
477
  async def handle_instruct(instruct):
478
478
  sub_branch = Branch(
@@ -483,7 +483,7 @@ async def handle_instruct(instruct):
483
483
 
484
484
  # run in parallel across all instruct models
485
485
  from lionagi.ln import alcall
486
- responses = await alcall(response3.instruct_models, handle_instruct)
486
+ responses = await alcall(response3.instruct_model, handle_instruct)
487
487
 
488
488
  # now hand these reports back to the orchestrator
489
489
  final_response = await orchestrator.communicate(
@@ -0,0 +1,164 @@
1
+ lionagi/__init__.py,sha256=JJlMMYTLN1B9OradguqKL-HdWec5X0jqc2laoqhSdbQ,2470
2
+ lionagi/_class_registry.py,sha256=vp3YkOelyv9azuQFfhGN_9N_n5fAKAY2MtpSLeNpjW0,3108
3
+ lionagi/_errors.py,sha256=QRiBlcArmdJbXbt0fku5LfpPFeK3It9dFsPE-vyikNE,3692
4
+ lionagi/_types.py,sha256=nGtsaSee7FaIZvym3PH8NPaN5PN8QscTgcZfpMNaMEo,1296
5
+ lionagi/config.py,sha256=meBzsT7xYDh1FwxGz_Q-XfOw3XkxPtlSJ1vqx9xk5YE,4779
6
+ lionagi/fields.py,sha256=r7r4-3nSvBBRuArztgOTn2zpNBmkQvZvf63IJeeW5_k,2036
7
+ lionagi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ lionagi/utils.py,sha256=j4wRrPiuHprx7l7j3z8U9NlPWMzrM8lHv5q3K_DJLPU,7080
9
+ lionagi/version.py,sha256=i8LHPc0qiYueFP9CAFrtufkGZfMfDAhFNqWW_Pa8HsI,23
10
+ lionagi/adapters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ lionagi/adapters/_utils.py,sha256=sniMG1LDDkwJNzUF2K32jv7rA6Y1QcohgyNclYsptzI,453
12
+ lionagi/adapters/async_postgres_adapter.py,sha256=-7Ah0A8JQvEEYBe2zMkze-65gYiUbpcJGxhYnzrv9ok,3285
13
+ lionagi/libs/__init__.py,sha256=ySvN2mEd6TEvCVCDGfBS9H_cSrZQ21WomjRC8Herm0Y,108
14
+ lionagi/libs/file/__init__.py,sha256=ySvN2mEd6TEvCVCDGfBS9H_cSrZQ21WomjRC8Herm0Y,108
15
+ lionagi/libs/file/chunk.py,sha256=_wHdZY9OCDILWWwWOvvS22T9CYGV9bW1zRUi96-UqDg,8970
16
+ lionagi/libs/file/process.py,sha256=A0dF2HZEZHRBNPKboKTlQBh03Rn0tHC_dRaQYMphOhE,6074
17
+ lionagi/libs/schema/__init__.py,sha256=ySvN2mEd6TEvCVCDGfBS9H_cSrZQ21WomjRC8Herm0Y,108
18
+ lionagi/libs/schema/as_readable.py,sha256=LeiZ4bXCZfmkfJvdduets2s50XS4hgUvn3Ay2xYdVr4,12023
19
+ lionagi/libs/schema/breakdown_pydantic_annotation.py,sha256=x-mfXroICPHXtNcLtAoC_SyFwao42dEaEAUZA9l3yWQ,1296
20
+ lionagi/libs/schema/extract_code_block.py,sha256=ZaDucwumx2rBE3AwWb4EDMeYO7Mb2IJFLlYvOan6-fM,2390
21
+ lionagi/libs/schema/extract_docstring.py,sha256=T_wiQfprlJniKNCeKuCxf_Oj7_6Pj_8HJ02ZjB3LelI,5710
22
+ lionagi/libs/schema/function_to_schema.py,sha256=uRMkpjXYgmL8kxdyVfOSTB-i0dRAbztSZPHI1LilRH8,5600
23
+ lionagi/libs/schema/load_pydantic_model_from_schema.py,sha256=IWPKhF_drI3VKABon45ufkiIb5hRYTS0sGWxhQLObpI,10112
24
+ lionagi/libs/schema/minimal_yaml.py,sha256=fj3LFn35o_KpFostcCYpJ6pQMrb1DICqIgxpnWriQRg,3085
25
+ lionagi/libs/validate/__init__.py,sha256=ySvN2mEd6TEvCVCDGfBS9H_cSrZQ21WomjRC8Herm0Y,108
26
+ lionagi/libs/validate/common_field_validators.py,sha256=9PUabJZVFGeXShOOZ5jliRaXLefBovACllynAQCU0Ow,4774
27
+ lionagi/libs/validate/to_num.py,sha256=ZRHDjpTCykPfDIZZa4rZKNaR_8ZHbPDFlw9rc02DrII,11610
28
+ lionagi/libs/validate/validate_boolean.py,sha256=WcszKSMksFBCels2OMd0qElqDauyq53-h7cuOM_nIKU,3610
29
+ lionagi/ln/__init__.py,sha256=rehWx09QyfPJrl4go_aEdvuW8sSBp_aYPq9mCSoq1Gk,1641
30
+ lionagi/ln/_async_call.py,sha256=hjei0sW-G92xDwQo_OI4qKVp1iP8N2eccJT1fAftV9w,9607
31
+ lionagi/ln/_hash.py,sha256=dIrQgOAdrWkVQcaCJXN-XIaA1sIZSYtAU302fywrtJU,4756
32
+ lionagi/ln/_json_dump.py,sha256=zOeoOE3JbaGAzL-lfAdMqdgaXWYXFliqcgXsZ_pxonI,10347
33
+ lionagi/ln/_list_call.py,sha256=zvISmCeNAH7yjBcusQI1s17n556tILgePhRMdAM2plA,2831
34
+ lionagi/ln/_to_list.py,sha256=V9hC3dpyMhRJwuuyOCU_wJygzEB6sJVZ0fmIRtM6uTg,6993
35
+ lionagi/ln/_utils.py,sha256=5Z_AsDxdtH5wNB-P4IiihhH0dYUcZMT-hTxFQBQPwL0,4303
36
+ lionagi/ln/types.py,sha256=vUprqqW1nfHDNrOGk417NHEeEXpTpJqP9eqlMuEOaBI,11118
37
+ lionagi/ln/concurrency/__init__.py,sha256=xt_GLZ1Zb-nC-RnrNt8jOBWb_uf1md__B1R5cplMShg,1190
38
+ lionagi/ln/concurrency/_compat.py,sha256=itxdRzl95PLEBQvNY0zTriF39kymaNRpKncT8QsOomA,2065
39
+ lionagi/ln/concurrency/cancel.py,sha256=8JlWy_EVto4Fls1yQLBteCbpn4zP6ydnqIa_EL5kxZc,3313
40
+ lionagi/ln/concurrency/errors.py,sha256=Tg76ods-CG_9rz7TksTiRGqpTzWHi-Wm9JPotGB9iEM,869
41
+ lionagi/ln/concurrency/patterns.py,sha256=08eebVxbBxkcMFgJqZB-cXS7lRZduH1Y-zorb8fTTZs,9447
42
+ lionagi/ln/concurrency/primitives.py,sha256=Elda6PSD_AwllvvmNYxNXE3E3oGMUjOnOwSYs3FKQag,9552
43
+ lionagi/ln/concurrency/resource_tracker.py,sha256=ffLr0FkHyaHsUa4UDyWwse-8wGLaLMnAyfyeTDyzrDA,1512
44
+ lionagi/ln/concurrency/task.py,sha256=LSRCKrcjA5QVNlFFRfyCrzPGWw9efBaHoJtHxKEbjCU,2692
45
+ lionagi/ln/concurrency/utils.py,sha256=MUWupnFtWxR15hWnligLZrS4Z1SAQ7j3cuCG08cK3GQ,431
46
+ lionagi/ln/fuzzy/__init__.py,sha256=Py7hPV7uk5rPRGvQ4yPjMzXS32aQ7QVkO-mX69FfsMM,544
47
+ lionagi/ln/fuzzy/_extract_json.py,sha256=rYHaK36yzRpie8qO-T7mZKOue2yqCLx3ixiuKhsaKvg,2224
48
+ lionagi/ln/fuzzy/_fuzzy_json.py,sha256=S0lCkNvprn7XZHoYdRfzXueexSbjxTeLPkpyJ9IAO3A,3860
49
+ lionagi/ln/fuzzy/_fuzzy_match.py,sha256=-rmYVjPtiAYaUAacQfhSwahVqQP03FBpfZrGFH7Zq98,5832
50
+ lionagi/ln/fuzzy/_fuzzy_validate.py,sha256=XuafNXflTerQrQYV0S6MrQHR3_6DuYBv6BAYTLSxgfI,5161
51
+ lionagi/ln/fuzzy/_string_similarity.py,sha256=01u73Bp4YPN-s7YMzQjbYM5d6mjKGSjJpar14Wab_5U,8792
52
+ lionagi/ln/fuzzy/_to_dict.py,sha256=Crz4sDIIcTZS3idxynWK7U4EdHvZooPDJIsOH3t6xgQ,12068
53
+ lionagi/models/__init__.py,sha256=Nq0RqoT7DXrpS1_lVgfrlZXl2_E2_E_HHANcbPlDfh8,418
54
+ lionagi/models/field_model.py,sha256=TgdkUTvVm50xf91auwbT2l257KGpHqP5P59jYQzl-Q0,29801
55
+ lionagi/models/hashable_model.py,sha256=U2Cw9dSdkX0PjyBY2kZ1UwvL_Rd69sVX4wA6nO_o1UQ,3242
56
+ lionagi/models/model_params.py,sha256=ZFknRIm1Qj-gBTNG1_jz7mjmoogXd2NpFObYPK42OK4,12110
57
+ lionagi/models/operable_model.py,sha256=t6EKeJzG4wqo4tHroPe873R_hMLpcWq4gUiwCC_8pcM,20175
58
+ lionagi/models/schema_model.py,sha256=atgySn8e3zcQdFDERMrfSS1ZKzRZjQCAlNNlnp22vIg,663
59
+ lionagi/operations/__init__.py,sha256=A9GvZqRuzxV98wrwo0-Y2bOTpz0TTPePHDTOj0cYR9Y,440
60
+ lionagi/operations/_visualize_graph.py,sha256=F0KadgRthP-6-R-FPgvlwiiaiWH3ueO-rjSd1bzRUbE,8594
61
+ lionagi/operations/builder.py,sha256=aGbXLe1Gfji59ZUWc0wM4NCYBbZv0wwki0AT7B7sHZs,14654
62
+ lionagi/operations/fields.py,sha256=dEbQUUOutT6DLMqNyVOfUsuhGvWJsXPoMEQtXhMNv3c,12274
63
+ lionagi/operations/flow.py,sha256=v7E9_ybTGnOE3kKMoYIgkNqxMp9_SUHHTGNQQQuswrc,25014
64
+ lionagi/operations/manager.py,sha256=YZr3VjPAZVVFd_bIjF1aoQqzzKZHNA1kcqefNi5QFFM,683
65
+ lionagi/operations/node.py,sha256=XjnsuqXgYxN6Kj5UvNdjdOWQs4rW2iGAanhNocmHuj0,3437
66
+ lionagi/operations/types.py,sha256=yX2N589BAHxCHNm_dtoEd5eIvsp9HoStmAmpdHn8Epw,3935
67
+ lionagi/operations/ReAct/ReAct.py,sha256=zgGo806jwFvDDw9r-e4Q60ERpsIUf1a6D6vPp6QJubM,20671
68
+ lionagi/operations/ReAct/__init__.py,sha256=ySvN2mEd6TEvCVCDGfBS9H_cSrZQ21WomjRC8Herm0Y,108
69
+ lionagi/operations/ReAct/utils.py,sha256=YzKZaqD_Yb016grdx7hqSR2irM-idY9-FgCjgp9zffg,4300
70
+ lionagi/operations/act/__init__.py,sha256=ySvN2mEd6TEvCVCDGfBS9H_cSrZQ21WomjRC8Herm0Y,108
71
+ lionagi/operations/act/act.py,sha256=LfcfXUdj2PuaQnqvGq71IRTUW-YWHyp6dsOKlPCzLN8,6449
72
+ lionagi/operations/chat/__init__.py,sha256=ySvN2mEd6TEvCVCDGfBS9H_cSrZQ21WomjRC8Herm0Y,108
73
+ lionagi/operations/chat/chat.py,sha256=j21Zxdc_pkuFskT6HH2rXgh6fkvbwqp4C77L7xfWs9Y,6667
74
+ lionagi/operations/communicate/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
75
+ lionagi/operations/communicate/communicate.py,sha256=zQ-15MwJmw6sic0HdOBl8EJvVUBOThj5bu55Stg9YdA,5569
76
+ lionagi/operations/interpret/__init__.py,sha256=ySvN2mEd6TEvCVCDGfBS9H_cSrZQ21WomjRC8Herm0Y,108
77
+ lionagi/operations/interpret/interpret.py,sha256=uVK9Yk4-n92DZfEQrNQ-IU7PJd_IfVJWJENbmVCf_Ns,2497
78
+ lionagi/operations/operate/__init__.py,sha256=ySvN2mEd6TEvCVCDGfBS9H_cSrZQ21WomjRC8Herm0Y,108
79
+ lionagi/operations/operate/operate.py,sha256=hjCODeSv0hft9tXjnDy0bsYXijYelJxsLG9wYQJbPWE,10340
80
+ lionagi/operations/operate/operative.py,sha256=nswc7mhZLJES_5m6tfYEUofAICZz1uf2PIR8KzUA09c,14330
81
+ lionagi/operations/operate/step.py,sha256=vzNSOyXXj4w5F0d-dmCCUC2GxG1ToEddhiOSKUeyC24,9103
82
+ lionagi/operations/parse/__init__.py,sha256=ySvN2mEd6TEvCVCDGfBS9H_cSrZQ21WomjRC8Herm0Y,108
83
+ lionagi/operations/parse/parse.py,sha256=LwQoKNbkADSnhkrwMZeOPlTFAjsKC1QmnorbtKsdNX8,6699
84
+ lionagi/operations/select/__init__.py,sha256=ySvN2mEd6TEvCVCDGfBS9H_cSrZQ21WomjRC8Herm0Y,108
85
+ lionagi/operations/select/select.py,sha256=a5goZp0DYiTkCUDh3hg8j0Ef2S653KpKTkhVV9CpKsc,4440
86
+ lionagi/operations/select/utils.py,sha256=R8_neCZMVfC_8reLw3YCbpbbAWexSphXw4bo3UCryug,3834
87
+ lionagi/protocols/__init__.py,sha256=ySvN2mEd6TEvCVCDGfBS9H_cSrZQ21WomjRC8Herm0Y,108
88
+ lionagi/protocols/_concepts.py,sha256=eheWQxlHTo36uGpkSpINLO-OmTdjpJEFrVX1hJ7N590,1551
89
+ lionagi/protocols/contracts.py,sha256=ZHPDy0GIu_V9MsiSNcJ4Nzs2GWbAJN3H-_FTivplE7w,1390
90
+ lionagi/protocols/ids.py,sha256=bhuXt_-_8C6w3lLmKSzKmulQ0Om5W6bzIyrilT7A4W8,1025
91
+ lionagi/protocols/types.py,sha256=fpBjcOt9_cuH1BK-4qeu7_E77OHFs6nxxmJpIjjJdX8,2130
92
+ lionagi/protocols/action/__init__.py,sha256=ySvN2mEd6TEvCVCDGfBS9H_cSrZQ21WomjRC8Herm0Y,108
93
+ lionagi/protocols/action/function_calling.py,sha256=Qu5wCBGZk-c0D-rKMF8nYI3mzJGphosLWi7NCySSErY,4534
94
+ lionagi/protocols/action/manager.py,sha256=xKN1RV-ugUToFN5Xh6vQXlSyMk6BcxaTMONRDDOD99o,19971
95
+ lionagi/protocols/action/tool.py,sha256=A4WNMUkR05ivE_2bruSfgVKSgpP9iKSgIpLBp3C1Q6Q,5846
96
+ lionagi/protocols/generic/__init__.py,sha256=5SI1sSwWsYTkCgSSQI19xxFo6-UHvynIYGwPozz64ZM,551
97
+ lionagi/protocols/generic/element.py,sha256=6nZQYUWfhhPrzBk82-WTwQgETAkaEu-eTe6WlqitjTk,11889
98
+ lionagi/protocols/generic/event.py,sha256=oTDHFZeLTlX_olNN-6IFAVUU0bAlxn7nBOi5mu5kMnY,6546
99
+ lionagi/protocols/generic/log.py,sha256=flAk8NrYQN6yfY9w0D8y2Q-MIpESUK-1XaQCLnYtJ_I,8393
100
+ lionagi/protocols/generic/pile.py,sha256=A8h6BQOluCBy8bKJ8Mgkj2FL9yWfCwz_bHCYa1K7i38,37111
101
+ lionagi/protocols/generic/processor.py,sha256=e4s9pf0yjx-VIGN0uYnJ48TKDVpc_O_98_L-0hwawEk,11701
102
+ lionagi/protocols/generic/progression.py,sha256=yWwulINX4zNYC2NS1UunqryzS3femIM0it0EvTVcQN8,15207
103
+ lionagi/protocols/graph/__init__.py,sha256=oHHzwu1ystmRqn6MMaZ0emiscmw09v7doL_-QaJN2Z4,249
104
+ lionagi/protocols/graph/edge.py,sha256=tHGdvGrp525G82CM22_MoRJLDY9DIy2pXXf5K9_HLmE,5243
105
+ lionagi/protocols/graph/graph.py,sha256=_zGQ6ypCYVyDuTBTMAR2dXtI8niOwX_vbgXEQM4YPvo,11155
106
+ lionagi/protocols/graph/node.py,sha256=e9LDNDGJoqp0l6WwVLrv_87ll00_5FxqBpj3hg6NPLg,5301
107
+ lionagi/protocols/messages/__init__.py,sha256=Hw0n1uQPvn8aGymZoJLku8fS0sC2vLrYOagizMvxm5U,976
108
+ lionagi/protocols/messages/action_request.py,sha256=VDmdxxKYJhSOE0oui8mNIPpVb3mmA_46Db_Xo8twV_I,3588
109
+ lionagi/protocols/messages/action_response.py,sha256=AioBkMKzBworwk7LtlxWZR7rQB6nrvEsjNGTk_v1XYQ,2989
110
+ lionagi/protocols/messages/assistant_response.py,sha256=jv1svk_pk4sc_AslHMDn7CtIAFCM5aKmaiPbqNyD4Ds,6071
111
+ lionagi/protocols/messages/base.py,sha256=xWDX2kpJZmH7NVfzuNZ_9jGVdy3UNZ80ivth45l_Y9Y,2640
112
+ lionagi/protocols/messages/instruction.py,sha256=GC3PCTthQPJwFkQYqQF1CmijnhhLsE6G1gr6Lgw38JQ,11800
113
+ lionagi/protocols/messages/manager.py,sha256=ZbQ1VfphbS7ddr4SHmnSqLTo8lnZ4Vtl8pKL8xnLPD0,18900
114
+ lionagi/protocols/messages/message.py,sha256=tgy_drcKB-CbAqFaKi6oQkhBPFuBQYREZU8DqQTz2BE,4457
115
+ lionagi/protocols/messages/system.py,sha256=A9RqcNUUCFq6GcGBvMpv7Y6R4igFt1sER9sZMXyyFWg,2380
116
+ lionagi/service/__init__.py,sha256=MYcfEFFLSdRS4blwYdx883T8Px2bn81JAeqSIPW9SFs,2545
117
+ lionagi/service/broadcaster.py,sha256=XvaUaBb6awcq-DJGVNJnnAIZUrrtOPnhWcgVgZTnGq8,1941
118
+ lionagi/service/imodel.py,sha256=GhptwsEMN4QORa3ePntCs-HkkcYuphehOWXlJzCUSPc,16626
119
+ lionagi/service/manager.py,sha256=ZQWj_QKYsKVblsNHeDBMMQllduMArjLqaZHlP3F1_tE,1160
120
+ lionagi/service/rate_limited_processor.py,sha256=D983_04YqurcA-svjDKXVzmlD1bWoVkFHtwqQhB-fGo,6095
121
+ lionagi/service/resilience.py,sha256=djIDMJHe2XHoULa3x0wygt3kjeMgElSmWf0RFeyD3SU,18717
122
+ lionagi/service/token_calculator.py,sha256=MW3ekSppvMcVlTU37RIU4SIkiVUfYxeE6TMiT4gIsGw,3723
123
+ lionagi/service/connections/__init__.py,sha256=5laA2kcjSmblSjjK7Qor6EMSFqh_G6iMkmx-Tt3XvuY,441
124
+ lionagi/service/connections/api_calling.py,sha256=8NpgyFzz9oU6lTXq_gBetaqH_M6RnOoxIg4rbcS1Jco,6003
125
+ lionagi/service/connections/endpoint.py,sha256=T4JKy-fQ9_LFDpaTP0SEzUFIlfnhlnMJFcEb-qgThVg,14833
126
+ lionagi/service/connections/endpoint_config.py,sha256=L-DQdxVLBA8ZapVSvLhjmlo0pP1199aRA8lccquGoHI,5172
127
+ lionagi/service/connections/header_factory.py,sha256=vwVV3jNHIUePvUzbcC5Sj7yDoxB2yVSyLZxgBm-kNjg,1824
128
+ lionagi/service/connections/match_endpoint.py,sha256=cOPdoEgOpvFE2iJ24zqGJ51fB6s20qg4-RDjTI_bx-0,2571
129
+ lionagi/service/connections/mcp/__init__.py,sha256=ySvN2mEd6TEvCVCDGfBS9H_cSrZQ21WomjRC8Herm0Y,108
130
+ lionagi/service/connections/mcp/wrapper.py,sha256=EDbAm9gj4_zGBRdXf9yS0ZpyMNLfkEuDV2zo_YRt9QA,9161
131
+ lionagi/service/connections/providers/__init__.py,sha256=ySvN2mEd6TEvCVCDGfBS9H_cSrZQ21WomjRC8Herm0Y,108
132
+ lionagi/service/connections/providers/anthropic_.py,sha256=7xShtS2Whg-F2DpueSyI0X3ZknqTYeDXi1AvkEDQOBc,3160
133
+ lionagi/service/connections/providers/claude_code_cli.py,sha256=jSTD7Gaz1-EBAVL5mClmpcN3UmdAGb7hto4HRLfUPFs,4485
134
+ lionagi/service/connections/providers/exa_.py,sha256=p2mVkuztpHuS4Ud2dR082dPPEiVp6MFUXlehU9fD9lc,1051
135
+ lionagi/service/connections/providers/nvidia_nim_.py,sha256=S1Z8XhL7W5uANiNTkHK_ffeBL3_lD9KuthI70NSd_4g,2412
136
+ lionagi/service/connections/providers/oai_.py,sha256=vXYecSAHkMONpbFoVivldBbyPlU2y8pWKYY-LiXzsBE,4289
137
+ lionagi/service/connections/providers/ollama_.py,sha256=Y1e8dR7uDOxnCI45f9qvPh4NtVUd0qDppohNb-g6tQM,4564
138
+ lionagi/service/connections/providers/perplexity_.py,sha256=9eXYXsGQuDy8WdEbZ3Och9qDl-lZTBmocMo9-FsTIeE,1649
139
+ lionagi/service/hooks/__init__.py,sha256=toX-rQji-pxglI4yKzu-0Xp7E4xVvh0__Z70G_Gz2Y0,469
140
+ lionagi/service/hooks/_types.py,sha256=zu3bJ-Lt-R24E5LWWkqXOBENJL3fLidfAVI_wY2YWYI,1263
141
+ lionagi/service/hooks/_utils.py,sha256=vkyiXaeNV98F8hDSORJ3DxqPyIpykbhrXXCyGe-BsV0,2629
142
+ lionagi/service/hooks/hook_event.py,sha256=7Yx-Xcl75RlX_SbffgVissPAzYVNb7xckm0642egtck,2719
143
+ lionagi/service/hooks/hook_registry.py,sha256=hHW1l4mGUPh8HASaSZ_CSYUdtn5j904_wyO9RuFEYpE,8535
144
+ lionagi/service/hooks/hooked_event.py,sha256=8lRCGZ9htRZL9JOV9fHIRB1rCHrMwW0YgLReQ7-5dtU,6947
145
+ lionagi/service/third_party/README.md,sha256=qFjWnI8rmLivIyr6Tc-hRZh-rQwntROp76af4MBNJJc,2214
146
+ lionagi/service/third_party/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
147
+ lionagi/service/third_party/anthropic_models.py,sha256=8Ioc2YjQkHIwsqrnzbfyXAADIIPpP21mPDhx7XkGpRo,4022
148
+ lionagi/service/third_party/claude_code.py,sha256=t3sSsiiXCJA7qciAj3Ct80i0meaKiWJwZ47t-WlPCoU,23795
149
+ lionagi/service/third_party/exa_models.py,sha256=G_hnekcy-DillPLzMoDQ8ZisVAL8Mp7iMAK4xqAT_3w,5470
150
+ lionagi/service/third_party/openai_models.py,sha256=HDIZ1llg26aLYPmyqYUep7xtWw2e3Ws-7ebvtHZKqT4,11405
151
+ lionagi/service/third_party/pplx_models.py,sha256=-EhyJgOWR6rzSv3zczUtk80X6c19p18Dg9KC6l8BFRQ,6473
152
+ lionagi/session/__init__.py,sha256=KqR6ZzF0JZmPxa0Yb5Ocm88MTMQR1alhlm00QTbHOvA,198
153
+ lionagi/session/branch.py,sha256=maymM9n8H21CXrhScbHEfEKA2nNciEXvvc5FeeUh6Es,52647
154
+ lionagi/session/prompts.py,sha256=GPr0jibyAAqS3awDzGC8SoCL6aWJLLCCbXY0JUuxOC0,3170
155
+ lionagi/session/session.py,sha256=mpG6QGPuzi4U9VUNctg_hAlnyMr8QPVyi_HPqxn7jdw,10044
156
+ lionagi/tools/__init__.py,sha256=ySvN2mEd6TEvCVCDGfBS9H_cSrZQ21WomjRC8Herm0Y,108
157
+ lionagi/tools/base.py,sha256=ypzT7-XPGW_KzIAAGwlzwRx594zcIPoBqW_WqAozwo4,1893
158
+ lionagi/tools/types.py,sha256=HD3lkxKFFxVKPgxVLOerJ-VNxQiXA0Cw2TrlxEEBQWU,226
159
+ lionagi/tools/file/__init__.py,sha256=ySvN2mEd6TEvCVCDGfBS9H_cSrZQ21WomjRC8Herm0Y,108
160
+ lionagi/tools/file/reader.py,sha256=JCKDyOcKv07Iee8oJls8y5Qg0_PefnfqsIp_FiZQrsQ,9660
161
+ lionagi-0.18.1.dist-info/METADATA,sha256=yAExwFITt_CsBqzPe-G8L71lNOX-z2QJ2kJqQVTZVP8,23462
162
+ lionagi-0.18.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
163
+ lionagi-0.18.1.dist-info/licenses/LICENSE,sha256=VXFWsdoN5AAknBCgFqQNgPWYx7OPp-PFEP961zGdOjc,11288
164
+ lionagi-0.18.1.dist-info/RECORD,,
@@ -1,47 +0,0 @@
1
- from .action import (
2
- ACTION_REQUESTS_FIELD,
3
- ACTION_REQUIRED_FIELD,
4
- ACTION_RESPONSES_FIELD,
5
- ActionRequestModel,
6
- ActionResponseModel,
7
- )
8
- from .base import (
9
- CodeSnippet,
10
- Outline,
11
- OutlineItem,
12
- Section,
13
- Source,
14
- TextSnippet,
15
- )
16
- from .file import Documentation, File, Module, ResearchSummary
17
- from .instruct import (
18
- INSTRUCT_FIELD,
19
- LIST_INSTRUCT_FIELD_MODEL,
20
- Instruct,
21
- InstructResponse,
22
- )
23
- from .reason import REASON_FIELD, Reason
24
-
25
- __all__ = (
26
- "ActionRequestModel",
27
- "ActionResponseModel",
28
- "Source",
29
- "TextSnippet",
30
- "CodeSnippet",
31
- "Section",
32
- "OutlineItem",
33
- "Outline",
34
- "File",
35
- "Module",
36
- "ResearchSummary",
37
- "Documentation",
38
- "Instruct",
39
- "InstructResponse",
40
- "Reason",
41
- "LIST_INSTRUCT_FIELD_MODEL",
42
- "INSTRUCT_FIELD",
43
- "ACTION_REQUESTS_FIELD",
44
- "ACTION_RESPONSES_FIELD",
45
- "ACTION_REQUIRED_FIELD",
46
- "REASON_FIELD",
47
- )
lionagi/fields/action.py DELETED
@@ -1,188 +0,0 @@
1
- # Copyright (c) 2023-2025, HaiyangLi <quantocean.li at gmail dot com>
2
- # SPDX-License-Identifier: Apache-2.0
3
-
4
- import re
5
- from typing import Any
6
-
7
- from pydantic import BaseModel, Field, field_validator
8
-
9
- from lionagi.libs.validate.common_field_validators import (
10
- validate_boolean_field,
11
- validate_nullable_string_field,
12
- )
13
- from lionagi.ln import extract_json, to_dict, to_list
14
- from lionagi.models import FieldModel, HashableModel
15
-
16
- __all__ = (
17
- "ActionRequestModel",
18
- "ActionResponseModel",
19
- )
20
-
21
-
22
- def parse_action_request(content: str | dict) -> list[dict]:
23
- json_blocks = []
24
-
25
- if isinstance(content, BaseModel):
26
- json_blocks = [content.model_dump()]
27
-
28
- elif isinstance(content, str):
29
- json_blocks = extract_json(content, fuzzy_parse=True)
30
- if not json_blocks:
31
- pattern2 = r"```python\s*(.*?)\s*```"
32
- _d = re.findall(pattern2, content, re.DOTALL)
33
- json_blocks = [
34
- extract_json(match, fuzzy_parse=True) for match in _d
35
- ]
36
- json_blocks = to_list(json_blocks, dropna=True)
37
-
38
- print(json_blocks)
39
-
40
- elif content and isinstance(content, dict):
41
- json_blocks = [content]
42
-
43
- if json_blocks and not isinstance(json_blocks, list):
44
- json_blocks = [json_blocks]
45
-
46
- out = []
47
-
48
- for i in json_blocks:
49
- j = {}
50
- if isinstance(i, dict):
51
- if "function" in i and isinstance(i["function"], dict):
52
- if "name" in i["function"]:
53
- i["function"] = i["function"]["name"]
54
- for k, v in i.items():
55
- k = (
56
- k.replace("action_", "")
57
- .replace("recipient_", "")
58
- .replace("s", "")
59
- )
60
- if k in ["name", "function", "recipient"]:
61
- j["function"] = v
62
- elif k in ["parameter", "argument", "arg", "param"]:
63
- j["arguments"] = to_dict(
64
- v, str_type="json", fuzzy_parse=True, suppress=True
65
- )
66
- if (
67
- j
68
- and all(key in j for key in ["function", "arguments"])
69
- and j["arguments"]
70
- ):
71
- out.append(j)
72
-
73
- return out
74
-
75
-
76
- class ActionRequestModel(HashableModel):
77
- """
78
- Captures a single action request, typically from a user or system message.
79
- Includes the name of the function and the arguments to be passed.
80
- """
81
-
82
- function: str | None = Field(
83
- None,
84
- title="Function",
85
- description=(
86
- "Name of the function to call from the provided `tool_schemas`. "
87
- "If no `tool_schemas` exist, set to None or leave blank. "
88
- "Never invent new function names outside what's given."
89
- ),
90
- examples=["multiply", "create_user"],
91
- )
92
- arguments: dict[str, Any] | None = Field(
93
- None,
94
- title="Arguments",
95
- description=(
96
- "Dictionary of arguments for the chosen function. "
97
- "Use only argument names/types defined in `tool_schemas`. "
98
- "Never introduce extra argument names."
99
- ),
100
- )
101
-
102
- @field_validator("arguments", mode="before")
103
- def validate_arguments(cls, value: Any) -> dict[str, Any]:
104
- """
105
- Coerce arguments into a dictionary if possible, recursively.
106
-
107
- Raises:
108
- ValueError if the data can't be coerced.
109
- """
110
- return to_dict(
111
- value,
112
- fuzzy_parse=True,
113
- recursive=True,
114
- recursive_python_only=False,
115
- )
116
-
117
- @field_validator("function", mode="before")
118
- def validate_function(cls, value: str) -> str:
119
- """
120
- Ensure the function name is a valid non-empty string (if provided).
121
- """
122
- return validate_nullable_string_field(cls, value, "function", False)
123
-
124
- @classmethod
125
- def create(cls, content: str):
126
- """
127
- Attempt to parse a string (usually from a conversation or JSON) into
128
- one or more ActionRequestModel instances.
129
-
130
- If no valid structure is found, returns an empty list.
131
- """
132
- try:
133
- content = parse_action_request(content)
134
- if content:
135
- return [cls.model_validate(i) for i in content]
136
- return []
137
- except Exception:
138
- return []
139
-
140
-
141
- ACTION_REQUESTS_FIELD = FieldModel(
142
- name="action_requests",
143
- annotation=list[ActionRequestModel],
144
- default_factory=list,
145
- title="Actions",
146
- description=(
147
- "List of actions to be executed when `action_required` is true. "
148
- "Each action must align with the available `tool_schemas`. "
149
- "Leave empty if no actions are needed."
150
- ),
151
- )
152
-
153
-
154
- class ActionResponseModel(HashableModel):
155
- """
156
- Encapsulates a function's output after being called. Typically
157
- references the original function name, arguments, and the result.
158
- """
159
-
160
- function: str = Field(default_factory=str, title="Function")
161
- arguments: dict[str, Any] = Field(default_factory=dict)
162
- output: Any = None
163
-
164
-
165
- ACTION_RESPONSES_FIELD = FieldModel(
166
- name="action_responses",
167
- annotation=list[ActionResponseModel],
168
- default_factory=list,
169
- title="Actions",
170
- description="**do not fill**",
171
- )
172
-
173
-
174
- ACTION_REQUIRED_FIELD = FieldModel(
175
- name="action_required",
176
- annotation=bool,
177
- default=False,
178
- title="Action Required",
179
- description=(
180
- "Whether this step strictly requires performing actions. "
181
- "If true, the requests in `action_requests` must be fulfilled, "
182
- "assuming `tool_schemas` are available. "
183
- "If false or no `tool_schemas` exist, actions are optional."
184
- ),
185
- validator=lambda cls, v: validate_boolean_field(cls, v, False),
186
- validator_kwargs={"mode": "before"},
187
- )
188
- # File: lionagi/libs/fields/action.py