symbolic-reasoning 0.7.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 (46) hide show
  1. symbolic_reasoning-0.7.0/LICENSE +203 -0
  2. symbolic_reasoning-0.7.0/MANIFEST.in +1 -0
  3. symbolic_reasoning-0.7.0/PKG-INFO +143 -0
  4. symbolic_reasoning-0.7.0/README.md +117 -0
  5. symbolic_reasoning-0.7.0/pyproject.toml +158 -0
  6. symbolic_reasoning-0.7.0/setup.cfg +4 -0
  7. symbolic_reasoning-0.7.0/src/symbolic_reasoning/__init__.py +85 -0
  8. symbolic_reasoning-0.7.0/src/symbolic_reasoning/compiler/__init__.py +20 -0
  9. symbolic_reasoning-0.7.0/src/symbolic_reasoning/compiler/compiler.py +473 -0
  10. symbolic_reasoning-0.7.0/src/symbolic_reasoning/compiler/parser.py +656 -0
  11. symbolic_reasoning-0.7.0/src/symbolic_reasoning/errors.py +19 -0
  12. symbolic_reasoning-0.7.0/src/symbolic_reasoning/gen/__init__.py +0 -0
  13. symbolic_reasoning-0.7.0/src/symbolic_reasoning/gen/py/__init__.py +1 -0
  14. symbolic_reasoning-0.7.0/src/symbolic_reasoning/gen/py/ast.py +410 -0
  15. symbolic_reasoning-0.7.0/src/symbolic_reasoning/gen/py/srg.py +348 -0
  16. symbolic_reasoning-0.7.0/src/symbolic_reasoning/mcp/__init__.py +5 -0
  17. symbolic_reasoning-0.7.0/src/symbolic_reasoning/mcp/__main__.py +39 -0
  18. symbolic_reasoning-0.7.0/src/symbolic_reasoning/mcp/server.py +136 -0
  19. symbolic_reasoning-0.7.0/src/symbolic_reasoning/models/__init__.py +74 -0
  20. symbolic_reasoning-0.7.0/src/symbolic_reasoning/models/aggregator_logic.py +91 -0
  21. symbolic_reasoning-0.7.0/src/symbolic_reasoning/models/srg.py +499 -0
  22. symbolic_reasoning-0.7.0/src/symbolic_reasoning/models/srg_execution.py +503 -0
  23. symbolic_reasoning-0.7.0/src/symbolic_reasoning/py.typed +0 -0
  24. symbolic_reasoning-0.7.0/src/symbolic_reasoning/recording.py +152 -0
  25. symbolic_reasoning-0.7.0/src/symbolic_reasoning/solvers/__init__.py +22 -0
  26. symbolic_reasoning-0.7.0/src/symbolic_reasoning/solvers/auto.py +71 -0
  27. symbolic_reasoning-0.7.0/src/symbolic_reasoning/solvers/protocols.py +33 -0
  28. symbolic_reasoning-0.7.0/src/symbolic_reasoning/solvers/requests.py +70 -0
  29. symbolic_reasoning-0.7.0/src/symbolic_reasoning/solvers/solver.py +73 -0
  30. symbolic_reasoning-0.7.0/src/symbolic_reasoning/tools/__init__.py +45 -0
  31. symbolic_reasoning-0.7.0/src/symbolic_reasoning/tools/models.py +38 -0
  32. symbolic_reasoning-0.7.0/src/symbolic_reasoning/tools/srg_tools.py +250 -0
  33. symbolic_reasoning-0.7.0/src/symbolic_reasoning/validation.py +161 -0
  34. symbolic_reasoning-0.7.0/src/symbolic_reasoning/viewer.py +151 -0
  35. symbolic_reasoning-0.7.0/src/symbolic_reasoning/viewer_assets/vendor/LICENSE.dagre +19 -0
  36. symbolic_reasoning-0.7.0/src/symbolic_reasoning/viewer_assets/vendor/LICENSE.graphlib +19 -0
  37. symbolic_reasoning-0.7.0/src/symbolic_reasoning/viewer_assets/vendor/README.md +14 -0
  38. symbolic_reasoning-0.7.0/src/symbolic_reasoning/viewer_assets/vendor/dagre.min.js +815 -0
  39. symbolic_reasoning-0.7.0/src/symbolic_reasoning/viewer_assets/viewer.css +101 -0
  40. symbolic_reasoning-0.7.0/src/symbolic_reasoning/viewer_assets/viewer.html +45 -0
  41. symbolic_reasoning-0.7.0/src/symbolic_reasoning/viewer_assets/viewer.js +429 -0
  42. symbolic_reasoning-0.7.0/src/symbolic_reasoning.egg-info/PKG-INFO +143 -0
  43. symbolic_reasoning-0.7.0/src/symbolic_reasoning.egg-info/SOURCES.txt +44 -0
  44. symbolic_reasoning-0.7.0/src/symbolic_reasoning.egg-info/dependency_links.txt +1 -0
  45. symbolic_reasoning-0.7.0/src/symbolic_reasoning.egg-info/requires.txt +4 -0
  46. symbolic_reasoning-0.7.0/src/symbolic_reasoning.egg-info/top_level.txt +1 -0
