xrtm-forecast 0.1.0__tar.gz

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 (55) hide show
  1. xrtm_forecast-0.1.0/LICENSE +201 -0
  2. xrtm_forecast-0.1.0/PKG-INFO +114 -0
  3. xrtm_forecast-0.1.0/README.md +83 -0
  4. xrtm_forecast-0.1.0/pyproject.toml +66 -0
  5. xrtm_forecast-0.1.0/setup.cfg +4 -0
  6. xrtm_forecast-0.1.0/src/forecast/__init__.py +33 -0
  7. xrtm_forecast-0.1.0/src/forecast/agents/__init__.py +0 -0
  8. xrtm_forecast-0.1.0/src/forecast/agents/base.py +34 -0
  9. xrtm_forecast-0.1.0/src/forecast/agents/graph.py +30 -0
  10. xrtm_forecast-0.1.0/src/forecast/agents/llm.py +59 -0
  11. xrtm_forecast-0.1.0/src/forecast/agents/registry.py +45 -0
  12. xrtm_forecast-0.1.0/src/forecast/agents/specialists/__init__.py +0 -0
  13. xrtm_forecast-0.1.0/src/forecast/agents/specialists/analyst.py +63 -0
  14. xrtm_forecast-0.1.0/src/forecast/agents/tool.py +29 -0
  15. xrtm_forecast-0.1.0/src/forecast/cognition/confidence.py +86 -0
  16. xrtm_forecast-0.1.0/src/forecast/data_sources/__init__.py +0 -0
  17. xrtm_forecast-0.1.0/src/forecast/data_sources/base.py +23 -0
  18. xrtm_forecast-0.1.0/src/forecast/data_sources/local.py +46 -0
  19. xrtm_forecast-0.1.0/src/forecast/data_sources/online/__init__.py +0 -0
  20. xrtm_forecast-0.1.0/src/forecast/data_sources/online/polymarket.py +68 -0
  21. xrtm_forecast-0.1.0/src/forecast/graph/__init__.py +0 -0
  22. xrtm_forecast-0.1.0/src/forecast/graph/orchestrator.py +89 -0
  23. xrtm_forecast-0.1.0/src/forecast/inference/__init__.py +0 -0
  24. xrtm_forecast-0.1.0/src/forecast/inference/base.py +48 -0
  25. xrtm_forecast-0.1.0/src/forecast/inference/config.py +28 -0
  26. xrtm_forecast-0.1.0/src/forecast/inference/factory.py +31 -0
  27. xrtm_forecast-0.1.0/src/forecast/inference/gemini_provider.py +510 -0
  28. xrtm_forecast-0.1.0/src/forecast/inference/openai_provider.py +151 -0
  29. xrtm_forecast-0.1.0/src/forecast/memory/base.py +42 -0
  30. xrtm_forecast-0.1.0/src/forecast/memory/chroma.py +46 -0
  31. xrtm_forecast-0.1.0/src/forecast/memory/learner.py +36 -0
  32. xrtm_forecast-0.1.0/src/forecast/memory/unified.py +107 -0
  33. xrtm_forecast-0.1.0/src/forecast/pipelines/__init__.py +0 -0
  34. xrtm_forecast-0.1.0/src/forecast/pipelines/analyst.py +56 -0
  35. xrtm_forecast-0.1.0/src/forecast/schemas/__init__.py +0 -0
  36. xrtm_forecast-0.1.0/src/forecast/schemas/base.py +80 -0
  37. xrtm_forecast-0.1.0/src/forecast/schemas/forecast.py +65 -0
  38. xrtm_forecast-0.1.0/src/forecast/schemas/graph.py +34 -0
  39. xrtm_forecast-0.1.0/src/forecast/telemetry/__init__.py +0 -0
  40. xrtm_forecast-0.1.0/src/forecast/telemetry/audit.py +115 -0
  41. xrtm_forecast-0.1.0/src/forecast/telemetry/hashing.py +37 -0
  42. xrtm_forecast-0.1.0/src/forecast/telemetry/token_stream.py +53 -0
  43. xrtm_forecast-0.1.0/src/forecast/tools/base.py +110 -0
  44. xrtm_forecast-0.1.0/src/forecast/tools/registry.py +53 -0
  45. xrtm_forecast-0.1.0/src/forecast/utils/__init__.py +0 -0
  46. xrtm_forecast-0.1.0/src/forecast/utils/control.py +66 -0
  47. xrtm_forecast-0.1.0/src/forecast/utils/json_util.py +41 -0
  48. xrtm_forecast-0.1.0/src/forecast/utils/parser.py +52 -0
  49. xrtm_forecast-0.1.0/src/forecast/utils/privacy.py +9 -0
  50. xrtm_forecast-0.1.0/src/forecast/utils/rate_limiter.py +129 -0
  51. xrtm_forecast-0.1.0/src/xrtm_forecast.egg-info/PKG-INFO +114 -0
  52. xrtm_forecast-0.1.0/src/xrtm_forecast.egg-info/SOURCES.txt +53 -0
  53. xrtm_forecast-0.1.0/src/xrtm_forecast.egg-info/dependency_links.txt +1 -0
  54. xrtm_forecast-0.1.0/src/xrtm_forecast.egg-info/requires.txt +21 -0
  55. xrtm_forecast-0.1.0/src/xrtm_forecast.egg-info/top_level.txt +1 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that you changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tour (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 XRTM Team
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,114 @@
1
+ Metadata-Version: 2.4
2
+ Name: xrtm-forecast
3
+ Version: 0.1.0
4
+ Summary: Institutional-grade parallelized agentic reasoning engine.
5
+ Author-email: XRTM Team <moy@xrtm.org>
6
+ License: Apache-2.0
7
+ Project-URL: Repository, https://github.com/xrtm-org/forecast
8
+ Project-URL: Issues, https://github.com/xrtm-org/forecast/issues
9
+ Requires-Python: >=3.11
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: pydantic>=2.0.0
13
+ Requires-Dist: google-genai>=0.1.0
14
+ Requires-Dist: openai>=1.0.0
15
+ Requires-Dist: aiohttp>=3.9.0
16
+ Requires-Dist: rich>=13.0.0
17
+ Provides-Extra: memory
18
+ Requires-Dist: chromadb>=0.4.0; extra == "memory"
19
+ Provides-Extra: redis
20
+ Requires-Dist: redis>=5.0.0; extra == "redis"
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
23
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
24
+ Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
25
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
26
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
27
+ Requires-Dist: mkdocs>=1.5.0; extra == "dev"
28
+ Requires-Dist: mkdocs-material>=9.4.0; extra == "dev"
29
+ Requires-Dist: mkdocstrings[python]>=0.23.0; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ # xrtm-forecast
33
+
34
+ Institutional-grade parallelized agentic reasoning engine.
35
+
36
+ ## Overview
37
+ `xrtm-forecast` is the core intelligence engine originally developed for the CAFE (Computer-Aided Financial Engineering) platform. It provides a domain-agnostic framework for:
38
+ - **Inference Layer**: Standardized provider interfaces for Gemini and OpenAI.
39
+ - **Reasoning Graph**: A pluggable state-machine orchestrator for multi-agent workflows.
40
+ - **Agent Core**: Standardized `BaseAgent` for structured reasoning and parsing.
41
+ - **Utilities**: Distributed rate limiting (Redis) and real-time interaction telemetry.
42
+
43
+ ## Architectural Design: "Engine vs. Specialists"
44
+
45
+ `xrtm-forecast` is designed for modularity using a "Lego" philosophy:
46
+ - **The Engine (`agents/`)**: Core structural bricks like `LLMAgent` and `ToolAgent`.
47
+ - **The Specialists (`agents/specialists/`)**: Pre-built expert roles like the `ForecastingAnalyst`.
48
+ - **The Registry**: A central exchange for discovering and plugging in agents and tools.
49
+
50
+ For a deep dive, see [Architecture & Design Principles](docs/architecture.md).
51
+
52
+ ## Installation
53
+
54
+ ### From PyPI (Stable)
55
+ ```bash
56
+ pip install xrtm-forecast
57
+
58
+ # With extras (redis, memory)
59
+ pip install "xrtm-forecast[redis,memory]"
60
+ ```
61
+
62
+ ### From Source (Latest)
63
+ ```bash
64
+ pip install git+https://github.com/xrtm-org/forecast.git
65
+ ```
66
+
67
+ ## Configuration
68
+
69
+ `xrtm-forecast` relies on environment variables for API keys and service connections. Create a `.env` file in your project root:
70
+
71
+ ```bash
72
+ GEMINI_API_KEY=your_key_here
73
+ REDIS_URL=redis://localhost:6379/0 # Optional (fallback to in-memory)
74
+ ```
75
+
76
+ ## Quick Start: Inference
77
+
78
+ ```python
79
+ import asyncio
80
+ from forecast import ModelFactory
81
+ from forecast.inference.config import GeminiConfig
82
+ from pydantic import SecretStr
83
+
84
+ async def main():
85
+ config = GeminiConfig(
86
+ api_key=SecretStr("your-key"),
87
+ model_id="gemini-2.0-flash-lite"
88
+ )
89
+ provider = ModelFactory.get_provider(config)
90
+ response = await provider.generate_content_async("What is the causality of inflation?")
91
+ print(response.text)
92
+
93
+ if __name__ == "__main__":
94
+ asyncio.run(main())
95
+ ```
96
+
97
+ ## Documentation & Examples
98
+
99
+ - **Architecture**: [The "Lego" Design](docs/architecture.md)
100
+ - **Agent Registry**: [Pre-built & Core Agents](docs/agents_registry.md)
101
+ - **Examples**: Check the `examples/` directory for full pipelines (Analyst, Custom Graphs, etc.)
102
+
103
+ ## Contributing
104
+
105
+ We welcome institutional-grade contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for setup instructions and our development workflow.
106
+
107
+
108
+ ---
109
+
110
+ ## License
111
+
112
+ `xrtm-forecast` is open-source software licensed under the **Apache-2.0** license. See the [LICENSE](LICENSE) file for more details.
113
+
114
+ Copyright © 2026 XRTM Team.
@@ -0,0 +1,83 @@
1
+ # xrtm-forecast
2
+
3
+ Institutional-grade parallelized agentic reasoning engine.
4
+
5
+ ## Overview
6
+ `xrtm-forecast` is the core intelligence engine originally developed for the CAFE (Computer-Aided Financial Engineering) platform. It provides a domain-agnostic framework for:
7
+ - **Inference Layer**: Standardized provider interfaces for Gemini and OpenAI.
8
+ - **Reasoning Graph**: A pluggable state-machine orchestrator for multi-agent workflows.
9
+ - **Agent Core**: Standardized `BaseAgent` for structured reasoning and parsing.
10
+ - **Utilities**: Distributed rate limiting (Redis) and real-time interaction telemetry.
11
+
12
+ ## Architectural Design: "Engine vs. Specialists"
13
+
14
+ `xrtm-forecast` is designed for modularity using a "Lego" philosophy:
15
+ - **The Engine (`agents/`)**: Core structural bricks like `LLMAgent` and `ToolAgent`.
16
+ - **The Specialists (`agents/specialists/`)**: Pre-built expert roles like the `ForecastingAnalyst`.
17
+ - **The Registry**: A central exchange for discovering and plugging in agents and tools.
18
+
19
+ For a deep dive, see [Architecture & Design Principles](docs/architecture.md).
20
+
21
+ ## Installation
22
+
23
+ ### From PyPI (Stable)
24
+ ```bash
25
+ pip install xrtm-forecast
26
+
27
+ # With extras (redis, memory)
28
+ pip install "xrtm-forecast[redis,memory]"
29
+ ```
30
+
31
+ ### From Source (Latest)
32
+ ```bash
33
+ pip install git+https://github.com/xrtm-org/forecast.git
34
+ ```
35
+
36
+ ## Configuration
37
+
38
+ `xrtm-forecast` relies on environment variables for API keys and service connections. Create a `.env` file in your project root:
39
+
40
+ ```bash
41
+ GEMINI_API_KEY=your_key_here
42
+ REDIS_URL=redis://localhost:6379/0 # Optional (fallback to in-memory)
43
+ ```
44
+
45
+ ## Quick Start: Inference
46
+
47
+ ```python
48
+ import asyncio
49
+ from forecast import ModelFactory
50
+ from forecast.inference.config import GeminiConfig
51
+ from pydantic import SecretStr
52
+
53
+ async def main():
54
+ config = GeminiConfig(
55
+ api_key=SecretStr("your-key"),
56
+ model_id="gemini-2.0-flash-lite"
57
+ )
58
+ provider = ModelFactory.get_provider(config)
59
+ response = await provider.generate_content_async("What is the causality of inflation?")
60
+ print(response.text)
61
+
62
+ if __name__ == "__main__":
63
+ asyncio.run(main())
64
+ ```
65
+
66
+ ## Documentation & Examples
67
+
68
+ - **Architecture**: [The "Lego" Design](docs/architecture.md)
69
+ - **Agent Registry**: [Pre-built & Core Agents](docs/agents_registry.md)
70
+ - **Examples**: Check the `examples/` directory for full pipelines (Analyst, Custom Graphs, etc.)
71
+
72
+ ## Contributing
73
+
74
+ We welcome institutional-grade contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for setup instructions and our development workflow.
75
+
76
+
77
+ ---
78
+
79
+ ## License
80
+
81
+ `xrtm-forecast` is open-source software licensed under the **Apache-2.0** license. See the [LICENSE](LICENSE) file for more details.
82
+
83
+ Copyright © 2026 XRTM Team.
@@ -0,0 +1,66 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "xrtm-forecast"
7
+ version = "0.1.0"
8
+ description = "Institutional-grade parallelized agentic reasoning engine."
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = {text = "Apache-2.0"}
12
+ authors = [
13
+ {name = "XRTM Team", email = "moy@xrtm.org"}
14
+ ]
15
+ dependencies = [
16
+ "pydantic>=2.0.0",
17
+ "google-genai>=0.1.0",
18
+ "openai>=1.0.0",
19
+ "aiohttp>=3.9.0",
20
+ "rich>=13.0.0"
21
+ ]
22
+
23
+ [project.urls]
24
+ Repository = "https://github.com/xrtm-org/forecast"
25
+ Issues = "https://github.com/xrtm-org/forecast/issues"
26
+
27
+ [project.optional-dependencies]
28
+ memory = [
29
+ "chromadb>=0.4.0"
30
+ ]
31
+ redis = [
32
+ "redis>=5.0.0"
33
+ ]
34
+ dev = [
35
+ "pytest>=7.0.0",
36
+ "pytest-asyncio>=0.21.0",
37
+ "pytest-cov>=4.1.0",
38
+ "ruff>=0.1.0",
39
+ "mypy>=1.0.0",
40
+ "mkdocs>=1.5.0",
41
+ "mkdocs-material>=9.4.0",
42
+ "mkdocstrings[python]>=0.23.0"
43
+ ]
44
+
45
+ [tool.pytest.ini_options]
46
+ pythonpath = ["."]
47
+ testpaths = ["tests"]
48
+ asyncio_mode = "strict"
49
+
50
+ [tool.setuptools]
51
+ package-dir = {"" = "src"}
52
+ packages = {find = {where = ["src"]}}
53
+
54
+ [tool.ruff]
55
+ line-length = 120
56
+ target-version = "py311"
57
+ exclude = [".git", ".venv", "build", "dist"]
58
+
59
+ [tool.ruff.lint]
60
+ select = ["E", "F", "I", "W"]
61
+ ignore = ["E501"]
62
+
63
+ [tool.mypy]
64
+ python_version = "3.11"
65
+ ignore_missing_imports = true
66
+ strict = false
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,33 @@
1
+ from forecast.agents.base import Agent
2
+ from forecast.agents.graph import GraphAgent
3
+ from forecast.agents.llm import LLMAgent
4
+ from forecast.agents.registry import registry
5
+ from forecast.agents.specialists.analyst import ForecastingAnalyst
6
+ from forecast.agents.tool import ToolAgent
7
+ from forecast.graph.orchestrator import Orchestrator
8
+ from forecast.inference.factory import ModelFactory
9
+ from forecast.memory.unified import Memory
10
+ from forecast.schemas.graph import BaseGraphState
11
+ from forecast.telemetry.audit import auditor
12
+ from forecast.tools.registry import tool_registry
13
+
14
+ __all__ = [
15
+ "Agent",
16
+ "ForecastingAnalyst",
17
+ "registry",
18
+ "LLMAgent",
19
+ "ToolAgent",
20
+ "GraphAgent",
21
+ "Orchestrator",
22
+ "BaseGraphState",
23
+ "ModelFactory",
24
+ "Memory",
25
+ "auditor",
26
+ "tool_registry",
27
+ ]
28
+
29
+ __version__ = "0.1.0"
30
+ __author__ = "XRTM Team"
31
+ __contact__ = "moy@xrtm.org"
32
+ __license__ = "Apache-2.0"
33
+ __copyright__ = "Copyright 2026 XRTM Team"
File without changes
@@ -0,0 +1,34 @@
1
+ import abc
2
+ import logging
3
+ from typing import Any, Dict, Optional, TypeVar
4
+
5
+ from pydantic import BaseModel
6
+
7
+ logger = logging.getLogger(__name__)
8
+
9
+ T = TypeVar("T", bound=BaseModel)
10
+
11
+
12
+ class Agent(abc.ABC):
13
+ """
14
+ Fundamental Lego piece of the xrtm-forecast engine.
15
+ Everything (LLMs, Tools, Graphs) is an Agent.
16
+ """
17
+ def __init__(self, name: Optional[str] = None):
18
+ self.name = name or self.__class__.__name__
19
+
20
+ @abc.abstractmethod
21
+ async def run(self, input_data: Any, **kwargs) -> Any:
22
+ """
23
+ Asynchronous execution of the agent's logic.
24
+ Ideally uses Pydantic models for input/output.
25
+ """
26
+ pass
27
+
28
+ def get_info(self) -> Dict[str, Any]:
29
+ """Returns metadata about the agent for structural tracing."""
30
+ return {
31
+ "name": self.name,
32
+ "type": self.__class__.__name__,
33
+ "version": "0.1.0" # Placeholder for versioning logic
34
+ }
@@ -0,0 +1,30 @@
1
+ from typing import Any, Optional
2
+
3
+ from forecast.agents.base import Agent
4
+ from forecast.graph.orchestrator import Orchestrator
5
+ from forecast.schemas.graph import BaseGraphState
6
+
7
+
8
+ class GraphAgent(Agent):
9
+ """
10
+ Agent that encapsulates a sub-graph (Orchestrator).
11
+ Enables 'Composite Nodes' where an agent internally runs a whole pipeline.
12
+ """
13
+ def __init__(self, orchestrator: Orchestrator, entry_node: str, name: Optional[str] = None):
14
+ super().__init__(name)
15
+ self.orchestrator = orchestrator
16
+ self.entry_node = entry_node
17
+
18
+ async def run(self, input_data: Any, **kwargs) -> Any:
19
+ """
20
+ Runs the internal orchestrator.
21
+ Converts input_data into a BaseGraphState context.
22
+ """
23
+ # Create a fresh state for the sub-graph
24
+ state = BaseGraphState(subject_id=f"subgraph_{self.name}")
25
+ state.context = {"input": input_data, **kwargs}
26
+
27
+ await self.orchestrator.run(state, entry_node=self.entry_node)
28
+
29
+ # Return the final context or a specific output if defined in state
30
+ return state.context.get("output", state.context)
@@ -0,0 +1,59 @@
1
+ import logging
2
+ from typing import Any, Dict, List, Optional, Type, TypeVar, Union
3
+
4
+ from pydantic import BaseModel
5
+
6
+ from forecast.agents.base import Agent
7
+ from forecast.inference.base import InferenceProvider
8
+ from forecast.tools.registry import tool_registry
9
+ from forecast.utils.parser import parse_json_markdown
10
+
11
+ logger = logging.getLogger(__name__)
12
+ T = TypeVar("T", bound=BaseModel)
13
+
14
+ class LLMAgent(Agent):
15
+ """
16
+ Agent that utilizes an LLM (InferenceProvider) for reasoning.
17
+ """
18
+ def __init__(self, model: InferenceProvider, name: Optional[str] = None):
19
+ super().__init__(name)
20
+ self.model = model
21
+
22
+ def get_tools(self, tool_names: Optional[List[str]] = None) -> List[Any]:
23
+ """
24
+ Retrieves tool instances from the global registry.
25
+ If tool_names is None, returns all registered tools.
26
+ """
27
+ if tool_names is None:
28
+ # Return all wrapped tool objects
29
+ return [tool_registry.get_tool(name) for name in tool_registry.list_tools()]
30
+
31
+ tools = []
32
+ for name in tool_names:
33
+ tool = tool_registry.get_tool(name)
34
+ if tool:
35
+ tools.append(tool)
36
+ return tools
37
+
38
+ def parse_output(
39
+ self, text: str, schema: Optional[Type[T]] = None, default: Any = None
40
+ ) -> Union[T, Dict[str, Any]]:
41
+ """Parses LLM text into a Pydantic model or dict."""
42
+ parsed = parse_json_markdown(text)
43
+ if parsed is None:
44
+ return default if default is not None else {}
45
+
46
+ if schema and isinstance(parsed, dict):
47
+ try:
48
+ # Filter out keys not in schema to prevent validation errors
49
+ valid_fields = schema.model_fields.keys()
50
+ filtered = {k: v for k, v in parsed.items() if k in valid_fields}
51
+ return schema(**filtered)
52
+ except Exception as e:
53
+ logger.warning(f"Schema validation failed: {e}")
54
+ return default if default is not None else parsed
55
+ return parsed
56
+
57
+ async def run(self, input_data: Any, **kwargs) -> Any:
58
+ # LLMAgents will typically override this with specific prompting logic
59
+ raise NotImplementedError("LLMAgent subclasses must implement run")
@@ -0,0 +1,45 @@
1
+ import logging
2
+ from typing import Dict, List, Optional, Union
3
+
4
+ from forecast.agents.base import Agent
5
+
6
+ logger = logging.getLogger(__name__)
7
+
8
+
9
+ class AgentRegistry:
10
+ """
11
+ Handles explicit registration and discovery of specialist agents.
12
+ Enables modular, multi-agent reasoning swarms.
13
+ """
14
+ def __init__(self):
15
+ self._agents: Dict[str, Agent] = {}
16
+
17
+ def register(self, agent: Union[Agent, type], name: Optional[str] = None):
18
+ """Registers an agent (instance or class) in the registry."""
19
+ if isinstance(agent, type):
20
+ # If it's a class, we'll instantiate it if we can
21
+ # but usually we want instances registered with specific configs
22
+ agent = agent()
23
+
24
+ # Mypy safe cast
25
+ from typing import cast
26
+ agent_instance = cast(Agent, agent)
27
+
28
+ name = name or agent_instance.name
29
+ self._agents[name.lower()] = agent_instance
30
+ logger.info(f"[REGISTRY] Registered agent: {name.upper()}")
31
+
32
+ def get_agent(self, name: str) -> Optional[Agent]:
33
+ """Retrieves an agent by name."""
34
+ return self._agents.get(name.lower())
35
+
36
+ def list_agents(self) -> List[str]:
37
+ """Returns a list of all registered agent names."""
38
+ return list(self._agents.keys())
39
+
40
+ # Compatibility Aliases for legacy specialist support
41
+ def get_specialist(self, domain: str) -> Optional[Agent]:
42
+ return self.get_agent(domain)
43
+
44
+ # Global Singleton instance for the library
45
+ registry = AgentRegistry()