sinapsis_core 1.0.0__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 (50) hide show
  1. sinapsis_core/__init__.py +0 -0
  2. sinapsis_core/agent/__init__.py +5 -0
  3. sinapsis_core/agent/agent.py +362 -0
  4. sinapsis_core/agent/agent_helpers.py +112 -0
  5. sinapsis_core/agent/base_models.py +361 -0
  6. sinapsis_core/agent/builder.py +112 -0
  7. sinapsis_core/agent/profiler_agent.py +117 -0
  8. sinapsis_core/cli/__init__.py +0 -0
  9. sinapsis_core/cli/arg_parser.py +29 -0
  10. sinapsis_core/cli/display_template_info.py +202 -0
  11. sinapsis_core/cli/run_agent_from_config.py +40 -0
  12. sinapsis_core/context_managers/__init__.py +0 -0
  13. sinapsis_core/context_managers/env_var_override_context_manager.py +39 -0
  14. sinapsis_core/context_managers/working_dir_context_manager.py +57 -0
  15. sinapsis_core/data_containers/__init__.py +0 -0
  16. sinapsis_core/data_containers/annotations.py +152 -0
  17. sinapsis_core/data_containers/data_packet.py +364 -0
  18. sinapsis_core/data_containers/model_types/__init__.py +38 -0
  19. sinapsis_core/data_containers/model_types/_asr_base_models.py +39 -0
  20. sinapsis_core/data_containers/model_types/llm_types.py +189 -0
  21. sinapsis_core/exceptions/agent_exceptions.py +2 -0
  22. sinapsis_core/hooks/__init__.py +15 -0
  23. sinapsis_core/hooks/pre_init_hook_registry.py +225 -0
  24. sinapsis_core/template_base/__init__.py +10 -0
  25. sinapsis_core/template_base/base_models.py +59 -0
  26. sinapsis_core/template_base/copy_data_container.py +46 -0
  27. sinapsis_core/template_base/dynamic_template.py +169 -0
  28. sinapsis_core/template_base/dynamic_template_factory.py +454 -0
  29. sinapsis_core/template_base/dynamic_template_helpers/__init__.py +0 -0
  30. sinapsis_core/template_base/dynamic_template_helpers/builder_methods.py +92 -0
  31. sinapsis_core/template_base/dynamic_template_helpers/signature_parser.py +625 -0
  32. sinapsis_core/template_base/empty_data_container.py +23 -0
  33. sinapsis_core/template_base/input_template.py +8 -0
  34. sinapsis_core/template_base/merge_data_flow.py +33 -0
  35. sinapsis_core/template_base/multi_execute_template.py +65 -0
  36. sinapsis_core/template_base/output_template.py +8 -0
  37. sinapsis_core/template_base/split_data_flow.py +50 -0
  38. sinapsis_core/template_base/template.py +292 -0
  39. sinapsis_core/template_base/transfer_data_container.py +13 -0
  40. sinapsis_core/utils/__init__.py +0 -0
  41. sinapsis_core/utils/base_model_updater.py +148 -0
  42. sinapsis_core/utils/doc_string_generator.py +20 -0
  43. sinapsis_core/utils/env_var_keys.py +249 -0
  44. sinapsis_core/utils/env_var_utils.py +6 -0
  45. sinapsis_core/utils/logging_utils.py +53 -0
  46. sinapsis_core-1.0.0.dist-info/METADATA +239 -0
  47. sinapsis_core-1.0.0.dist-info/RECORD +50 -0
  48. sinapsis_core-1.0.0.dist-info/WHEEL +4 -0
  49. sinapsis_core-1.0.0.dist-info/licenses/LICENSE-APACHE +202 -0
  50. sinapsis_core-1.0.0.dist-info/licenses/LICENSE-MIT +21 -0