@@ -0,0 +1,203 @@
1
+ Copyright 2026 Anterior, Inc.
2
+
3
+ Apache License
4
+ Version 2.0, January 2004
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction,
12
+ and distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by
15
+ the copyright owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all
18
+ other entities that control, are controlled by, or are under common
19
+ control with that entity. For the purposes of this definition,
20
+ "control" means (i) the power, direct or indirect, to cause the
21
+ direction or management of such entity, whether by contract or
22
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
23
+ outstanding shares, or (iii) beneficial ownership of such entity.
24
+
25
+ "You" (or "Your") shall mean an individual or Legal Entity
26
+ exercising permissions granted by this License.
27
+
28
+ "Source" form shall mean the preferred form for making modifications,
29
+ including but not limited to software source code, documentation
30
+ source, and configuration files.
31
+
32
+ "Object" form shall mean any form resulting from mechanical
33
+ transformation or translation of a Source form, including but
34
+ not limited to compiled object code, generated documentation,
35
+ and conversions to other media types.
36
+
37
+ "Work" shall mean the work of authorship, whether in Source or
38
+ Object form, made available under the License, as indicated by a
39
+ copyright notice that is included in or attached to the work
40
+ (an example is provided in the Appendix below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean any work of authorship, including
51
+ the original version of the Work and any modifications or additions
52
+ to that Work or Derivative Works thereof, that is intentionally
53
+ submitted to Licensor for inclusion in the Work by the copyright owner
54
+ or by an individual or Legal Entity authorized to submit on behalf of
55
+ the copyright owner. For the purposes of this definition, "submitted"
56
+ means any form of electronic, verbal, or written communication sent
57
+ to the Licensor or its representatives, including but not limited to
58
+ communication on electronic mailing lists, source code control systems,
59
+ and issue tracking systems that are managed by, or on behalf of, the
60
+ Licensor for the purpose of discussing and improving the Work, but
61
+ excluding communication that is conspicuously marked or otherwise
62
+ designated in writing by the copyright owner as "Not a Contribution."
63
+
64
+ "Contributor" shall mean Licensor and any individual or Legal Entity
65
+ on behalf of whom a Contribution has been received by Licensor and
66
+ subsequently incorporated within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by combination of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
86
+ or a Contribution incorporated within the Work constitutes direct
87
+ or contributory patent infringement, then any patent licenses
88
+ granted to You under this License for that Work shall terminate
89
+ as of the date such litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or
97
+ Derivative Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, then any Derivative Works that You distribute must
110
+ include a readable copy of the attribution notices contained
111
+ within such NOTICE file, excluding those notices that do not
112
+ pertain to any part of the Derivative Works, in at least one
113
+ of the following places: within a NOTICE text file distributed
114
+ as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or,
116
+ within a display generated by the Derivative Works, if and
117
+ wherever such third-party notices normally appear. The contents
118
+ of the NOTICE file are for informational purposes only and
119
+ do not modify the License. You may add Your own attribution
120
+ notices within Derivative Works that You distribute, alongside
121
+ or as an addendum to the NOTICE text from the Work, provided
122
+ that such additional attribution notices cannot be construed
123
+ as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and
126
+ may provide additional or different license terms and conditions
127
+ for use, reproduction, or distribution of Your modifications, or
128
+ for any such Derivative Works as a whole, provided Your use,
129
+ reproduction, and distribution of the Work otherwise complies with
130
+ the conditions stated in this License.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for reasonable and customary use in describing the
143
+ origin of the Work and reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or consequential damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or any and all
164
+ other commercial damages or losses), even if such Contributor
165
+ has been advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may choose to offer,
169
+ and charge a fee for, acceptance of support, warranty, indemnity,
170
+ or other liability obligations and/or rights consistent with this
171
+ License. However, in accepting such obligations, You may act only
172
+ on Your own behalf and on Your sole responsibility, not on behalf
173
+ of any other Contributor, and only if You agree to indemnify,
174
+ defend, and hold each Contributor harmless for any liability
175
+ incurred by, or claims asserted against, such Contributor by reason
176
+ of your accepting any such warranty or additional liability.
177
+
178
+ END OF TERMS AND CONDITIONS
179
+
180
+ APPENDIX: How to apply the Apache License to your work.
181
+
182
+ To apply the Apache License to your work, attach the following
183
+ boilerplate notice, with the fields enclosed by brackets "[]"
184
+ replaced with your own identifying information. (Don't include
185
+ the brackets!) The text should be enclosed in the appropriate
186
+ comment syntax for the file format. We also recommend that a
187
+ file or class name and description of purpose be included on the
188
+ same "printed page" as the copyright notice for easier
189
+ identification within third-party archives.
190
+
191
+ Copyright [yyyy] [name of copyright owner]
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
@@ -0,0 +1 @@
1
+ prune tests
@@ -0,0 +1,143 @@
1
+ Metadata-Version: 2.4
2
+ Name: symbolic-reasoning
3
+ Version: 0.7.0
4
+ Summary: A Python library for structured reasoning over policies and knowledge to produce deterministic, auditable and explainable outcomes
5
+ Author-email: "Anterior, Inc." <tech@anterior.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/anteriorai/symbolic-reasoning#readme
8
+ Project-URL: Repository, https://github.com/anteriorai/symbolic-reasoning
9
+ Project-URL: Issues, https://github.com/anteriorai/symbolic-reasoning/issues
10
+ Keywords: reasoning,policies,symbolic,ai,decision-making
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.12
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: pydantic>=2.10
23
+ Provides-Extra: mcp
24
+ Requires-Dist: mcp<3,>=2.2; extra == "mcp"
25
+ Dynamic: license-file
26
+
27
+ # symbolic-reasoning
28
+
29
+ <img src="https://raw.githubusercontent.com/anteriorai/symbolic-reasoning/master/docs/images/symbolic-reasoning.png" width="900" alt="A policy compiles to a symbolic reasoning graph that the solver evaluates. The solver asks an oracle, which draws on case knowledge, and the result is a reasoning trace that leads to an outcome." />
30
+
31
+ **Policy-adherent, auditable reasoning for AI agents.**
32
+
33
+ > **Research preview.** `symbolic-reasoning` is pre-1.0 and under active development. The API, the `.srg` language and output formats may change between minor releases without deprecation. Review its outputs before relying on them for consequential decisions. Provided "as is", without warranty, under the [Apache 2.0 License](https://github.com/anteriorai/symbolic-reasoning/blob/master/LICENSE).
34
+
35
+ `symbolic-reasoning` evaluates policies deterministically. You write a policy in the `.srg` language; the library works out which questions need answering, asks your oracle (an LLM, a database, a human), and returns the outcomes with a reasoning trace.
36
+
37
+ | Concern | Handled by |
38
+ |---|---|
39
+ | What are the rules? | Your policy (`.srg`) |
40
+ | What is true in this case? | Your oracle |
41
+ | Which question or decision follows? | The runtime |
42
+ | Why was that decision made? | The reasoning trace |
43
+
44
+ ## Installation
45
+
46
+ Requires Python 3.12+.
47
+
48
+ ```bash
49
+ uv add symbolic-reasoning # or: pip install symbolic-reasoning
50
+ ```
51
+
52
+ ## Quick start
53
+
54
+ Save a policy as `loan_approval.srg`:
55
+
56
+ ```srg
57
+ predicate has_good_credit: "Does the applicant have a credit score of 700 or above?"
58
+ predicate has_stable_income: "Does the applicant have stable employment for at least 2 years?"
59
+ predicate has_low_dti: "Is the applicant's debt-to-income ratio below 43%?"
60
+ predicate has_down_payment: "Has the applicant provided at least 20% down payment?"
61
+
62
+ outcome approved: "Loan Approved"
63
+ outcome denied: "Loan Denied"
64
+ outcome manual_review: "Sent to Manual Review"
65
+
66
+ define core_eligible: all(has_good_credit, has_stable_income, has_low_dti)
67
+
68
+ path approve: all(core_eligible, has_down_payment) => approved
69
+ path review: all(core_eligible, not(has_down_payment)) => manual_review
70
+ path deny: not(core_eligible) => denied
71
+ ```
72
+
73
+ Solve it with an oracle. This one asks you at the terminal:
74
+
75
+ ```python
76
+ import asyncio
77
+
78
+ import symbolic_reasoning as sr
79
+
80
+
81
+ async def oracle(request: sr.OracleRequest) -> dict[str, sr.Answer]:
82
+ answers = {}
83
+ for predicate_request in request.predicate_requests:
84
+ p = predicate_request.predicate
85
+ reply = input(f"{p.question} (y/n): ")
86
+ answers[p.id] = sr.Answer(is_met=reply == "y", reasoning=f"User answered {reply}")
87
+ return answers
88
+
89
+
90
+ async def main() -> None:
91
+ srg = sr.compile_srg_file("loan_approval.srg")
92
+ execution = await sr.asolve(srg, oracle)
93
+
94
+ for path in sr.reasoning_trace(execution).outcome_paths:
95
+ print(srg.outcomes[path.outcome_id].description)
96
+ for step in path.steps:
97
+ mark = "YES" if step.is_met else "NO "
98
+ print(f" {mark} {srg.predicates[step.predicate_id].question}")
99
+
100
+
101
+ asyncio.run(main())
102
+ ```
103
+
104
+ It prints each outcome reached and the answers that led to it:
105
+
106
+ ```
107
+ Sent to Manual Review
108
+ YES Does the applicant have a credit score of 700 or above?
109
+ YES Does the applicant have stable employment for at least 2 years?
110
+ YES Is the applicant's debt-to-income ratio below 43%?
111
+ NO Has the applicant provided at least 20% down payment?
112
+ ```
113
+
114
+ ## Learn more
115
+
116
+ - [The SRG language](https://github.com/anteriorai/symbolic-reasoning/blob/master/docs/srg-language.md): the `.srg` syntax, how policies are evaluated and how to design them.
117
+ - [Python guide](https://github.com/anteriorai/symbolic-reasoning/blob/master/docs/python-guide.md): oracles, step-by-step solving, coverage, reasoning traces, recording and replay, and the API reference.
118
+
119
+ ## Use with agents
120
+
121
+ The quick start runs a policy as a workflow: your code drives the solve and calls the oracle for each round of questions. The agent tools invert that control. The agent drives the solve through tool calls, starting an execution, answering each question from the case evidence and reading the outcomes, while the library still decides which questions are asked and how the answers combine.
122
+
123
+ Serve the tools over MCP with the `mcp` extra:
124
+
125
+ ```bash
126
+ uv add "symbolic-reasoning[mcp]"
127
+ uv run python -m symbolic_reasoning.mcp --srg loan_approval loan_approval.srg
128
+ ```
129
+
130
+ The server talks over stdio, so a host such as Claude Code launches it. See [MCP setup](https://github.com/anteriorai/symbolic-reasoning/blob/master/docs/mcp.md) to connect one.
131
+
132
+ To use the tools without MCP, see the [Python guide](https://github.com/anteriorai/symbolic-reasoning/blob/master/docs/python-guide.md#use-with-agents).
133
+
134
+ ## Use with decision models
135
+
136
+ Every predicate is a yes/no question about the case, which is what a decision model answers. Use one as the oracle: the policy fixes which questions are asked and how their answers combine, and the model answers each from the case evidence. Map its probability to `is_met` and keep the probability in `reasoning`, so the trace shows how confident each answer was.
137
+
138
+ The [Jev example](https://github.com/anteriorai/symbolic-reasoning/tree/master/examples/integrations/jev) does this with [TypeSafe's Jev](https://docs.typesafe.ai/concepts/system-one).
139
+
140
+ ## Examples
141
+
142
+ - [`examples/integrations/jev`](https://github.com/anteriorai/symbolic-reasoning/tree/master/examples/integrations/jev): an oracle backed by the Jev decision model, which answers a policy's questions from Markdown case files and records the run.
143
+ - [`examples/data`](https://github.com/anteriorai/symbolic-reasoning/tree/master/examples/data): an underwriting policy with an application, and a medical necessity review policy with a synthetic clinical record and a replay.
@@ -0,0 +1,117 @@
1
+ # symbolic-reasoning
2
+
3
+ <img src="https://raw.githubusercontent.com/anteriorai/symbolic-reasoning/master/docs/images/symbolic-reasoning.png" width="900" alt="A policy compiles to a symbolic reasoning graph that the solver evaluates. The solver asks an oracle, which draws on case knowledge, and the result is a reasoning trace that leads to an outcome." />
4
+
5
+ **Policy-adherent, auditable reasoning for AI agents.**
6
+
7
+ > **Research preview.** `symbolic-reasoning` is pre-1.0 and under active development. The API, the `.srg` language and output formats may change between minor releases without deprecation. Review its outputs before relying on them for consequential decisions. Provided "as is", without warranty, under the [Apache 2.0 License](https://github.com/anteriorai/symbolic-reasoning/blob/master/LICENSE).
8
+
9
+ `symbolic-reasoning` evaluates policies deterministically. You write a policy in the `.srg` language; the library works out which questions need answering, asks your oracle (an LLM, a database, a human), and returns the outcomes with a reasoning trace.
10
+
11
+ | Concern | Handled by |
12
+ |---|---|
13
+ | What are the rules? | Your policy (`.srg`) |
14
+ | What is true in this case? | Your oracle |
15
+ | Which question or decision follows? | The runtime |
16
+ | Why was that decision made? | The reasoning trace |
17
+
18
+ ## Installation
19
+
20
+ Requires Python 3.12+.
21
+
22
+ ```bash
23
+ uv add symbolic-reasoning # or: pip install symbolic-reasoning
24
+ ```
25
+
26
+ ## Quick start
27
+
28
+ Save a policy as `loan_approval.srg`:
29
+
30
+ ```srg
31
+ predicate has_good_credit: "Does the applicant have a credit score of 700 or above?"
32
+ predicate has_stable_income: "Does the applicant have stable employment for at least 2 years?"
33
+ predicate has_low_dti: "Is the applicant's debt-to-income ratio below 43%?"
34
+ predicate has_down_payment: "Has the applicant provided at least 20% down payment?"
35
+
36
+ outcome approved: "Loan Approved"
37
+ outcome denied: "Loan Denied"
38
+ outcome manual_review: "Sent to Manual Review"
39
+
40
+ define core_eligible: all(has_good_credit, has_stable_income, has_low_dti)
41
+
42
+ path approve: all(core_eligible, has_down_payment) => approved
43
+ path review: all(core_eligible, not(has_down_payment)) => manual_review
44
+ path deny: not(core_eligible) => denied
45
+ ```
46
+
47
+ Solve it with an oracle. This one asks you at the terminal:
48
+
49
+ ```python
50
+ import asyncio
51
+
52
+ import symbolic_reasoning as sr
53
+
54
+
55
+ async def oracle(request: sr.OracleRequest) -> dict[str, sr.Answer]:
56
+ answers = {}
57
+ for predicate_request in request.predicate_requests:
58
+ p = predicate_request.predicate
59
+ reply = input(f"{p.question} (y/n): ")
60
+ answers[p.id] = sr.Answer(is_met=reply == "y", reasoning=f"User answered {reply}")
61
+ return answers
62
+
63
+
64
+ async def main() -> None:
65
+ srg = sr.compile_srg_file("loan_approval.srg")
66
+ execution = await sr.asolve(srg, oracle)
67
+
68
+ for path in sr.reasoning_trace(execution).outcome_paths:
69
+ print(srg.outcomes[path.outcome_id].description)
70
+ for step in path.steps:
71
+ mark = "YES" if step.is_met else "NO "
72
+ print(f" {mark} {srg.predicates[step.predicate_id].question}")
73
+
74
+
75
+ asyncio.run(main())
76
+ ```
77
+
78
+ It prints each outcome reached and the answers that led to it:
79
+
80
+ ```
81
+ Sent to Manual Review
82
+ YES Does the applicant have a credit score of 700 or above?
83
+ YES Does the applicant have stable employment for at least 2 years?
84
+ YES Is the applicant's debt-to-income ratio below 43%?
85
+ NO Has the applicant provided at least 20% down payment?
86
+ ```
87
+
88
+ ## Learn more
89
+
90
+ - [The SRG language](https://github.com/anteriorai/symbolic-reasoning/blob/master/docs/srg-language.md): the `.srg` syntax, how policies are evaluated and how to design them.
91
+ - [Python guide](https://github.com/anteriorai/symbolic-reasoning/blob/master/docs/python-guide.md): oracles, step-by-step solving, coverage, reasoning traces, recording and replay, and the API reference.
92
+
93
+ ## Use with agents
94
+
95
+ The quick start runs a policy as a workflow: your code drives the solve and calls the oracle for each round of questions. The agent tools invert that control. The agent drives the solve through tool calls, starting an execution, answering each question from the case evidence and reading the outcomes, while the library still decides which questions are asked and how the answers combine.
96
+
97
+ Serve the tools over MCP with the `mcp` extra:
98
+
99
+ ```bash
100
+ uv add "symbolic-reasoning[mcp]"
101
+ uv run python -m symbolic_reasoning.mcp --srg loan_approval loan_approval.srg
102
+ ```
103
+
104
+ The server talks over stdio, so a host such as Claude Code launches it. See [MCP setup](https://github.com/anteriorai/symbolic-reasoning/blob/master/docs/mcp.md) to connect one.
105
+
106
+ To use the tools without MCP, see the [Python guide](https://github.com/anteriorai/symbolic-reasoning/blob/master/docs/python-guide.md#use-with-agents).
107
+
108
+ ## Use with decision models
109
+
110
+ Every predicate is a yes/no question about the case, which is what a decision model answers. Use one as the oracle: the policy fixes which questions are asked and how their answers combine, and the model answers each from the case evidence. Map its probability to `is_met` and keep the probability in `reasoning`, so the trace shows how confident each answer was.
111
+
112
+ The [Jev example](https://github.com/anteriorai/symbolic-reasoning/tree/master/examples/integrations/jev) does this with [TypeSafe's Jev](https://docs.typesafe.ai/concepts/system-one).
113
+
114
+ ## Examples
115
+
116
+ - [`examples/integrations/jev`](https://github.com/anteriorai/symbolic-reasoning/tree/master/examples/integrations/jev): an oracle backed by the Jev decision model, which answers a policy's questions from Markdown case files and records the run.
117
+ - [`examples/data`](https://github.com/anteriorai/symbolic-reasoning/tree/master/examples/data): an underwriting policy with an application, and a medical necessity review policy with a synthetic clinical record and a replay.
@@ -0,0 +1,158 @@
1
+ [project]
2
+ name = "symbolic-reasoning"
3
+ version = "0.7.0"
4
+ description = "A Python library for structured reasoning over policies and knowledge to produce deterministic, auditable and explainable outcomes"
5
+ readme = "README.md"
6
+ license = "Apache-2.0"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.12"
9
+ authors = [
10
+ {name = "Anterior, Inc.", email = "tech@anterior.com"},
11
+ ]
12
+ keywords = ["reasoning", "policies", "symbolic", "ai", "decision-making"]
13
+ classifiers = [
14
+ "Development Status :: 3 - Alpha",
15
+ "Intended Audience :: Developers",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.12",
18
+ "Programming Language :: Python :: 3.13",
19
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
20
+ "Topic :: Software Development :: Libraries :: Python Modules",
21
+ "Typing :: Typed",
22
+ ]
23
+ dependencies = [
24
+ "pydantic>=2.10",
25
+ ]
26
+
27
+ [project.urls]
28
+ Homepage = "https://github.com/anteriorai/symbolic-reasoning#readme"
29
+ Repository = "https://github.com/anteriorai/symbolic-reasoning"
30
+ Issues = "https://github.com/anteriorai/symbolic-reasoning/issues"
31
+
32
+ [project.optional-dependencies]
33
+ mcp = [
34
+ "mcp>=2.2,<3",
35
+ ]
36
+
37
+ [build-system]
38
+ requires = ["setuptools>=77.0", "wheel"]
39
+ build-backend = "setuptools.build_meta"
40
+
41
+ [tool.setuptools.packages.find]
42
+ where = ["src"]
43
+
44
+ [tool.setuptools.package-data]
45
+ symbolic_reasoning = ["viewer_assets/*.html", "viewer_assets/*.css", "viewer_assets/*.js", "viewer_assets/vendor/*"]
46
+
47
+ [dependency-groups]
48
+ dev = [
49
+ "pytest>=9.0.0",
50
+ "pytest-cov>=4.0.0",
51
+ "pytest-asyncio>=0.21.0",
52
+ "ruff>=0.1.0",
53
+ "ty>=0.0.85",
54
+ "datamodel-code-generator==0.87.0",
55
+ ]
56
+
57
+ # Ruff configuration for linting and formatting
58
+ [tool.ruff]
59
+ target-version = "py312"
60
+ line-length = 88
61
+ extend-exclude = [
62
+ "*.ipynb",
63
+ "src/symbolic_reasoning/gen", # Generated code - don't lint or format
64
+ ]
65
+
66
+ [tool.ruff.lint]
67
+ select = [
68
+ "E", # pycodestyle errors
69
+ "W", # pycodestyle warnings
70
+ "F", # pyflakes
71
+ "I", # isort
72
+ "B", # flake8-bugbear
73
+ "C4", # flake8-comprehensions
74
+ "UP", # pyupgrade
75
+ "ARG001", # unused-function-args
76
+ "SIM", # flake8-simplify
77
+ "PIE", # flake8-pie
78
+ "A", # flake8-builtins
79
+ "ANN", # flake8-annotations
80
+ "C90", # mccabe
81
+ "ICN", # flake8-import-conventions
82
+ "G", # flake8-logging-format
83
+ "INP", # flake8-no-pep420
84
+ "PTH", # flake8-use-pathlib
85
+ "ERA", # eradicate
86
+ "PD", # pandas-vet
87
+ "PGH", # pygrep-hooks
88
+ "PL", # pylint
89
+ "TRY", # tryceratops
90
+ "FLY", # flynt
91
+ "NPY", # numpy
92
+ "AIR", # airflow
93
+ "PERF", # perflint
94
+ "FURB", # refurb
95
+ "RUF", # ruff-specific rules
96
+ ]
97
+ ignore = [
98
+ "E501", # line too long, handled by black
99
+ "B008", # do not perform function calls in argument defaults
100
+ "C901", # too complex
101
+ "W191", # indentation contains tabs
102
+ "PLR0913", # too many arguments
103
+ "PLR0912", # too many branches
104
+ "PLR0915", # too many statements
105
+ "PLR0911", # too many return statements
106
+ "PLR2004", # magic value used in comparison
107
+ "TRY003", # avoid specifying long messages outside exception class
108
+ "COM812", # trailing comma missing (conflicts with formatter)
109
+ "ANN401", # typing.Any in annotations
110
+ ]
111
+
112
+ [tool.ruff.lint.per-file-ignores]
113
+ "tests/*" = ["PLR2004", "S101", "TID252"]
114
+ "examples/*" = ["INP001"] # standalone scripts, not packages
115
+
116
+ [tool.ruff.lint.isort]
117
+ known-first-party = ["symbolic_reasoning"]
118
+
119
+ [tool.ruff.lint.pylint]
120
+ max-args = 10
121
+
122
+ [tool.ruff.lint.flake8-builtins]
123
+ # Graph symbols are keyed by `id`; builder methods take it by that name.
124
+ builtins-ignorelist = ["id"]
125
+
126
+ # ty configuration
127
+ [tool.ty.analysis]
128
+ allowed-unresolved-imports = [
129
+ "typesafe_sdk.**", # example-only dependency, not installed at the repo root
130
+ ]
131
+
132
+ [tool.ty.rules]
133
+ blanket-ignore-comment = "error"
134
+ dynamic-function-decorator-return = "error"
135
+ redundant-condition-strict = "error"
136
+ unsound-return-statement = "error"
137
+
138
+ # Pytest configuration
139
+ [tool.pytest.ini_options]
140
+ minversion = "8.0"
141
+ addopts = [
142
+ "--strict-markers",
143
+ "--strict-config",
144
+ "--cov=src/symbolic_reasoning",
145
+ "--cov-report=term-missing",
146
+ "--cov-report=html",
147
+ "--cov-report=xml",
148
+ ]
149
+ testpaths = ["tests"]
150
+ python_files = ["test_*.py", "*_test.py"]
151
+ python_classes = ["Test*"]
152
+ python_functions = ["test_*"]
153
+ markers = [
154
+ "slow: marks tests as slow (deselect with '-m \"not slow\"')",
155
+ "integration: marks tests as integration tests",
156
+ "unit: marks tests as unit tests",
157
+ ]
158
+ asyncio_mode = "auto"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+