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
@@ -1,135 +0,0 @@
1
- # Copyright (c) 2023-2025, HaiyangLi <quantocean.li at gmail dot com>
2
- # SPDX-License-Identifier: Apache-2.0
3
-
4
- from typing import Any, ClassVar, Literal
5
-
6
- from pydantic import Field, JsonValue, field_validator
7
-
8
- from lionagi.libs.validate.common_field_validators import (
9
- validate_boolean_field,
10
- validate_nullable_jsonvalue_field,
11
- )
12
- from lionagi.models import FieldModel, HashableModel
13
-
14
- __all__ = (
15
- "Instruct",
16
- "InstructResponse",
17
- )
18
-
19
-
20
- class Instruct(HashableModel):
21
- """Model for defining instruction parameters and execution requirements.
22
-
23
- Attributes:
24
- instruction (JsonValue | None): The primary instruction.
25
- guidance (JsonValue | None): Execution guidance.
26
- context (JsonValue | None): Task context.
27
- """
28
-
29
- reserved_kwargs: ClassVar[list[str]] = [
30
- "operative_model",
31
- "field_models",
32
- "operative",
33
- "reason",
34
- "actions",
35
- "action_strategy",
36
- "request_params",
37
- "response_params",
38
- ]
39
- instruction: JsonValue | None = Field(
40
- None,
41
- title="Primary Instruction",
42
- description=(
43
- "A clear, actionable task definition. Specify:\n"
44
- "1) The primary goal or objective\n"
45
- "2) Key success criteria or constraints\n"
46
- "\n"
47
- "Guidelines:\n"
48
- "- Start with a direct action verb (e.g., 'Analyze', 'Generate', 'Create')\n"
49
- "- Include scope, boundaries, or constraints\n"
50
- "- Provide success criteria if relevant\n"
51
- "- For complex tasks, break them into logical steps"
52
- ),
53
- )
54
- guidance: JsonValue | None = Field(
55
- None,
56
- title="Guidance",
57
- description=(
58
- "Strategic direction and constraints for executing the task. "
59
- "Include:\n"
60
- "1) Preferred methods or frameworks\n"
61
- "2) Quality benchmarks (e.g., speed, clarity)\n"
62
- "3) Resource or environmental constraints\n"
63
- "4) Relevant compliance or standards\n"
64
- "Use None if no special guidance."
65
- ),
66
- )
67
- context: JsonValue | None = Field(
68
- None,
69
- description=(
70
- "Background information and current-state data needed for the task. "
71
- "Should be:\n"
72
- "1) Directly relevant\n"
73
- "2) Sufficient to perform the task\n"
74
- "3) Free of extraneous detail\n"
75
- "Include environment, prior outcomes, system states, or dependencies. "
76
- "Use None if no additional context is needed."
77
- ),
78
- )
79
- reason: bool | None = Field(
80
- None,
81
- description=(
82
- "Include a thoughtful explanation of decisions, trade-offs, "
83
- "and insights. Encourage deeper introspection on why certain "
84
- "choices were made, potential alternatives, and how confidence "
85
- "was shaped. If not needed, set to None."
86
- ),
87
- )
88
- actions: bool | None = Field(
89
- None,
90
- description=(
91
- "Controls execution mode. "
92
- "True: Execute specified actions. "
93
- "False: Analysis/recommendations only. "
94
- "None: Contextual execution."
95
- ),
96
- )
97
- action_strategy: Literal["sequential", "concurrent"] | None = Field(
98
- None,
99
- description="Action strategy to use for executing actions. Default "
100
- "is 'concurrent'. Only provide for if actions are enabled.",
101
- )
102
-
103
- @field_validator("instruction", "guidance", "context", mode="before")
104
- def _validate_instruction(cls, v):
105
- return validate_nullable_jsonvalue_field(cls, v)
106
-
107
- @field_validator("reason", "actions", mode="before")
108
- def _validate_reason(cls, v):
109
- return validate_boolean_field(cls, v)
110
-
111
- @field_validator("action_strategy", mode="before")
112
- def _validate_action_strategy(cls, v):
113
- if v not in ["batch", "sequential", "concurrent"]:
114
- return "concurrent"
115
- return v
116
-
117
-
118
- class InstructResponse(HashableModel):
119
- instruct: Instruct
120
- response: Any | None = None
121
-
122
-
123
- INSTRUCT_FIELD = FieldModel(
124
- name="instruct_model",
125
- annotation=Instruct | None,
126
- default=None,
127
- )
128
-
129
- LIST_INSTRUCT_FIELD_MODEL = FieldModel(
130
- name="instruct_models",
131
- annotation=list[Instruct] | None,
132
- default=None,
133
- )
134
-
135
- # File: lionagi/fields/instruct.py
lionagi/fields/reason.py DELETED
@@ -1,55 +0,0 @@
1
- # Copyright (c) 2023-2025, HaiyangLi <quantocean.li at gmail dot com>
2
- # SPDX-License-Identifier: Apache-2.0
3
-
4
- from pydantic import Field, field_validator
5
-
6
- from lionagi.libs.validate.to_num import to_num
7
- from lionagi.models import FieldModel, HashableModel
8
-
9
- __all__ = ("Reason",)
10
-
11
-
12
- class Reason(HashableModel):
13
- title: str | None = None
14
- content: str | None = None
15
- confidence_score: float | None = Field(
16
- None,
17
- title="Confidence Score",
18
- description=(
19
- "Numeric confidence score (0.0 to 1.0, up to three decimals) indicating "
20
- "how well you've met user expectations. Use this guide:\n"
21
- " • 1.0: Highly confident\n"
22
- " • 0.8-1.0: Reasonably sure\n"
23
- " • 0.5-0.8: Re-check, refine or backtrack\n"
24
- " • 0.0-0.5: Off track, stop"
25
- ),
26
- )
27
-
28
- @field_validator("confidence_score", mode="before")
29
- def _validate_confidence(cls, v):
30
- return validate_confidence_score(cls, v)
31
-
32
-
33
- def validate_confidence_score(cls, v):
34
- if v is None:
35
- return None
36
- try:
37
- return to_num(
38
- v,
39
- upper_bound=1,
40
- lower_bound=0,
41
- num_type=float,
42
- precision=3,
43
- )
44
- except Exception:
45
- return -1
46
-
47
-
48
- REASON_FIELD = FieldModel(
49
- name="reason",
50
- annotation=Reason | None,
51
- title="Reason",
52
- description="**Provide a concise reason for the decision made.**",
53
- )
54
-
55
- # File: lionagi/fields/reason.py
@@ -1,52 +0,0 @@
1
- # Copyright (c) 2023-2025, HaiyangLi <quantocean.li at gmail dot com>
2
- # SPDX-License-Identifier: Apache-2.0
3
-
4
- from pydantic import Field
5
-
6
- from lionagi.models import HashableModel
7
-
8
- from .base import CodeSnippet, TextSnippet
9
-
10
- __all__ = (
11
- "ResearchFinding",
12
- "PotentialRisk",
13
- "ResearchSummary",
14
- )
15
-
16
-
17
- class ResearchFinding(HashableModel):
18
- """
19
- A single piece of information or insight from the research phase.
20
- """
21
-
22
- summary: str | None = Field(
23
- None,
24
- description="Concise text describing the discovered fact, concept, or best practice.",
25
- )
26
- snippets: list[TextSnippet | CodeSnippet] = Field(
27
- default_factory=list,
28
- description="Ordered list of content snippets (text or code) that illustrate or support the finding.",
29
- )
30
- relevance: str | None = Field(
31
- default=None,
32
- description="Why this finding matters to the project. E.g., 'Helps solve concurrency issue.'",
33
- )
34
-
35
-
36
- class PotentialRisk(HashableModel):
37
- """
38
- Identifies a risk or challenge discovered during research.
39
- """
40
-
41
- description: str | None = Field(
42
- None,
43
- description="Short text describing the risk. E.g., 'Scalability concerns with chosen DB'.",
44
- )
45
- impact: str | None = Field(
46
- default=None,
47
- description="Possible consequences if not mitigated. E.g., 'System slowdown, possible downtime.'",
48
- )
49
- mitigation_ideas: str | None = Field(
50
- default=None,
51
- description="Preliminary ways to reduce or handle this risk.",
52
- )
@@ -1,86 +0,0 @@
1
- # Copyright (c) 2023-2025, HaiyangLi <quantocean.li at gmail dot com>
2
- # SPDX-License-Identifier: Apache-2.0
3
-
4
- import logging
5
- from typing import TYPE_CHECKING
6
-
7
- from pydantic import BaseModel
8
-
9
- from lionagi.fields.action import ActionResponseModel
10
- from lionagi.protocols.types import ActionRequest, Log
11
-
12
- if TYPE_CHECKING:
13
- from lionagi.session.branch import Branch
14
-
15
-
16
- async def _act(
17
- branch: "Branch",
18
- action_request: BaseModel | dict,
19
- suppress_errors: bool = False,
20
- verbose_action: bool = False,
21
- ) -> "ActionResponseModel":
22
- _request = {}
23
-
24
- if isinstance(action_request, BaseModel):
25
- if hasattr(action_request, "function") and hasattr(
26
- action_request, "arguments"
27
- ):
28
- _request["function"] = action_request.function
29
- _request["arguments"] = action_request.arguments
30
- elif isinstance(action_request, dict):
31
- if {"function", "arguments"} <= set(action_request.keys()):
32
- _request["function"] = action_request["function"]
33
- _request["arguments"] = action_request["arguments"]
34
-
35
- try:
36
- if verbose_action:
37
- args_ = str(_request["arguments"])
38
- args_ = args_[:50] + "..." if len(args_) > 50 else args_
39
- print(f"Invoking action {_request['function']} with {args_}.")
40
-
41
- func_call = await branch._action_manager.invoke(_request)
42
- if verbose_action:
43
- print(
44
- f"Action {_request['function']} invoked, status: {func_call.status}."
45
- )
46
-
47
- except Exception as e:
48
- content = {
49
- "error": str(e),
50
- "function": _request.get("function"),
51
- "arguments": _request.get("arguments"),
52
- "branch": str(branch.id),
53
- }
54
- branch._log_manager.log(Log(content=content))
55
- if verbose_action:
56
- print(f"Action {_request['function']} failed, error: {str(e)}.")
57
- if suppress_errors:
58
- logging.error(
59
- f"Error invoking action '{_request['function']}': {e}"
60
- )
61
- return None
62
- raise e
63
-
64
- branch._log_manager.log(Log.create(func_call))
65
-
66
- if not isinstance(action_request, ActionRequest):
67
- action_request = ActionRequest.create(
68
- sender=branch.id,
69
- recipient=func_call.func_tool.id,
70
- **_request,
71
- )
72
-
73
- # Add the action request/response to the message manager, if not present
74
- if action_request not in branch.messages:
75
- branch.msgs.add_message(action_request=action_request)
76
-
77
- branch.msgs.add_message(
78
- action_request=action_request,
79
- action_output=func_call.response,
80
- )
81
-
82
- return ActionResponseModel(
83
- function=action_request.function,
84
- arguments=action_request.arguments,
85
- output=func_call.response,
86
- )
@@ -1,2 +0,0 @@
1
- # Copyright (c) 2023-2025, HaiyangLi <quantocean.li at gmail dot com>
2
- # SPDX-License-Identifier: Apache-2.0