lionagi 0.18.0__py3-none-any.whl → 0.18.2__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 (93) hide show
  1. lionagi/__init__.py +102 -59
  2. lionagi/_errors.py +0 -5
  3. lionagi/adapters/spec_adapters/__init__.py +9 -0
  4. lionagi/adapters/spec_adapters/_protocol.py +236 -0
  5. lionagi/adapters/spec_adapters/pydantic_field.py +158 -0
  6. lionagi/fields.py +83 -0
  7. lionagi/ln/__init__.py +3 -1
  8. lionagi/ln/_async_call.py +2 -2
  9. lionagi/ln/concurrency/primitives.py +4 -4
  10. lionagi/ln/concurrency/task.py +1 -0
  11. lionagi/ln/fuzzy/_fuzzy_match.py +2 -2
  12. lionagi/ln/types/__init__.py +51 -0
  13. lionagi/ln/types/_sentinel.py +154 -0
  14. lionagi/ln/{types.py → types/base.py} +108 -168
  15. lionagi/ln/types/operable.py +221 -0
  16. lionagi/ln/types/spec.py +441 -0
  17. lionagi/models/field_model.py +69 -7
  18. lionagi/models/hashable_model.py +2 -3
  19. lionagi/models/model_params.py +4 -3
  20. lionagi/operations/ReAct/ReAct.py +1 -1
  21. lionagi/operations/act/act.py +3 -3
  22. lionagi/operations/builder.py +5 -7
  23. lionagi/operations/fields.py +380 -0
  24. lionagi/operations/flow.py +4 -6
  25. lionagi/operations/node.py +4 -4
  26. lionagi/operations/operate/operate.py +123 -89
  27. lionagi/operations/operate/operative.py +198 -0
  28. lionagi/operations/operate/step.py +203 -0
  29. lionagi/operations/select/select.py +1 -1
  30. lionagi/operations/select/utils.py +7 -1
  31. lionagi/operations/types.py +7 -7
  32. lionagi/protocols/action/manager.py +5 -6
  33. lionagi/protocols/contracts.py +2 -2
  34. lionagi/protocols/generic/__init__.py +22 -0
  35. lionagi/protocols/generic/element.py +36 -127
  36. lionagi/protocols/generic/pile.py +9 -10
  37. lionagi/protocols/generic/progression.py +23 -22
  38. lionagi/protocols/graph/edge.py +6 -5
  39. lionagi/protocols/ids.py +6 -49
  40. lionagi/protocols/messages/__init__.py +3 -1
  41. lionagi/protocols/messages/base.py +7 -6
  42. lionagi/protocols/messages/instruction.py +0 -1
  43. lionagi/protocols/messages/message.py +2 -2
  44. lionagi/protocols/types.py +1 -11
  45. lionagi/service/connections/__init__.py +3 -0
  46. lionagi/service/connections/providers/claude_code_cli.py +3 -2
  47. lionagi/service/hooks/_types.py +1 -1
  48. lionagi/service/hooks/_utils.py +1 -1
  49. lionagi/service/hooks/hook_event.py +3 -8
  50. lionagi/service/hooks/hook_registry.py +5 -5
  51. lionagi/service/hooks/hooked_event.py +61 -1
  52. lionagi/service/imodel.py +24 -20
  53. lionagi/service/third_party/claude_code.py +1 -2
  54. lionagi/service/third_party/openai_models.py +24 -22
  55. lionagi/service/token_calculator.py +1 -94
  56. lionagi/session/branch.py +26 -228
  57. lionagi/session/session.py +5 -90
  58. lionagi/version.py +1 -1
  59. {lionagi-0.18.0.dist-info → lionagi-0.18.2.dist-info}/METADATA +6 -5
  60. {lionagi-0.18.0.dist-info → lionagi-0.18.2.dist-info}/RECORD +62 -82
  61. lionagi/fields/__init__.py +0 -47
  62. lionagi/fields/action.py +0 -188
  63. lionagi/fields/base.py +0 -153
  64. lionagi/fields/code.py +0 -239
  65. lionagi/fields/file.py +0 -234
  66. lionagi/fields/instruct.py +0 -135
  67. lionagi/fields/reason.py +0 -55
  68. lionagi/fields/research.py +0 -52
  69. lionagi/operations/brainstorm/__init__.py +0 -2
  70. lionagi/operations/brainstorm/brainstorm.py +0 -498
  71. lionagi/operations/brainstorm/prompt.py +0 -11
  72. lionagi/operations/instruct/__init__.py +0 -2
  73. lionagi/operations/instruct/instruct.py +0 -28
  74. lionagi/operations/plan/__init__.py +0 -6
  75. lionagi/operations/plan/plan.py +0 -386
  76. lionagi/operations/plan/prompt.py +0 -25
  77. lionagi/operations/utils.py +0 -45
  78. lionagi/protocols/forms/__init__.py +0 -2
  79. lionagi/protocols/forms/base.py +0 -85
  80. lionagi/protocols/forms/flow.py +0 -79
  81. lionagi/protocols/forms/form.py +0 -86
  82. lionagi/protocols/forms/report.py +0 -48
  83. lionagi/protocols/mail/__init__.py +0 -2
  84. lionagi/protocols/mail/exchange.py +0 -220
  85. lionagi/protocols/mail/mail.py +0 -51
  86. lionagi/protocols/mail/mailbox.py +0 -103
  87. lionagi/protocols/mail/manager.py +0 -218
  88. lionagi/protocols/mail/package.py +0 -101
  89. lionagi/protocols/operatives/__init__.py +0 -2
  90. lionagi/protocols/operatives/operative.py +0 -362
  91. lionagi/protocols/operatives/step.py +0 -227
  92. {lionagi-0.18.0.dist-info → lionagi-0.18.2.dist-info}/WHEEL +0 -0
  93. {lionagi-0.18.0.dist-info → lionagi-0.18.2.dist-info}/licenses/LICENSE +0 -0