@@ -0,0 +1,249 @@
1
+ # -*- coding: utf-8 -*-
2
+ import logging
3
+ import os
4
+ import typing
5
+ from pathlib import Path
6
+
7
+ from pydantic import BaseModel, StringConstraints, computed_field
8
+ from typing_extensions import Annotated
9
+
10
+ EnvVarNameType = Annotated[str, StringConstraints(strip_whitespace=True, strict=True, to_upper=True)]
11
+ DocStringType = Annotated[str, StringConstraints(strip_whitespace=True, strict=True, to_upper=True, min_length=15)]
12
+ EnvVarTypes = typing.Union[str | bool | float | int | list | None]
13
+
14
+
15
+ class EnvVarEntry(BaseModel):
16
+ var_name: EnvVarNameType
17
+ default_value: EnvVarTypes
18
+ allowed_values: list[EnvVarTypes] | None = None
19
+ description: str | None = None
20
+ return_type: type = str
21
+ required: bool = False
22
+ is_secret: bool = False
23
+
24
+ @computed_field
25
+ @property
26
+ def value(self) -> EnvVarTypes:
27
+ val: EnvVarTypes
28
+ val = os.getenv(self.var_name)
29
+
30
+ if val:
31
+ if self.return_type is bool:
32
+ val = val.lower() in ("true", "1")
33
+
34
+ elif self.return_type is list:
35
+ val = list(val.split(","))
36
+
37
+ elif self.return_type is int:
38
+ val = int(val)
39
+ elif self.return_type is float:
40
+ val = float(val)
41
+ if (self.allowed_values and val in self.allowed_values) or not self.allowed_values:
42
+ return val
43
+ log_msg = (
44
+ f"`{self.var_name}` is not set or set with invalid value `{val}`, "
45
+ f"falling back on default `{self.default_value}`"
46
+ )
47
+ logging.debug(log_msg)
48
+ return self.default_value
49
+
50
+ def __repr__(self) -> str:
51
+ if self.is_secret:
52
+ value = "*" * len(self.value)
53
+ default = "*" * len(self.default_value)
54
+ else:
55
+ value = self.value
56
+ default = self.default_value
57
+
58
+ return (
59
+ f"EnvVarEntry:"
60
+ f"\tname: {self.var_name}"
61
+ f"\tvalue: {value}"
62
+ f"\tdefault: {default}"
63
+ f"\tallowed_values: {self.allowed_values}"
64
+ f"\tdescription: {self.description}"
65
+ f"\treturn_type: {self.return_type}"
66
+ f"\tis_secret: {self.is_secret}"
67
+ f"\trequired: {self.required}"
68
+ )
69
+
70
+
71
+ def return_docs_for_vars(
72
+ env_var_class: BaseModel,
73
+ docs: str = "",
74
+ string_for_doc: str = """Agent env vars available: \n""",
75
+ ) -> str:
76
+ docs += string_for_doc
77
+
78
+ for var, entry in env_var_class.model_fields.items():
79
+ options = (
80
+ f"one of {entry.default.allowed_values}"
81
+ if entry.default.allowed_values
82
+ else f"Var must be of type: {EnvVarTypes}"
83
+ )
84
+ docs += f"""
85
+ {var}:
86
+ {entry.default.description}
87
+ options: {options}
88
+ """
89
+ return docs
90
+
91
+
92
+ class _SinapsisEnvVarDefaults(BaseModel):
93
+ SINAPSIS_BUILD_DOCS: EnvVarEntry = EnvVarEntry(
94
+ var_name="SINAPSIS_BUILD_DOCS",
95
+ default_value=False,
96
+ allowed_values=[True, False, 1, 0],
97
+ description="env var to be set when building documentation. It is particularly"
98
+ "useful in dynamic templates where a module is being wrapped and or "
99
+ "multiple dynamic templates are created. ",
100
+ return_type=bool,
101
+ )
102
+
103
+ SINAPSIS_PRODUCTION_MODE: EnvVarEntry = EnvVarEntry(
104
+ var_name="SINAPSIS_PRODUCTION_MODE",
105
+ default_value=False,
106
+ allowed_values=[True, False, 1, 0],
107
+ description="sets production mode, which can be used import production version "
108
+ "of templates and other optimized code, with less dependencies.",
109
+ return_type=bool,
110
+ )
111
+ SINAPSIS_CACHE_DIR: EnvVarEntry = EnvVarEntry(
112
+ var_name="SINAPSIS_CACHE_DIR",
113
+ default_value=str(Path.joinpath(Path.home(), ".cache/sinapsis/")),
114
+ allowed_values=None,
115
+ description="set cache directory for anything that gets saved to disk",
116
+ )
117
+ SINAPSIS_LOG_LEVEL: EnvVarEntry = EnvVarEntry(
118
+ var_name="SINAPSIS_LOG_LEVEL",
119
+ default_value="INFO",
120
+ allowed_values=["TRACE", "DEBUG", "INFO", "SUCCESS", "WARNING", "ERROR", "CRITICAL"],
121
+ description="set log level for the agent",
122
+ )
123
+ SINAPSIS_LOGGER: EnvVarEntry = EnvVarEntry(
124
+ var_name="SINAPSIS_LOGGER",
125
+ default_value="loguru",
126
+ allowed_values=["loguru", "standard"],
127
+ description="set logger to either loguru or standard, i.e. python's built in logging module",
128
+ )
129
+ AGENT_MODE: EnvVarEntry = EnvVarEntry(
130
+ var_name="AGENT_MODE",
131
+ default_value="generator",
132
+ allowed_values=["generator", "single", "loop_forever"],
133
+ description="set agent execution mode",
134
+ )
135
+ ADDITIONAL_TEMPLATE_PATHS: EnvVarEntry = EnvVarEntry(
136
+ var_name="ADDITIONAL_TEMPLATE_PATHS",
137
+ default_value=[],
138
+ allowed_values=None,
139
+ description="Set additional template paths. This must be a list of directory paths given "
140
+ "as ADDITIONAL_TEMPLATE_PATHS=path/one,path/two",
141
+ return_type=list,
142
+ )
143
+
144
+ # these should be moved when splitting monorepo
145
+ STREAMLIT_LOG_LEVEL: EnvVarEntry = EnvVarEntry(
146
+ var_name="STREAMLIT_LOG_LEVEL",
147
+ default_value="debug",
148
+ allowed_values=list(logging._nameToLevel.keys()),
149
+ description="set streamlit log level",
150
+ )
151
+ REBUILD_UI_TEMPLATES: EnvVarEntry = EnvVarEntry(
152
+ var_name="REBUILD_UI_TEMPLATES",
153
+ default_value=False,
154
+ allowed_values=[True, False, 1, 0],
155
+ description="Force rebuilding all UI blocks when restarting the streamlit app. "
156
+ "It does not have effect if the cached file does not exit. ",
157
+ return_type=bool,
158
+ )
159
+ MP_START_METHOD: EnvVarEntry = EnvVarEntry(
160
+ var_name="MP_START_METHOD",
161
+ default_value="spawn",
162
+ allowed_values=["spawn", "forkserver", "fork"],
163
+ description="Set the multiprocessing start method for torch. This is useful"
164
+ "particularly when using other packages that use multiprocessing "
165
+ "under the hood and may cause conflicts. See multiprocessing python module for more info.",
166
+ return_type=bool,
167
+ )
168
+ AUTHORIZATION_SINAPSIS_TOKEN: EnvVarEntry = EnvVarEntry(
169
+ var_name="AUTHORIZATION_SINAPSIS_TOKEN",
170
+ default_value="",
171
+ allowed_values=None,
172
+ description="set the internal token to retrieve messages from database",
173
+ )
174
+ GRADIO_SHARE_APP: EnvVarEntry = EnvVarEntry(
175
+ var_name="GRADIO_SHARE_APP",
176
+ default_value=False,
177
+ allowed_values=[True, False, 1, 0],
178
+ description="Env var to be ued in gradio apps to set share=True|False",
179
+ return_type=bool,
180
+ )
181
+ AGENT_CONFIG_PATH: EnvVarEntry = EnvVarEntry(
182
+ var_name="AGENT_CONFIG_PATH",
183
+ default_value=None,
184
+ allowed_values=None,
185
+ description="set the path to the agent config to be executed",
186
+ )
187
+
188
+ WORKING_DIR: EnvVarEntry = EnvVarEntry(
189
+ var_name="WORKING_DIR",
190
+ default_value=str(Path.cwd()),
191
+ allowed_values=None,
192
+ description="set the path to the current working directory",
193
+ )
194
+
195
+ ENABLED_PRE_INIT_HOOKS: EnvVarEntry = EnvVarEntry(
196
+ var_name="ENABLED_PRE_INIT_HOOKS",
197
+ default_value=[],
198
+ allowed_values=None,
199
+ description="sets sinapsis package names to include pre-init hooks from, ",
200
+ return_type=list,
201
+ )
202
+
203
+ ENABLED_AGENT_DECORATORS: EnvVarEntry = EnvVarEntry(
204
+ var_name="ENABLED_AGENT_DECORATORS",
205
+ default_value=[],
206
+ allowed_values=None,
207
+ description="sets sinapsis package names to exclude agent decorators from",
208
+ return_type=list,
209
+ )
210
+
211
+ USER_STAGING_DATA_ROOT_DIR: EnvVarEntry = EnvVarEntry(
212
+ var_name="USER_STAGING_DATA_ROOT_DIR",
213
+ default_value="/data/staging/",
214
+ allowed_values=None,
215
+ description="Dir to save staging [temporary or intermediate] user data, i.e. data saved "
216
+ " during streaming or by templates that require saving data to disk. ",
217
+ return_type=str,
218
+ )
219
+ USER_PERSISTENT_DATA_ROOT_DIR: EnvVarEntry = EnvVarEntry(
220
+ var_name="USER_PERSISTENT_DATA_ROOT_DIR",
221
+ default_value="/data/persistent/",
222
+ allowed_values=None,
223
+ description="Dir used to store user's persisted data, "
224
+ "commonly uploaded through UIUpload* templates. "
225
+ "Persistency depends on tiers",
226
+ return_type=str,
227
+ )
228
+
229
+
230
+ SinapsisEnvVarDefaults: BaseModel = _SinapsisEnvVarDefaults()
231
+ doc_str = return_docs_for_vars(SinapsisEnvVarDefaults)
232
+
233
+
234
+ __doc__ = doc_str
235
+
236
+
237
+ def __getattr__(name: str) -> str:
238
+ """to use as an import, when updating the value is not important"""
239
+ if name in SinapsisEnvVarDefaults.model_fields:
240
+ return SinapsisEnvVarDefaults.model_fields[name].default.value
241
+
242
+ raise AttributeError(f"Agent does not have `{name}` env var")
243
+
244
+
245
+ __all__ = (
246
+ *list(SinapsisEnvVarDefaults.model_fields.keys()),
247
+ "SinapsisEnvVarDefaults",
248
+ "EnvVarEntry",
249
+ )
@@ -0,0 +1,6 @@
1
+ # -*- coding: utf-8 -*-
2
+ import multiprocessing
3
+
4
+
5
+ def set_multiprocessing_start_method(start_method: str) -> None:
6
+ multiprocessing.set_start_method(start_method, force=True)
@@ -0,0 +1,53 @@
1
+ # -*- coding: utf-8 -*-
2
+ import sys
3
+ from typing import Any
4
+
5
+ from sinapsis_core.utils.env_var_keys import SINAPSIS_LOG_LEVEL, SINAPSIS_LOGGER
6
+
7
+
8
+ def make_loguru() -> Any:
9
+ """
10
+ Starts a logging object using loguru module
11
+ """
12
+
13
+ def formatter(record: dict) -> str:
14
+ keyname = " {extra[agent_name]}" if "agent_name" in record["extra"] else "{file.path}" # "{module}"
15
+ keyname += "| {extra[template_name]}" if "template_name" in record["extra"] else ""
16
+ keyname += " | {extra[template_class_name]}" if "template_class_name" in record["extra"] else ""
17
+ return (
18
+ "<g>{time:YYYY-MM-DD @ HH:mm:ss:SSS}</> | <lvl>{level}</> | <c>%s:{function}:{line}</> -"
19
+ " {message}\n{exception}" % keyname
20
+ )
21
+
22
+ from loguru import logger
23
+
24
+ logger.remove()
25
+ logger.add(
26
+ sys.stderr,
27
+ format=formatter,
28
+ level=SINAPSIS_LOG_LEVEL.upper(),
29
+ backtrace=True,
30
+ diagnose=True,
31
+ enqueue=False, ### TBD
32
+ )
33
+ return logger
34
+
35
+
36
+ def make_standard_logger() -> Any:
37
+ """Starts a logging object using built-in logging module"""
38
+ import logging
39
+
40
+ agent_logger = logging.getLogger("sinapsis_agent")
41
+ # monkey patch to mimic loguru
42
+ agent_logger.bind = lambda *args, **kwargs: agent_logger # type:ignore [attr-defined] # noqa: ARG005 unused args
43
+ agent_logger.setLevel(SINAPSIS_LOG_LEVEL.upper())
44
+ formatter_handler = logging.StreamHandler()
45
+ formatter_handler.setLevel(SINAPSIS_LOG_LEVEL.upper())
46
+ formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
47
+ formatter_handler.setFormatter(formatter)
48
+ agent_logger.addHandler(formatter_handler)
49
+ agent_logger.propagate = False
50
+ return agent_logger
51
+
52
+
53
+ sinapsis_logger = make_standard_logger() if SINAPSIS_LOGGER == "standard" else make_loguru()
@@ -0,0 +1,239 @@
1
+ Metadata-Version: 2.5
2
+ Name: sinapsis_core
3
+ Version: 1.0.0
4
+ Summary: sinapsis core agent and template implementation
5
+ Project-URL: Homepage, https://sinapsis.tech
6
+ Project-URL: Documentation, https://docs.sinapsis.tech/docs
7
+ Project-URL: Tutorials, https://docs.sinapsis.tech/docs/latest/tutorials
8
+ Project-URL: Repository, https://github.com/SinapsisHub/sinapsis-hub.git
9
+ Author-email: Ariel Ruiz-Garcia <ariel@sinapsis.tech>
10
+ Maintainer-email: sinapsis <dev@sinapsis.tech>, Nimesh Patel <nimesh@sinapsis.tech>
11
+ License-Expression: MIT OR Apache-2.0
12
+ License-File: LICENSE-APACHE
13
+ License-File: LICENSE-MIT
14
+ Requires-Python: >=3.13
15
+ Requires-Dist: docstring-parser>=0.16
16
+ Requires-Dist: loguru>=0.7.3
17
+ Requires-Dist: pydantic>=2.8.2
18
+ Requires-Dist: pyyaml>=6.0.2
19
+ Description-Content-Type: text/markdown
20
+
21
+ <h1 align="center">
22
+ <br>
23
+ <a href="https://sinapsis.tech/">
24
+ <img
25
+ src="https://github.com/SinapsisHub/brand-resources/blob/main/public/logo/sinapsis-logo-horizontal-dark-brand.png?raw=true"
26
+ alt="Sinapsis"
27
+ width="300">
28
+ </a>
29
+ <br>
30
+ sinapsis-core
31
+ <br>
32
+ </h1>
33
+
34
+ <p align="center">
35
+ <strong>Agent graphs · Template execution · Shared data semantics</strong>
36
+ </p>
37
+
38
+ `sinapsis-core` implements the Agent and Template runtime and owns the `DataContainer` and typed Packet models behind Sinapsis. This document describes the computational model and the contracts that other framework components depend on. It is not an installation guide or a catalogue of integrations.
39
+
40
+ ## 1. Runtime model
41
+
42
+ Sinapsis separates **the description of a computation** from **the objects that execute it** and **the data exchanged during execution**.
43
+
44
+ ```mermaid
45
+ flowchart TD
46
+ D["Agent definition<br/>declarative configuration"] --> V["AgentSchema<br/>Pydantic validation and graph resolution"]
47
+ V --> R["Agent runtime<br/>template instantiation and orchestration"]
48
+ R --> T1["Template instance A"]
49
+ R --> T2["Template instance B"]
50
+ T1 -->|"DataContainer"| T2
51
+ T2 --> O["Results / completion"]
52
+ ```
53
+
54
+ | Concept | Meaning | Responsibility |
55
+ | --- | --- | --- |
56
+ | **Agent definition** | User-supplied description of a computational graph. | Names template nodes, selects implementations, configures attributes, and declares dependencies. |
57
+ | **`AgentSchema`** | Validated, normalized representation of that definition. | Enforces the canonical graph and configuration rules and records information derived during validation. |
58
+ | **Agent runtime** | Live orchestration object created from a valid definition. | Instantiates and coordinates Templates, manages execution and completion, and produces results. |
59
+ | **Template instance** | Configured instance of a reusable Python computation. | Performs one unit of work under the runtime's input/output and lifecycle conventions. |
60
+ | **`DataContainer` / Packet** | Shared computation-level data model. | Moves multimodal content and associated metadata between Templates. |
61
+
62
+ These concepts must remain distinct: **validating an Agent does not instantiate or execute it**, and a runtime instance is not a substitute for its serializable definition.
63
+
64
+ ## 2. Agent definitions and graph semantics
65
+
66
+ An Agent is a directed graph whose nodes are **Template instances** and whose edges express declared input dependencies. The graph describes *what depends on what*, rather than prescribing which Python method must call which other method.
67
+
68
+ A node declaration has several separate identities:
69
+
70
+ ```yaml
71
+ - template_name: DetectObjects
72
+ class_name: ObjectDetector
73
+ template_input: DecodeImage
74
+ attributes:
75
+ confidence: 0.5
76
+ ```
77
+
78
+ | Field | Semantics |
79
+ | --- | --- |
80
+ | `template_name` | Identifies this **instance** within the Agent graph. Multiple nodes may use the same Template class but must remain distinguishable as instances. |
81
+ | `class_name` | Identifies the Template **implementation** to resolve in the installed environment. |
82
+ | `template_input` | Refers to the upstream node supplying input; it is a graph edge, not a direct Python invocation. |
83
+ | `attributes` | Supplies configuration for this node, validated according to its Template's typed attribute model. |
84
+
85
+ The fragment illustrates the relationship; the referenced class and its attributes are examples, not built-in core implementations.
86
+
87
+ ### Dependency resolution
88
+
89
+ The runtime uses graph dependencies to determine valid execution order, including **topological sorting**. An upstream node must supply the data needed by its dependent node. Independent portions of a graph can be candidates for parallel execution; the actual scheduling strategy is a runtime concern, not a guarantee implied by configuration order.
90
+
91
+ ```mermaid
92
+ flowchart LR
93
+ A[Input] --> B[Preprocess]
94
+ B --> C[Vision model]
95
+ B --> D[Metadata extraction]
96
+ C --> E[Postprocess]
97
+ D --> E
98
+ ```
99
+
100
+ The graph's textual order is not the authoritative execution order. When changing graph validation or scheduling, preserve the distinction between **dependency ordering**, **runtime readiness**, and **completion**: a node can exist in the graph without being ready to run, and repeated execution is possible under non-single modes.
101
+
102
+ ### Canonical validation
103
+
104
+ The framework has **one** authoritative Agent-graph builder, exposed by the stable `sinapsis` interface:
105
+
106
+ ```python
107
+ from sinapsis.agent import AgentSchema, generic_agent_schema_builder
108
+
109
+ agent_schema: AgentSchema = generic_agent_schema_builder(agent_definition)
110
+ ```
111
+
112
+ > **Import convention:** Although `AgentSchema` and `generic_agent_schema_builder` are implemented in `sinapsis-core`, they are exposed through the `sinapsis` package, which provides the stable public API.
113
+ >
114
+ > Consumers should import from `sinapsis` to avoid coupling their code to internal implementation details. Internal modules within `sinapsis-core` may use direct imports where appropriate.
115
+
116
+ The builder returns the canonical `AgentSchema`. Its output may contain derived graph structures such as `sorted_templates`, `template_mapping_dict`, or `sorted_templates_as_dict`. These are part of the validated representation: consumers must not discard them, invent a competing schema, or coerce typed values (for example, numeric `template_type` values) into different representations.
117
+
118
+ **Pydantic is the schema boundary**, not a replacement for runtime coordination. It validates models and configuration; the Agent runtime still owns execution state, scheduling, and lifecycle transitions.
119
+
120
+ ## 3. Template semantics
121
+
122
+ A Template wraps an individual Python computation behind the framework's configuration, lifecycle, and input/output conventions. Its implementation may use any suitable library, model, API, or ordinary Python code; the Agent interacts with it through the common Template contract.
123
+
124
+ ### Configuration versus instance state
125
+
126
+ Template **attributes** describe how a node should behave (for example, model selection or thresholds). A running Template may also hold **state** (for example, initialized resources, iterators, cached models, or progress across inputs). These are different concerns:
127
+
128
+ - Attribute validation establishes the configured shape and types before or during instantiation.
129
+ - Initialization may be eager or lazy, depending on the Template and runtime configuration.
130
+ - Execution consumes framework data and produces framework data under the shared contract.
131
+ - Reset, attribute updates, completion, and stopping are lifecycle operations; they should not be confused with reconstructing the Agent definition.
132
+
133
+ The framework's conventional processing boundary is **one `DataContainer` input and one `DataContainer` output** for a Template invocation. A container may itself hold many packets across modalities. A streaming or iterative Agent can process many such invocations over its lifetime.
134
+
135
+ ### Composition
136
+
137
+ A **composite Template** or **SubAgent** encapsulates a more complex computation behind a Template-level interface. This allows a parent Agent to treat a nested workflow as a reusable unit while the nested structure retains its own internal execution semantics.
138
+
139
+ Composition does not imply that every nested operation shares one process, one set of dependencies, or one scheduling policy; those are execution-environment concerns.
140
+
141
+ ## 4. Agent execution and lifecycle
142
+
143
+ The orchestration layer resolves graph dependencies, manages Template instances, advances their execution, and tracks whether further work is available or the Agent should terminate.
144
+
145
+ A useful conceptual lifecycle is:
146
+
147
+ ```text
148
+ Agent definition
149
+ │
150
+ ▼
151
+ Validate / normalize graph
152
+ │
153
+ ▼
154
+ Resolve and create Template instances
155
+ │ (possibly with lazy resource initialization)
156
+ ▼
157
+ Determine ready Templates from graph and runtime state
158
+ │
159
+ ▼
160
+ Execute Templates / propagate DataContainers
161
+ │
162
+ ├── more work available ──► continue
163
+ │
164
+ ├── blocked / waiting ────► coordinate readiness
165
+ │
166
+ └── completed / stopped ──► finish execution
167
+ ```
168
+
169
+ The runtime also supports blocking and completion signalling where needed. Those signals are **control state**, not extra modality data to insert into a `DataContainer`.
170
+
171
+ ### Execution modes
172
+
173
+ | Mode | Termination semantics | Typical data behavior |
174
+ | --- | --- | --- |
175
+ | **Single** | Execute a workflow once. | Produces a result for that execution. |
176
+ | **Generator** | Advance through successive inputs/results until the participating Templates finish. | Suitable for finite streams, datasets, or iterators. |
177
+ | **Continuous** | Continue processing until explicitly stopped. | Suitable for live sources; outputs are often consumed or persisted as they are produced. |
178
+
179
+ The mode governs **how execution progresses and ends**; it does not change the Template or `DataContainer` contracts. The precise Python entry point and result-consumption mechanism are determined by the caller/runner.
180
+
181
+ ## 5. DataContainer and Packet semantics
182
+
183
+ `DataContainer` and the typed Packet models are **defined in `sinapsis-core`**. Together they form Sinapsis's **universal data transport (UDT) contract** at Template boundaries. A container is a structured collection of content, not a requirement that every Template understand every modality.
184
+
185
+ ```text
186
+ DataContainer
187
+ ├── container_id
188
+ ├── llm_conversations[] → LLmconversationPacket
189
+ ├── images[] → ImagePacket
190
+ ├── audios[] → AudioPacket
191
+ ├── texts[] → TextPacket
192
+ ├── time_series[] → TimeSeriesPacket
193
+ ├── binary_data[] → BinaryPacket
194
+ └── generic_data{} → additional structured values
195
+ ```
196
+
197
+ The collections above illustrate the core data model; exact field types and optional metadata are defined by the `sinapsis-core` Pydantic models.
198
+
199
+ ### Container versus Packet
200
+
201
+ - A **container** is the unit exchanged between Template invocations. One container can carry zero, one, or many packets, including multiple modalities at once.
202
+ - A **Packet** represents an individual content item plus metadata relevant to that item. Packet schemas preserve modality-specific structure instead of flattening everything into untyped dictionaries.
203
+ - **`generic_data`** accommodates structured values without a suitable native packet type. Use typed packets when one exists, so downstream Templates retain a predictable contract.
204
+
205
+ | Packet | Represents | Examples of modality-specific context |
206
+ | --- | --- | --- |
207
+ | `ImagePacket` | Image content, including individual video frames where appropriate. | Colour space, boxes, keypoints, segmentation annotations. |
208
+ | `AudioPacket` | Audio content. | Sample rate, duration. |
209
+ | `TextPacket` | Text content. | Language or token-related information. |
210
+ | `TimeSeriesPacket` | Temporal observations or forecasts. | Time indexes, past/future covariates. |
211
+ | `BinaryPacket` | Binary payloads. | Content carried without requiring a modality-specific interpretation. |
212
+
213
+ Some packet models also record **provenance** (for example, `source` or `modified_by_templates`) and annotations. These fields describe the individual item's history or interpretation, not the Agent's scheduling state. Preserve them when transforming a packet unless the operation explicitly changes their meaning.
214
+
215
+ ### Data flow is not wire serialization
216
+
217
+ `DataContainer` defines the **logical in-memory contract**. Encoding its content for network transport, streams, databases, or object storage is a separate responsibility. A serialization layer must preserve typed content and metadata; a plain JSON conversion is not automatically suitable for arbitrary binary or numerical payloads.
218
+
219
+ Likewise, the contract does not guarantee automatic cloning or merging of containers at every graph edge. Copying, mutation, fan-out, and fan-in behavior must follow the actual Template/runtime implementation rather than assumptions made by an integration.
220
+
221
+ ## 6. Architectural boundaries and invariants
222
+
223
+ `sinapsis-core` owns the **Agent runtime, Template contracts, and universal data transport models** (`DataContainer` and typed Packets). The separate `sinapsis` distribution supplies the **stable public import surface** over those implementations. Serialization and remote-transport integrations may live in other packages, but the in-memory data model itself is part of `sinapsis-core`.
224
+
225
+ Core must remain independent of particular hosted services. Authentication, package publication, persistence, billing, remote scheduling, result streaming, and infrastructure scaling belong to surrounding components, not to the Agent graph model.
226
+
227
+ When working on the runtime, the important invariants are:
228
+
229
+ 1. **One graph authority.** `generic_agent_schema_builder()` and `AgentSchema` define the canonical validated Agent representation. No parallel graph validator in the API, CLI, SDK, or Management layer.
230
+ 2. **Distinct graph identities.** Preserve the difference between a Template's implementation class, its named graph instance, and an instantiated runtime object.
231
+ 3. **Declarative edges.** `template_input` expresses dependencies; execution order is derived from graph and runtime state, not YAML position.
232
+ 4. **Typed configuration.** Retain Pydantic validation and serialisation semantics, including derived fields in `model_dump(mode="json")`.
233
+ 5. **Consistent data transport.** Maintain `DataContainer` and Packet contracts across Template boundaries; do not replace them with integration-specific interchange types.
234
+ 6. **Explicit lifecycle semantics.** Keep initialization, execution, blocking, completion, reset, and stopping distinct, particularly across generator and continuous modes.
235
+ 7. **Stable facade.** Internal refactors may change `sinapsis-core`, but must preserve the supported interfaces exported by `sinapsis`.
236
+
237
+ ## License
238
+
239
+ Unless otherwise noted, `sinapsis-core` is dual-licensed under **MIT OR Apache-2.0**. See `LICENSE-MIT` and `LICENSE-APACHE` in the Sinapsis Hub repository.
@@ -0,0 +1,50 @@
1
+ sinapsis_core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ sinapsis_core/agent/__init__.py,sha256=Iq24HRa1ofh3tDVtmBMkQ8ymXIGZZlDdbhi3DB5Dmzw,72
3
+ sinapsis_core/agent/agent.py,sha256=WA1NEof71DvgB0ICKTJDPtqKAnTD1u1DXAOruLNtz3Q,17053
4
+ sinapsis_core/agent/agent_helpers.py,sha256=3wj-EPTMFp6J3IbAnD0dzniZORD_6tCG8PzDs19spQ8,4101
5
+ sinapsis_core/agent/base_models.py,sha256=kNnJS3Ssb3ocIMe734UI3_2gvF0Ek-D2aXkvja_NtaM,13948
6
+ sinapsis_core/agent/builder.py,sha256=sZd3K3IM9ixexSVmXBZDPo79Rop2POhT-s8iK4iPmBc,4447
7
+ sinapsis_core/agent/profiler_agent.py,sha256=LBhLutgbfvcE7gTjqJQ_Hk34zywDVkusA07HmNR-gvo,5404
8
+ sinapsis_core/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ sinapsis_core/cli/arg_parser.py,sha256=HHRmfBwJ75vzITq7V07KBxGBCH3BkxBVkAdw5qq9qzk,1394
10
+ sinapsis_core/cli/display_template_info.py,sha256=omK1_cA27pEXfPhmv6fpJIU875JPCdmqsQJBFD-g9ZQ,8250
11
+ sinapsis_core/cli/run_agent_from_config.py,sha256=hDGKLhV0kqH6uCXAAy-n1d02lRVR6FpRab1sEWNfCwM,1582
12
+ sinapsis_core/context_managers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
+ sinapsis_core/context_managers/env_var_override_context_manager.py,sha256=sgjcDmV2Sa0xll8doC_W5Jt5FSE1UVTpa2lSNCWOyeg,1354
14
+ sinapsis_core/context_managers/working_dir_context_manager.py,sha256=QjI8b6cfgSai0bTwOSR1FInt9cz-ZYdTWvbGfDZpbEs,1912
15
+ sinapsis_core/data_containers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
+ sinapsis_core/data_containers/annotations.py,sha256=Y9ZU6MzmFB9gW2nR1VtLweB8XU4OLt0JlM20j8401_0,4281
17
+ sinapsis_core/data_containers/data_packet.py,sha256=MPgjJbe_rHTM_7wa8R4y3ogfiz49scUESewAmSlCy3E,12246
18
+ sinapsis_core/data_containers/model_types/__init__.py,sha256=uGgUuo9FCBFgnI0blYvYwmnAv7rWgh5V3Tw4nxXfYO4,806
19
+ sinapsis_core/data_containers/model_types/_asr_base_models.py,sha256=tB0nei8ag7CO6njL9XKtPioCShCruESTxvqOY4-EgJM,1046
20
+ sinapsis_core/data_containers/model_types/llm_types.py,sha256=tJ7fYK_kEykbvx8DemirPs1oYW7keefvjxfcbYCm3lE,7382
21
+ sinapsis_core/exceptions/agent_exceptions.py,sha256=uydEYZ7u5Iogb-WwDf524MsVx1S9beKZy-Ixy15wTnk,51
22
+ sinapsis_core/hooks/__init__.py,sha256=uLBrFQ4cBStrS_ls_JRjmCDuuWHoVk9Kyh9htvTz_qc,298
23
+ sinapsis_core/hooks/pre_init_hook_registry.py,sha256=qICJJcj_p5q2igCuIxXS1ujpLLz2Y4ctSSrvkj7DTNk,8859
24
+ sinapsis_core/template_base/__init__.py,sha256=syM7P9FhR3GP47I0MTmdzoMKS1DKV7YU7V9Ath2A6Fc,303
25
+ sinapsis_core/template_base/base_models.py,sha256=fxO2jCrKQUsWiuOPnPMdg7ZWIwPYXF3ZB-xjyb_Iv-Y,1614
26
+ sinapsis_core/template_base/copy_data_container.py,sha256=zsRCN8NKlY4k3b2pA5hoMOvNvIEWOi8ZjGDGtJZlwUg,1453
27
+ sinapsis_core/template_base/dynamic_template.py,sha256=-McFz2ZvCcVCoTSxrw5yCRZAs1P3GOff61XazAOjR-k,7860
28
+ sinapsis_core/template_base/dynamic_template_factory.py,sha256=17YOM2091wM9HGbNaIInLQc71VYOWpiwv6iQsLVF4MM,20037
29
+ sinapsis_core/template_base/empty_data_container.py,sha256=aHrPWnxHuLI_0UexEDA2REFTS58iGj2FNiufxRezY2Q,671
30
+ sinapsis_core/template_base/input_template.py,sha256=OFy3XbZusVvdsFAskiBivFND8BZ2LICXzkSMbfjEn3o,234
31
+ sinapsis_core/template_base/merge_data_flow.py,sha256=BviRI99Ra4vTwve4f5vi5vIzo_EMF9ThRsqNf1_oUaA,1294
32
+ sinapsis_core/template_base/multi_execute_template.py,sha256=tLtJEt8BcQFgva27Tm5qBBBg8sLmAIbHgsafDV5DfuM,2330
33
+ sinapsis_core/template_base/output_template.py,sha256=9D-CRrgJnPgsZIK7L0q3R7CtRlXGaCC6ZtOSEbU_DXE,236
34
+ sinapsis_core/template_base/split_data_flow.py,sha256=_njeKY6iiu3ReryV1mzQsAiqzpTUnhF9J0F-xvj4JR4,1887
35
+ sinapsis_core/template_base/template.py,sha256=BB_y5EmpcPDzv2lbz3wd8fweUdij2D-tVnyl1mGKjtk,11365
36
+ sinapsis_core/template_base/transfer_data_container.py,sha256=RQZ_L5I-L3vyh1X0H4EJb3-vBmBAf17QEC7Rz5FSxak,415
37
+ sinapsis_core/template_base/dynamic_template_helpers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
38
+ sinapsis_core/template_base/dynamic_template_helpers/builder_methods.py,sha256=YIfws58BB2nFw5B0Ojaiergvc7SZUIXbYdexybcFOtc,3061
39
+ sinapsis_core/template_base/dynamic_template_helpers/signature_parser.py,sha256=-9owuN_AvXh9r425FYe9FOOdIEzMyBI4z5LHP9Zg3dw,24015
40
+ sinapsis_core/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
41
+ sinapsis_core/utils/base_model_updater.py,sha256=hBGpq3CF3QvcZWI5LrYr2-9DJxPUFd16SOAv5LeHZJQ,5774
42
+ sinapsis_core/utils/doc_string_generator.py,sha256=m_5BPoSzYyvHKGvwYcqvD92Uop6daOBLp_IBC1Xcfs0,790
43
+ sinapsis_core/utils/env_var_keys.py,sha256=CaFCUveouEHqpDhh3Mu2QmHt-PhYXcKh5JtCIL5S9fc,8947
44
+ sinapsis_core/utils/env_var_utils.py,sha256=YV8BHTh092x0TpLvRrlkRnyK0feqbhIS5ov2dwZcxqg,177
45
+ sinapsis_core/utils/logging_utils.py,sha256=JE46_uuWbr4ijriugsD73ABTTlc7P1LpUGhNXfPyOjQ,1842
46
+ sinapsis_core-1.0.0.dist-info/METADATA,sha256=XcGlTAa4M4ymCJw8iMZ19gCoBuHBqIH5OatF6HGsCvk,14897
47
+ sinapsis_core-1.0.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
48
+ sinapsis_core-1.0.0.dist-info/licenses/LICENSE-APACHE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
49
+ sinapsis_core-1.0.0.dist-info/licenses/LICENSE-MIT,sha256=iCOHXEYY1dWKRkzcJLxYZSxr3EbT8zDzS2OgrVytqD0,1079
50
+ sinapsis_core-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any