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
lionagi/fields/base.py DELETED
@@ -1,153 +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, HttpUrl
7
-
8
- from lionagi.models import HashableModel
9
-
10
- __all__ = (
11
- "Source",
12
- "TextSnippet",
13
- "CodeSnippet",
14
- "Section",
15
- "OutlineItem",
16
- "Outline",
17
- )
18
-
19
-
20
- class Source(HashableModel):
21
- """
22
- Represents a citation or external source, such as:
23
- - a website,
24
- - documentation link,
25
- - research paper,
26
- - or any external resource.
27
- """
28
-
29
- title: str = Field(
30
- ...,
31
- description="Short label or title for the reference (e.g. 'Pydantic Docs', 'RFC 3986').",
32
- )
33
-
34
- url: str | HttpUrl | None = Field(
35
- None,
36
- description="Full URL or local path pointing to the resource. Must conform to standard URL format.",
37
- )
38
-
39
- note: str | None = Field(
40
- default=None,
41
- description=(
42
- "Optional additional note explaining why this reference is relevant or what it contains."
43
- ),
44
- )
45
-
46
-
47
- class SnippetType(str, Enum):
48
- TEXT = "text"
49
- CODE = "code"
50
-
51
-
52
- class TextSnippet(HashableModel):
53
- """
54
- Specialized snippet for textual/prose content.
55
- """
56
-
57
- type: SnippetType = Field(
58
- SnippetType.TEXT,
59
- description=(
60
- "Must be 'text' for textual snippets. Ensures explicit type distinction."
61
- ),
62
- )
63
- content: str = Field(
64
- ...,
65
- description=(
66
- "The actual text. Can be a paragraph, bullet list, or any narrative content."
67
- ),
68
- )
69
-
70
-
71
- class CodeSnippet(HashableModel):
72
- """
73
- Specialized snippet for source code or command-line examples.
74
- """
75
-
76
- type: SnippetType = Field(
77
- SnippetType.CODE,
78
- description=(
79
- "Must be 'code' for code snippets. Allows separate handling or formatting."
80
- ),
81
- )
82
- content: str = Field(
83
- ...,
84
- description=(
85
- "The actual code or command sequence. Should be well-formatted so it can be rendered properly."
86
- ),
87
- )
88
-
89
-
90
- class Section(HashableModel):
91
- """
92
- A single section of a document or article. Each section has:
93
- - A title
94
- - A sequential list of content snippets (text or code),
95
- which appear in the intended reading order.
96
- - Optional sources specifically cited in this section.
97
- """
98
-
99
- title: str = Field(
100
- ...,
101
- description=(
102
- "The section heading or label, e.g., 'Introduction', 'Implementation Steps'."
103
- ),
104
- )
105
- snippets: list[TextSnippet | CodeSnippet] = Field(
106
- default_factory=list,
107
- description=(
108
- "Ordered list of content snippets. Could be multiple text blocks, code examples, etc."
109
- ),
110
- )
111
-
112
- sources: list[Source] = Field(
113
- default_factory=list,
114
- description=(
115
- "References specifically cited in this section. "
116
- "If sources are stored at the doc-level, this can be omitted."
117
- ),
118
- )
119
-
120
-
121
- class OutlineItem(HashableModel):
122
- """
123
- Represents a single outline item, which could become a full section later.
124
- """
125
-
126
- heading: str = Field(
127
- ...,
128
- description="Short name or label for this item, e.g., 'Chapter 1: Basics'.",
129
- )
130
- summary: str | None = Field(
131
- default=None,
132
- description=(
133
- "A brief description of what this section will cover, if known."
134
- ),
135
- )
136
-
137
-
138
- class Outline(HashableModel):
139
- """
140
- A top-level outline for a document or article.
141
- """
142
-
143
- topic: str = Field(
144
- ..., description="Working title or overarching topic of the document."
145
- )
146
- items: list[OutlineItem] = Field(
147
- default_factory=list,
148
- description="List of major outline points or sections planned.",
149
- )
150
- notes: str | None = Field(
151
- default=None,
152
- description="Any additional remarks, questions, or brainstorming notes for the outline.",
153
- )
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