lionagi/fields/code.py DELETED
@@ -1,239 +0,0 @@
1
- # Copyright (c) 2023-2025, HaiyangLi <quantocean.li at gmail dot com>
2
- # SPDX-License-Identifier: Apache-2.0
3
-
4
- from enum import Enum
5
-
6
- from pydantic import Field
7
-
8
- from lionagi.models import HashableModel
9
-
10
- __all__ = (
11
- "ParameterKind",
12
- "Parameter",
13
- "Decorator",
14
- "Import",
15
- "Attribute",
16
- "Function",
17
- "Method",
18
- "Class",
19
- "Module",
20
- )
21
-
22
-
23
- class ParameterKind(str, Enum):
24
- """
25
- Distinguishes how a function/method parameter is used.
26
- Primarily inspired by Python's param categories, but can be ignored by simpler languages.
27
- Pay attention to the languege's own conventions for parameter handling.
28
- """
29
-
30
- POSITIONAL_ONLY = "positional_only" # E.g. Python's '/'-based params
31
- POSITIONAL_OR_KEYWORD = "positional_or_keyword" # Default for many
32
- VAR_POSITIONAL = "var_positional" # *args-like
33
- KEYWORD_ONLY = "keyword_only" # Python's '*' marker
34
- VAR_KEYWORD = "var_keyword" # **kwargs-like
35
-
36
-
37
- class Parameter(HashableModel):
38
- """
39
- Represents one parameter in a function or method signature.
40
- """
41
-
42
- name: str = Field(
43
- ...,
44
- description="Exact identifier for the parameter (e.g., 'user_id', 'self', 'arg').",
45
- )
46
- type: str | None = Field(
47
- default=None,
48
- description=(
49
- "Type annotation as a string (e.g., 'str', 'int', 'SomeClass'). None if untyped or not declared."
50
- ),
51
- )
52
- default_value_repr: str | None = Field(
53
- default=None,
54
- description=(
55
- "String representation of default value if present (e.g., 'None', '10', '\"hi\"'). "
56
- "None if parameter is required with no default."
57
- ),
58
- )
59
- kind: ParameterKind = Field(
60
- default=ParameterKind.POSITIONAL_OR_KEYWORD,
61
- description=(
62
- "Parameter's calling convention category. 'positional_or_keyword' is typical if unspecified."
63
- ),
64
- )
65
-
66
-
67
- class Decorator(HashableModel):
68
- """
69
- A decorator or annotation attached to a function, class, or method.
70
- Common in Python (@deco), Java (@Override), .NET ([Attribute]), etc.
71
- """
72
-
73
- name: str = Field(
74
- ...,
75
- description="Decorator/annotation name (e.g., '@staticmethod', '[ApiController]', '@Override').",
76
- )
77
- arguments_repr: list[str] | None = Field(
78
- default=None,
79
- description=(
80
- "If this decorator/annotation is called with arguments, provide them as a list of string expressions "
81
- "(e.g., `['\"/home\"', 'methods=[\"GET\"]']`). None if no arguments."
82
- ),
83
- )
84
-
85
-
86
- class Import(HashableModel):
87
- """
88
- Represents an import/using/include statement. Merges Python's 'import X' and 'from Y import Z' logic.
89
- Other languages can interpret accordingly.
90
- """
91
-
92
- module: str | None = Field(
93
- default=None,
94
- description=(
95
- "The module/package/namespace from which symbols are imported (e.g., 'os.path', 'java.util'). "
96
- "None for a direct import statement like 'import X' if no sub-path is specified."
97
- ),
98
- )
99
- name: str = Field(
100
- ...,
101
- description=(
102
- "The symbol or module being imported (e.g., 'os', 'List', 'time', '*')."
103
- ),
104
- )
105
- alias: str | None = Field(
106
- default=None,
107
- description="Alias name if used ('import X as Y'), else None.",
108
- )
109
- level: int = Field(
110
- default=0,
111
- description=(
112
- "For Pythonic relative imports. Number of leading dots. 0 if absolute or not applicable."
113
- ),
114
- )
115
-
116
-
117
- class Attribute(HashableModel):
118
- """
119
- A variable/constant/field at class or module level. Possibly static/final, with an initial value.
120
- """
121
-
122
- name: str = Field(
123
- ...,
124
- description="Identifier for this attribute/field (e.g., 'MAX_CONNECTIONS', 'version').",
125
- )
126
- type: str | None = Field(
127
- default=None,
128
- description="String type annotation if declared. None if untyped.",
129
- )
130
- initial_value_repr: str | None = Field(
131
- default=None,
132
- description="String representation of any initial value (e.g., '100', 'true', 'None'). None if uninitialized.",
133
- )
134
- is_static: bool = Field(
135
- default=False,
136
- description="True if this is a static (class-level) attribute. Otherwise instance-level or module-level.",
137
- )
138
- is_final: bool = Field(
139
- default=False,
140
- description="True if this attribute/field is read-only/const/final after initialization.",
141
- )
142
- visibility: str | None = Field(
143
- default=None,
144
- description="Optional access modifier (e.g., 'public', 'private', 'protected'). None if default or not applicable.",
145
- )
146
-
147
-
148
- class Function(HashableModel):
149
- """
150
- Represents a standalone function or procedure.
151
- For methods (attached to classes), see 'Method' below.
152
- """
153
-
154
- name: str = Field(
155
- ..., description="Function name identifier (e.g., 'process_data')."
156
- )
157
- parameters: list[Parameter] = Field(
158
- default_factory=list,
159
- description="Ordered list of Parameter objects for this function.",
160
- )
161
- return_type: str | None = Field(
162
- default=None,
163
- description="Return type string if declared. None if not declared or no explicit type.",
164
- )
165
- is_async: bool = Field(
166
- default=False,
167
- description="True if an 'async' function in languages that support it. Else False.",
168
- )
169
- docstring: str | None = Field(
170
- default=None,
171
- description="Documentation string or comment describing this function.",
172
- )
173
- decorators: list[Decorator] = Field(
174
- default_factory=list,
175
- description="List of decorators/annotations on this function (e.g., @staticmethod).",
176
- )
177
-
178
-
179
- class Method(Function):
180
- """
181
- A function bound to a class, including potential method-specific flags (static, abstract, etc.).
182
- Inherits fields from 'Function.'
183
- """
184
-
185
- is_static: bool = Field(
186
- default=False,
187
- description="True if method is static (no instance or 'self' needed).",
188
- )
189
- is_classmethod: bool = Field(
190
- default=False,
191
- description="True if method is recognized as a class method (receives class as first arg).",
192
- )
193
- is_abstract: bool = Field(
194
- default=False,
195
- description="True if the method is abstract (no concrete implementation).",
196
- )
197
- visibility: str | None = Field(
198
- default=None,
199
- description="Access level like 'public', 'private', etc., if relevant to the language.",
200
- )
201
-
202
-
203
- class Class(HashableModel):
204
- """
205
- Represents a class, interface, or other composite type, with optional docstring, attributes, methods, etc.
206
- """
207
-
208
- name: str = Field(
209
- ...,
210
- description="Class/struct/interface name (e.g., 'UserRepository', 'MyDataClass').",
211
- )
212
- base_types: list[str] = Field(
213
- default_factory=list,
214
- description="List of parent classes or interfaces by name. Empty if none.",
215
- )
216
- is_abstract: bool = Field(
217
- default=False,
218
- description="True if this is an abstract class (cannot be instantiated directly).",
219
- )
220
- is_interface: bool = Field(
221
- default=False,
222
- description="True if this represents an interface definition rather than a concrete class.",
223
- )
224
- docstring: str | None = Field(
225
- default=None,
226
- description="Documentation for the class/interface, if any.",
227
- )
228
- decorators: list[Decorator] = Field(
229
- default_factory=list,
230
- description="Class-level decorators/annotations (e.g., @dataclass).",
231
- )
232
- attributes: list[Attribute] = Field(
233
- default_factory=list,
234
- description="Fields or properties declared at class level.",
235
- )
236
- methods: list[Method] = Field(
237
- default_factory=list,
238
- description="List of Method objects representing this class's methods.",
239
- )
lionagi/fields/file.py DELETED
@@ -1,234 +0,0 @@
1
- # Copyright (c) 2023-2025, HaiyangLi <quantocean.li at gmail dot com>
2
- # SPDX-License-Identifier: Apache-2.0
3
-
4
- from abc import abstractmethod
5
- from pathlib import Path
6
-
7
- from pydantic import Field, field_validator
8
-
9
- from .base import HashableModel, Source
10
- from .code import Class, Function, Import
11
- from .research import PotentialRisk, ResearchFinding
12
-
13
- __all__ = (
14
- "File",
15
- "Documentation",
16
- "ResearchSummary",
17
- "Module",
18
- )
19
-
20
-
21
- class File(HashableModel):
22
- """
23
- Represents a generic file with an optional name, content, and brief
24
- description. Useful for capturing and validating metadata about any
25
- kind of file within a project.
26
- """
27
-
28
- file_name: str | None = Field(
29
- default=None,
30
- description=(
31
- "Provide the name of the file or its relative path in the "
32
- "project. If an absolute path is given, it will be converted"
33
- " to a string. "
34
- ),
35
- examples=[
36
- "session.py",
37
- "src/components/UserCard.tsx",
38
- "/absolute/path/to/my_file.txt",
39
- ],
40
- )
41
- description: str | None = Field(
42
- default=None,
43
- description=(
44
- "Briefly explain the file's purpose or function within the "
45
- "project. This can be a short summary describing why this "
46
- "file is needed and/or what it does."
47
- ),
48
- examples=[
49
- "Manages user session logic for the LionAGI framework.",
50
- "Contains CSS styles for the navbar component.",
51
- ],
52
- )
53
-
54
- @field_validator("file_name", mode="before")
55
- def validate_file_name(cls, value):
56
- if isinstance(value, Path):
57
- return str(value)
58
- return value
59
-
60
- @abstractmethod
61
- def render_content(
62
- self,
63
- header: str | None = None,
64
- footer: str | None = None,
65
- ) -> str:
66
- pass
67
-
68
- def persist(
69
- self,
70
- directory: Path | str,
71
- overwrite: bool = True,
72
- timestamp: bool = False,
73
- random_hash_digits: int = None,
74
- header: str | None = None,
75
- footer: str | None = None,
76
- ) -> Path:
77
- from lionagi.utils import create_path
78
-
79
- fp = create_path(
80
- directory=directory,
81
- filename=self.file_name,
82
- file_exist_ok=overwrite,
83
- timestamp=timestamp,
84
- random_hash_digits=random_hash_digits,
85
- )
86
- fp.write_text(self.render_content(header=header, footer=footer))
87
- return fp
88
-
89
-
90
- class Documentation(File):
91
- """
92
- Represents a documentation file, typically Markdown-based, that includes
93
- a title and main content explaining or describing some aspect of the project.
94
- """
95
-
96
- title: str = Field(
97
- default_factory=str,
98
- description=(
99
- "Specify the title of this documentation entry or page. "
100
- "For instance, this might be the top-level heading in a Markdown file.\n"
101
- ),
102
- examples=["Getting Started", "API Reference: LionAGI Session Module"],
103
- )
104
- content: str = Field(
105
- default_factory=str,
106
- description=(
107
- "Provide the primary Markdown (or similar) content for the documentation. "
108
- "This can include headings, bullet points, tables, code snippets, etc.\n"
109
- ),
110
- )
111
- sources: list[Source] | None = Field(
112
- default=None,
113
- description=(
114
- "List of sources or references used to create this documentation. "
115
- "Each source should include a title and URL to the original content."
116
- ),
117
- )
118
-
119
- def render_content(
120
- self,
121
- header: str | None = None,
122
- footer: str | None = None,
123
- include_source: bool = True,
124
- ) -> str:
125
- """
126
- Renders the documentation content, optionally including citations for sources.
127
- """
128
- footer = footer or ""
129
- if include_source and self.sources:
130
- footer = "\n\n## Sources\n"
131
- for source in self.sources:
132
- footer += f"- [{source.title}]({source.url})\n"
133
- footer += f" - {source.note}\n" if source.note else ""
134
- return (header or "") + self.content + footer
135
-
136
-
137
- class ResearchSummary(Documentation):
138
- """
139
- Captures the final outcome of the deep research process.
140
- """
141
-
142
- scope: str | None = Field(
143
- default=None,
144
- description="Brief statement of what was investigated. E.g., 'Surveyed python-based ORMs.'",
145
- )
146
- main_takeaways: str = Field(
147
- ...,
148
- description="High-level summary of the most critical insights for the project.",
149
- )
150
- findings: list[ResearchFinding] = Field(
151
- default_factory=list,
152
- description="List of key facts or knowledge gained.",
153
- )
154
- risks: list[PotentialRisk] = Field(
155
- default_factory=list,
156
- description="Identified obstacles or concerns for the project.",
157
- )
158
-
159
- def render_content(
160
- self,
161
- header: str | None = None,
162
- footer: str | None = None,
163
- ) -> str:
164
- """
165
- Renders the documentation content, optionally including citations for sources.
166
- """
167
- content = self.model_dump(exclude_unset=True, exclude_none=True)
168
-
169
- from lionagi.libs.schema.as_readable import as_readable
170
-
171
- text = as_readable(content, md=True, format_curly=True)
172
-
173
- footer = footer or ""
174
- if self.sources:
175
- footer = "\n\n## Sources\n"
176
- for source in self.sources:
177
- footer += f"- [{source.title}]({source.url})\n"
178
- footer += f" - {source.note}\n" if source.note else ""
179
- return (header or "") + text + footer
180
-
181
-
182
- class Module(File):
183
- """
184
- Represents a single source file: docstring, imports, top-level functions, classes, etc.
185
- """
186
-
187
- name: str = Field(
188
- ...,
189
- description="Logical name for this file/module (e.g., 'utils', 'main', 'data_models').",
190
- )
191
- path: str | None = Field(
192
- default=None,
193
- description="Filesystem path if known (e.g., 'src/utils.py').",
194
- )
195
- docstring: str | None = Field(
196
- default=None, description="File-level docstring or comments if any."
197
- )
198
- imports: list[Import] = Field(
199
- default_factory=list,
200
- description="All import statements / using directives / includes in this file.",
201
- )
202
- classes: list[Class] = Field(
203
- default_factory=list,
204
- description="All class or interface definitions in this file.",
205
- )
206
- functions: list[Function] = Field(
207
- default_factory=list,
208
- description="All top-level (non-class) functions in this file.",
209
- )
210
- variables: list = Field(
211
- default_factory=list,
212
- description="All top-level variables/constants in this file.",
213
- )
214
- language: str = Field(
215
- default_factory=str,
216
- description=(
217
- "Indicate the programming language of this code file. e.g., 'python', 'typescript'. "
218
- "LLMs or humans can use this info to apply specific formatting or syntax analysis."
219
- ),
220
- )
221
-
222
- def render_content(
223
- self,
224
- header: str | None = None,
225
- footer: str | None = None,
226
- ) -> str:
227
- """
228
- Renders the documentation content, optionally including citations for sources.
229
- """
230
- text = self.model_dump_json(exclude_none=True, exclude_unset=True)
231
- return header or "" + text + footer or ""
232
-
233
-
234
- # File: lionagi/fields/file.py
@@ -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