solidstate-fsm 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.
- solidstate_fsm-0.1.0/LICENSE +201 -0
- solidstate_fsm-0.1.0/PKG-INFO +147 -0
- solidstate_fsm-0.1.0/README.md +125 -0
- solidstate_fsm-0.1.0/pyproject.toml +39 -0
- solidstate_fsm-0.1.0/setup.cfg +4 -0
- solidstate_fsm-0.1.0/src/solidstate/__init__.py +3 -0
- solidstate_fsm-0.1.0/src/solidstate/checkpointing/__init__.py +1 -0
- solidstate_fsm-0.1.0/src/solidstate/checkpointing/base.py +15 -0
- solidstate_fsm-0.1.0/src/solidstate/checkpointing/dynamodb_checkpointer.py +34 -0
- solidstate_fsm-0.1.0/src/solidstate/checkpointing/file_checkpointer.py +36 -0
- solidstate_fsm-0.1.0/src/solidstate/checkpointing/redis_checkpointer.py +30 -0
- solidstate_fsm-0.1.0/src/solidstate/graph.py +161 -0
- solidstate_fsm-0.1.0/src/solidstate/interrupts/__init__.py +1 -0
- solidstate_fsm-0.1.0/src/solidstate/interrupts/approval_manager.py +17 -0
- solidstate_fsm-0.1.0/src/solidstate/interrupts/interrupt_manager.py +17 -0
- solidstate_fsm-0.1.0/src/solidstate/models/__init__.py +1 -0
- solidstate_fsm-0.1.0/src/solidstate/models/base.py +26 -0
- solidstate_fsm-0.1.0/src/solidstate/models/bedrock_model.py +55 -0
- solidstate_fsm-0.1.0/src/solidstate/models/cache.py +30 -0
- solidstate_fsm-0.1.0/src/solidstate/models/fake_model.py +36 -0
- solidstate_fsm-0.1.0/src/solidstate/models/gemini_model.py +82 -0
- solidstate_fsm-0.1.0/src/solidstate/models/ollama_model.py +73 -0
- solidstate_fsm-0.1.0/src/solidstate/models/openai_model.py +78 -0
- solidstate_fsm-0.1.0/src/solidstate/policy/__init__.py +1 -0
- solidstate_fsm-0.1.0/src/solidstate/policy/evaluator.py +20 -0
- solidstate_fsm-0.1.0/src/solidstate/policy/rules.py +10 -0
- solidstate_fsm-0.1.0/src/solidstate/runtime.py +241 -0
- solidstate_fsm-0.1.0/src/solidstate/state/__init__.py +1 -0
- solidstate_fsm-0.1.0/src/solidstate/state/message_store.py +12 -0
- solidstate_fsm-0.1.0/src/solidstate/state/state_store.py +12 -0
- solidstate_fsm-0.1.0/src/solidstate/tools/__init__.py +1 -0
- solidstate_fsm-0.1.0/src/solidstate/tools/executor.py +40 -0
- solidstate_fsm-0.1.0/src/solidstate/tools/registry.py +64 -0
- solidstate_fsm-0.1.0/src/solidstate/tools/schema.py +73 -0
- solidstate_fsm-0.1.0/src/solidstate/tracing/__init__.py +1 -0
- solidstate_fsm-0.1.0/src/solidstate/tracing/audit_log.py +19 -0
- solidstate_fsm-0.1.0/src/solidstate/tracing/cloudwatch_tracer.py +32 -0
- solidstate_fsm-0.1.0/src/solidstate/tracing/tracer.py +23 -0
- solidstate_fsm-0.1.0/src/solidstate/types.py +84 -0
- solidstate_fsm-0.1.0/src/solidstate/utils/__init__.py +1 -0
- solidstate_fsm-0.1.0/src/solidstate/utils/ids.py +5 -0
- solidstate_fsm-0.1.0/src/solidstate/utils/time.py +5 -0
- solidstate_fsm-0.1.0/src/solidstate_fsm.egg-info/PKG-INFO +147 -0
- solidstate_fsm-0.1.0/src/solidstate_fsm.egg-info/SOURCES.txt +52 -0
- solidstate_fsm-0.1.0/src/solidstate_fsm.egg-info/dependency_links.txt +1 -0
- solidstate_fsm-0.1.0/src/solidstate_fsm.egg-info/requires.txt +14 -0
- solidstate_fsm-0.1.0/src/solidstate_fsm.egg-info/top_level.txt +1 -0
- solidstate_fsm-0.1.0/tests/test_checkpoint_resume.py +17 -0
- solidstate_fsm-0.1.0/tests/test_graph.py +108 -0
- solidstate_fsm-0.1.0/tests/test_new_features.py +157 -0
- solidstate_fsm-0.1.0/tests/test_policy_evaluator.py +40 -0
- solidstate_fsm-0.1.0/tests/test_runtime_loop.py +159 -0
- solidstate_fsm-0.1.0/tests/test_tool_registry.py +68 -0
- solidstate_fsm-0.1.0/tests/test_tracing.py +7 -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 tort (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 [yyyy] [name of copyright owner]
|
|
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/LICENSE-2.0
|
|
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,147 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: solidstate-fsm
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A high-reliability, lightweight agent state machine runtime.
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: pydantic>=2.7.0
|
|
9
|
+
Requires-Dist: openai>=1.0.0
|
|
10
|
+
Requires-Dist: google-generativeai>=0.5.0
|
|
11
|
+
Requires-Dist: ollama>=0.2.0
|
|
12
|
+
Requires-Dist: boto3>=1.34.0
|
|
13
|
+
Requires-Dist: redis>=5.0.0
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
16
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
|
|
17
|
+
Requires-Dist: ruff>=0.4.0; extra == "dev"
|
|
18
|
+
Requires-Dist: fastapi>=0.111.0; extra == "dev"
|
|
19
|
+
Requires-Dist: uvicorn>=0.30.0; extra == "dev"
|
|
20
|
+
Requires-Dist: httpx>=0.27.0; extra == "dev"
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
# SolidState
|
|
24
|
+
A high-reliability, lightweight agent state machine runtime.
|
|
25
|
+
|
|
26
|
+
This project maps to the article/PDF proposal:
|
|
27
|
+
|
|
28
|
+
```text
|
|
29
|
+
receive input
|
|
30
|
+
update state
|
|
31
|
+
call model
|
|
32
|
+
parse tool call
|
|
33
|
+
evaluate policy
|
|
34
|
+
execute or interrupt
|
|
35
|
+
update state
|
|
36
|
+
checkpoint
|
|
37
|
+
trace
|
|
38
|
+
continue or finish
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The goal is not to replace LangChain, LangGraph, Semantic Kernel, OpenAI Agents SDK, CrewAI, or AutoGen.
|
|
42
|
+
|
|
43
|
+
The goal is to expose the runtime mechanics clearly.
|
|
44
|
+
|
|
45
|
+
## Core runtime components
|
|
46
|
+
|
|
47
|
+
- **Async & Parallel Execution**: Built for non-blocking I/O with parallel tool execution support.
|
|
48
|
+
- **StateGraph Engine**: A minimal graph-based orchestrator for multi-agent handoffs and complex workflows.
|
|
49
|
+
- **Smart Caching**: Built-in response caching to reduce latency and model costs.
|
|
50
|
+
- **Context Management**: Automatic message history trimming to stay within context limits.
|
|
51
|
+
- **Streaming Ready**: Architecture supports token-by-token streaming for responsive UIs.
|
|
52
|
+
- **Conditional Routing**: Dynamic runtime routing using custom logic functions.
|
|
53
|
+
- **Symbolic Syntax**: Clean, expressive chaining using the `>>` operator.
|
|
54
|
+
- **Visualization**: Built-in support for generating Mermaid diagrams of your workflows.
|
|
55
|
+
- **Multi-Provider**: Adapters for OpenAI, Google Gemini, Anthropic (via AWS Bedrock), and Ollama (local).
|
|
56
|
+
- **AWS Ready**: Built-in support for **Amazon Bedrock** (models) and **Amazon DynamoDB** (persistence).
|
|
57
|
+
- **Cloud Native**: Distributed state via **Redis** and structured observability via **CloudWatch JSON Tracing**.
|
|
58
|
+
- **Message state**: Standardized format for system, user, and assistant/model turns.
|
|
59
|
+
- **Tool registry**: Dynamic function registration with multi-tool support.
|
|
60
|
+
- **Tool schema generator**: Automatic JSON schema generation with Pydantic support.
|
|
61
|
+
- **Policy evaluator**: Extensible rules for tool approval and rejection.
|
|
62
|
+
- **Execution engine**: Robust loop with max-step controls and error handling.
|
|
63
|
+
- **State store/checkpointer**: JSON-based persistence for pause/resume.
|
|
64
|
+
- **Tracing and audit log**: Detailed JSONL logs for every internal decision.
|
|
65
|
+
|
|
66
|
+
## Install
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
python -m venv .venv
|
|
70
|
+
source .venv/bin/activate
|
|
71
|
+
pip install -e ".[dev]"
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Run examples
|
|
75
|
+
|
|
76
|
+
| File | Feature Demonstrated |
|
|
77
|
+
| :--- | :--- |
|
|
78
|
+
| `01_basic_runtime.py` | Simple agent conversation loop. |
|
|
79
|
+
| `02_tool_execution.py` | Tool registration and successful execution. |
|
|
80
|
+
| `03_policy_interrupt.py` | Safety policies and automatic rejections. |
|
|
81
|
+
| `04_resume_after_approval.py` | Human-in-the-loop (Pause & Resume). |
|
|
82
|
+
| `05_credit_review_demo.py` | Real-world banking workflow simulation. |
|
|
83
|
+
| `06_ollama_local_run.py` | Running on 100% local hardware. |
|
|
84
|
+
| `07_multi_agent_graph.py` | Orchestrating multiple specialized agents. |
|
|
85
|
+
| `08_symbolic_chaining.py` | Using the `>>` operator for clean pipelines. |
|
|
86
|
+
| `09_conditional_router.py` | Dynamic routing and Mermaid visualization. |
|
|
87
|
+
| `10_performance_bench.py` | Smart Caching and Context Trimming. |
|
|
88
|
+
| `11_researcher_writer_graph.py` | Complex 3-agent reasoning pipeline. |
|
|
89
|
+
| `12_structured_data_extraction.py` | Pydantic model support for tool arguments. |
|
|
90
|
+
| `13_error_recovery_retry.py` | Self-healing agents (retrying on tool failure). |
|
|
91
|
+
| `14_manual_state_injection.py` | Programmatic state manipulation. |
|
|
92
|
+
| `15_aws_lambda_handler.py` | Deployment template for AWS Lambda + DynamoDB. |
|
|
93
|
+
| `16_distributed_redis_state.py` | Distributed state management using Redis. |
|
|
94
|
+
| `17_cloudwatch_tracing.py` | Structured JSON observability for CloudWatch. |
|
|
95
|
+
| `18_parallel_tool_execution.py` | Concurrent execution of multiple tool calls using asyncio.gather. |
|
|
96
|
+
| `19_multi_threaded_actor_graph.py` | Graph execution in multi-threaded Actor Mode. |
|
|
97
|
+
| `20_token_streaming.py` | Real-time token streaming from the model adapter. |
|
|
98
|
+
|
|
99
|
+
## Project philosophy
|
|
100
|
+
|
|
101
|
+
The model reasons.
|
|
102
|
+
|
|
103
|
+
The runtime controls execution.
|
|
104
|
+
|
|
105
|
+
Every serious agent framework has to answer the same engineering question:
|
|
106
|
+
|
|
107
|
+
> How do we let a probabilistic system participate in deterministic business execution without losing control?
|
|
108
|
+
|
|
109
|
+
## Documentation
|
|
110
|
+
|
|
111
|
+
The framework is documented in 10 chapters, covering the journey from core state machine philosophy to a production-ready concurrent system:
|
|
112
|
+
|
|
113
|
+
1. [**Introduction**](docs/intro.md): Philosophy and core pillars.
|
|
114
|
+
2. [**Chapter 1: Philosophy & The State Machine Pattern**](docs/chapter1_philosophy_state_machine.md): Deterministic control over probabilistic models.
|
|
115
|
+
3. [**Chapter 2: The Core Loop Execution**](docs/chapter2_core_loop_execution.md): Step limits, context trimming, and execution loops.
|
|
116
|
+
4. [**Chapter 3: Message & State Representation**](docs/chapter3_message_state_representation.md): Structuring states, roles, and timestamps.
|
|
117
|
+
5. [**Chapter 4: The Tool Registry & Parameter Introspection**](docs/chapter4_tool_registry_introspection.md): Auto-boxing schemas and execution safety boundaries.
|
|
118
|
+
6. [**Chapter 5: Guardrails, Policies & Human-in-the-Loop**](docs/chapter5_policies_human_in_the_loop.md): Governance, Evaluator decisions, and asymmetric approvals.
|
|
119
|
+
7. [**Chapter 6: Multi-Agent Orchestration & The StateGraph**](docs/chapter6_multi_agent_stategraph.md): Nodes, edges, routers, and symbolic `>>` operator chaining.
|
|
120
|
+
8. [**Chapter 7: Concurrency & The Multi-threaded Actor Model**](docs/chapter7_concurrency_actor_model.md): Multi-threaded queue-based actors and worker threads.
|
|
121
|
+
9. [**Chapter 8: Memory & State Persistence (Checkpointing)**](docs/chapter8_memory_state_persistence.md): BaseCheckpointer contracts, Local files, Redis, and DynamoDB.
|
|
122
|
+
10. [**Chapter 9: Observability, Observational Integrity & Tracing**](docs/chapter9_observability_tracing.md): Auditing decisions, JSONL records, and CloudWatch structures.
|
|
123
|
+
11. [**Chapter 10: Production Performance, Caching & Cloud Serverless**](docs/chapter10_production_performance_cloud.md): Adapters, flyweight caching, and AWS Lambda serverless handlers.
|
|
124
|
+
|
|
125
|
+
## Tests
|
|
126
|
+
|
|
127
|
+
The project includes a robust test suite covering 100% of the core logic:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
pytest
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
| Suite | Focus |
|
|
134
|
+
| :--- | :--- |
|
|
135
|
+
| `test_runtime_loop.py` | Async turn execution and parallel tool calls. |
|
|
136
|
+
| `test_graph.py` | Node transitions and conditional routing. |
|
|
137
|
+
| `test_tool_registry.py` | Pydantic schema generation and autoboxing. |
|
|
138
|
+
| `test_policy_evaluator.py` | Approval/Rejection logic. |
|
|
139
|
+
| `test_checkpoint_resume.py` | Persistence and state recovery. |
|
|
140
|
+
| `test_tracing.py` | Audit log integrity. |
|
|
141
|
+
| `test_new_features.py` | State serialization and adapter mock streaming. |
|
|
142
|
+
|
|
143
|
+
## Contributing & Feedback
|
|
144
|
+
|
|
145
|
+
We welcome contributions! Please feel free to:
|
|
146
|
+
* Report bugs or suggest new features by opening a [GitHub Issue](https://github.com/gavarah/solidstate/issues).
|
|
147
|
+
* Read our [Contributing Guidelines](CONTRIBUTING.md) to set up your local development environment and submit Pull Requests.
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# SolidState
|
|
2
|
+
A high-reliability, lightweight agent state machine runtime.
|
|
3
|
+
|
|
4
|
+
This project maps to the article/PDF proposal:
|
|
5
|
+
|
|
6
|
+
```text
|
|
7
|
+
receive input
|
|
8
|
+
update state
|
|
9
|
+
call model
|
|
10
|
+
parse tool call
|
|
11
|
+
evaluate policy
|
|
12
|
+
execute or interrupt
|
|
13
|
+
update state
|
|
14
|
+
checkpoint
|
|
15
|
+
trace
|
|
16
|
+
continue or finish
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The goal is not to replace LangChain, LangGraph, Semantic Kernel, OpenAI Agents SDK, CrewAI, or AutoGen.
|
|
20
|
+
|
|
21
|
+
The goal is to expose the runtime mechanics clearly.
|
|
22
|
+
|
|
23
|
+
## Core runtime components
|
|
24
|
+
|
|
25
|
+
- **Async & Parallel Execution**: Built for non-blocking I/O with parallel tool execution support.
|
|
26
|
+
- **StateGraph Engine**: A minimal graph-based orchestrator for multi-agent handoffs and complex workflows.
|
|
27
|
+
- **Smart Caching**: Built-in response caching to reduce latency and model costs.
|
|
28
|
+
- **Context Management**: Automatic message history trimming to stay within context limits.
|
|
29
|
+
- **Streaming Ready**: Architecture supports token-by-token streaming for responsive UIs.
|
|
30
|
+
- **Conditional Routing**: Dynamic runtime routing using custom logic functions.
|
|
31
|
+
- **Symbolic Syntax**: Clean, expressive chaining using the `>>` operator.
|
|
32
|
+
- **Visualization**: Built-in support for generating Mermaid diagrams of your workflows.
|
|
33
|
+
- **Multi-Provider**: Adapters for OpenAI, Google Gemini, Anthropic (via AWS Bedrock), and Ollama (local).
|
|
34
|
+
- **AWS Ready**: Built-in support for **Amazon Bedrock** (models) and **Amazon DynamoDB** (persistence).
|
|
35
|
+
- **Cloud Native**: Distributed state via **Redis** and structured observability via **CloudWatch JSON Tracing**.
|
|
36
|
+
- **Message state**: Standardized format for system, user, and assistant/model turns.
|
|
37
|
+
- **Tool registry**: Dynamic function registration with multi-tool support.
|
|
38
|
+
- **Tool schema generator**: Automatic JSON schema generation with Pydantic support.
|
|
39
|
+
- **Policy evaluator**: Extensible rules for tool approval and rejection.
|
|
40
|
+
- **Execution engine**: Robust loop with max-step controls and error handling.
|
|
41
|
+
- **State store/checkpointer**: JSON-based persistence for pause/resume.
|
|
42
|
+
- **Tracing and audit log**: Detailed JSONL logs for every internal decision.
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
python -m venv .venv
|
|
48
|
+
source .venv/bin/activate
|
|
49
|
+
pip install -e ".[dev]"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Run examples
|
|
53
|
+
|
|
54
|
+
| File | Feature Demonstrated |
|
|
55
|
+
| :--- | :--- |
|
|
56
|
+
| `01_basic_runtime.py` | Simple agent conversation loop. |
|
|
57
|
+
| `02_tool_execution.py` | Tool registration and successful execution. |
|
|
58
|
+
| `03_policy_interrupt.py` | Safety policies and automatic rejections. |
|
|
59
|
+
| `04_resume_after_approval.py` | Human-in-the-loop (Pause & Resume). |
|
|
60
|
+
| `05_credit_review_demo.py` | Real-world banking workflow simulation. |
|
|
61
|
+
| `06_ollama_local_run.py` | Running on 100% local hardware. |
|
|
62
|
+
| `07_multi_agent_graph.py` | Orchestrating multiple specialized agents. |
|
|
63
|
+
| `08_symbolic_chaining.py` | Using the `>>` operator for clean pipelines. |
|
|
64
|
+
| `09_conditional_router.py` | Dynamic routing and Mermaid visualization. |
|
|
65
|
+
| `10_performance_bench.py` | Smart Caching and Context Trimming. |
|
|
66
|
+
| `11_researcher_writer_graph.py` | Complex 3-agent reasoning pipeline. |
|
|
67
|
+
| `12_structured_data_extraction.py` | Pydantic model support for tool arguments. |
|
|
68
|
+
| `13_error_recovery_retry.py` | Self-healing agents (retrying on tool failure). |
|
|
69
|
+
| `14_manual_state_injection.py` | Programmatic state manipulation. |
|
|
70
|
+
| `15_aws_lambda_handler.py` | Deployment template for AWS Lambda + DynamoDB. |
|
|
71
|
+
| `16_distributed_redis_state.py` | Distributed state management using Redis. |
|
|
72
|
+
| `17_cloudwatch_tracing.py` | Structured JSON observability for CloudWatch. |
|
|
73
|
+
| `18_parallel_tool_execution.py` | Concurrent execution of multiple tool calls using asyncio.gather. |
|
|
74
|
+
| `19_multi_threaded_actor_graph.py` | Graph execution in multi-threaded Actor Mode. |
|
|
75
|
+
| `20_token_streaming.py` | Real-time token streaming from the model adapter. |
|
|
76
|
+
|
|
77
|
+
## Project philosophy
|
|
78
|
+
|
|
79
|
+
The model reasons.
|
|
80
|
+
|
|
81
|
+
The runtime controls execution.
|
|
82
|
+
|
|
83
|
+
Every serious agent framework has to answer the same engineering question:
|
|
84
|
+
|
|
85
|
+
> How do we let a probabilistic system participate in deterministic business execution without losing control?
|
|
86
|
+
|
|
87
|
+
## Documentation
|
|
88
|
+
|
|
89
|
+
The framework is documented in 10 chapters, covering the journey from core state machine philosophy to a production-ready concurrent system:
|
|
90
|
+
|
|
91
|
+
1. [**Introduction**](docs/intro.md): Philosophy and core pillars.
|
|
92
|
+
2. [**Chapter 1: Philosophy & The State Machine Pattern**](docs/chapter1_philosophy_state_machine.md): Deterministic control over probabilistic models.
|
|
93
|
+
3. [**Chapter 2: The Core Loop Execution**](docs/chapter2_core_loop_execution.md): Step limits, context trimming, and execution loops.
|
|
94
|
+
4. [**Chapter 3: Message & State Representation**](docs/chapter3_message_state_representation.md): Structuring states, roles, and timestamps.
|
|
95
|
+
5. [**Chapter 4: The Tool Registry & Parameter Introspection**](docs/chapter4_tool_registry_introspection.md): Auto-boxing schemas and execution safety boundaries.
|
|
96
|
+
6. [**Chapter 5: Guardrails, Policies & Human-in-the-Loop**](docs/chapter5_policies_human_in_the_loop.md): Governance, Evaluator decisions, and asymmetric approvals.
|
|
97
|
+
7. [**Chapter 6: Multi-Agent Orchestration & The StateGraph**](docs/chapter6_multi_agent_stategraph.md): Nodes, edges, routers, and symbolic `>>` operator chaining.
|
|
98
|
+
8. [**Chapter 7: Concurrency & The Multi-threaded Actor Model**](docs/chapter7_concurrency_actor_model.md): Multi-threaded queue-based actors and worker threads.
|
|
99
|
+
9. [**Chapter 8: Memory & State Persistence (Checkpointing)**](docs/chapter8_memory_state_persistence.md): BaseCheckpointer contracts, Local files, Redis, and DynamoDB.
|
|
100
|
+
10. [**Chapter 9: Observability, Observational Integrity & Tracing**](docs/chapter9_observability_tracing.md): Auditing decisions, JSONL records, and CloudWatch structures.
|
|
101
|
+
11. [**Chapter 10: Production Performance, Caching & Cloud Serverless**](docs/chapter10_production_performance_cloud.md): Adapters, flyweight caching, and AWS Lambda serverless handlers.
|
|
102
|
+
|
|
103
|
+
## Tests
|
|
104
|
+
|
|
105
|
+
The project includes a robust test suite covering 100% of the core logic:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
pytest
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
| Suite | Focus |
|
|
112
|
+
| :--- | :--- |
|
|
113
|
+
| `test_runtime_loop.py` | Async turn execution and parallel tool calls. |
|
|
114
|
+
| `test_graph.py` | Node transitions and conditional routing. |
|
|
115
|
+
| `test_tool_registry.py` | Pydantic schema generation and autoboxing. |
|
|
116
|
+
| `test_policy_evaluator.py` | Approval/Rejection logic. |
|
|
117
|
+
| `test_checkpoint_resume.py` | Persistence and state recovery. |
|
|
118
|
+
| `test_tracing.py` | Audit log integrity. |
|
|
119
|
+
| `test_new_features.py` | State serialization and adapter mock streaming. |
|
|
120
|
+
|
|
121
|
+
## Contributing & Feedback
|
|
122
|
+
|
|
123
|
+
We welcome contributions! Please feel free to:
|
|
124
|
+
* Report bugs or suggest new features by opening a [GitHub Issue](https://github.com/gavarah/solidstate/issues).
|
|
125
|
+
* Read our [Contributing Guidelines](CONTRIBUTING.md) to set up your local development environment and submit Pull Requests.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "solidstate-fsm"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
readme = "README.md"
|
|
5
|
+
description = "A high-reliability, lightweight agent state machine runtime."
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"pydantic>=2.7.0",
|
|
9
|
+
"openai>=1.0.0",
|
|
10
|
+
"google-generativeai>=0.5.0",
|
|
11
|
+
"ollama>=0.2.0",
|
|
12
|
+
"boto3>=1.34.0",
|
|
13
|
+
"redis>=5.0.0",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[project.optional-dependencies]
|
|
17
|
+
dev = [
|
|
18
|
+
"pytest>=8.0.0",
|
|
19
|
+
"pytest-asyncio>=0.23.0",
|
|
20
|
+
"ruff>=0.4.0",
|
|
21
|
+
"fastapi>=0.111.0",
|
|
22
|
+
"uvicorn>=0.30.0",
|
|
23
|
+
"httpx>=0.27.0",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[tool.pytest.ini_options]
|
|
27
|
+
testpaths = ["tests"]
|
|
28
|
+
pythonpath = ["src"]
|
|
29
|
+
|
|
30
|
+
[tool.ruff]
|
|
31
|
+
line-length = 100
|
|
32
|
+
target-version = "py310"
|
|
33
|
+
|
|
34
|
+
[build-system]
|
|
35
|
+
requires = ["setuptools>=61.0.0", "wheel"]
|
|
36
|
+
build-backend = "setuptools.build_meta"
|
|
37
|
+
|
|
38
|
+
[tool.setuptools.packages.find]
|
|
39
|
+
where = ["src"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
|
|
5
|
+
from solidstate.types import RuntimeState
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Checkpointer(ABC):
|
|
9
|
+
@abstractmethod
|
|
10
|
+
async def save(self, state: RuntimeState) -> None:
|
|
11
|
+
raise NotImplementedError
|
|
12
|
+
|
|
13
|
+
@abstractmethod
|
|
14
|
+
async def load(self, run_id: str) -> RuntimeState:
|
|
15
|
+
raise NotImplementedError
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import boto3
|
|
3
|
+
import asyncio
|
|
4
|
+
from solidstate.checkpointing.base import Checkpointer
|
|
5
|
+
from solidstate.types import RuntimeState
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class DynamoDBCheckpointer(Checkpointer):
|
|
9
|
+
"""AWS-ready checkpointer using Amazon DynamoDB."""
|
|
10
|
+
|
|
11
|
+
def __init__(self, table_name: str, region_name: str = "us-east-1"):
|
|
12
|
+
self.table_name = table_name
|
|
13
|
+
self.dynamodb = boto3.resource("dynamodb", region_name=region_name)
|
|
14
|
+
self.table = self.dynamodb.Table(table_name)
|
|
15
|
+
|
|
16
|
+
async def save(self, state: RuntimeState) -> None:
|
|
17
|
+
data = state.to_dict()
|
|
18
|
+
# Convert to JSON for storage to avoid DynamoDB type issues with deep nested objects
|
|
19
|
+
item = {
|
|
20
|
+
"run_id": state.run_id,
|
|
21
|
+
"status": state.status,
|
|
22
|
+
"state_json": json.dumps(data),
|
|
23
|
+
"updated_at": state.created_at # Using existing timestamp for now
|
|
24
|
+
}
|
|
25
|
+
await asyncio.to_thread(self.table.put_item, Item=item)
|
|
26
|
+
|
|
27
|
+
async def load(self, run_id: str) -> RuntimeState:
|
|
28
|
+
response = await asyncio.to_thread(self.table.get_item, Key={"run_id": run_id})
|
|
29
|
+
item = response.get("Item")
|
|
30
|
+
if not item:
|
|
31
|
+
raise ValueError(f"No state found for run_id: {run_id}")
|
|
32
|
+
|
|
33
|
+
data = json.loads(item["state_json"])
|
|
34
|
+
return RuntimeState.from_dict(data)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import json
|
|
3
|
+
from dataclasses import asdict
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from solidstate.checkpointing.base import Checkpointer
|
|
7
|
+
from solidstate.types import Message, RuntimeState, ToolCall, ToolResult
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class FileCheckpointer(Checkpointer):
|
|
11
|
+
def __init__(self, directory: str = ".checkpoints"):
|
|
12
|
+
self.directory = Path(directory)
|
|
13
|
+
self.directory.mkdir(parents=True, exist_ok=True)
|
|
14
|
+
|
|
15
|
+
async def save(self, state: RuntimeState) -> None:
|
|
16
|
+
path = self.directory / f"{state.run_id}.json"
|
|
17
|
+
data = asdict(state)
|
|
18
|
+
await asyncio.to_thread(path.write_text, json.dumps(data, indent=2), encoding="utf-8")
|
|
19
|
+
|
|
20
|
+
async def load(self, run_id: str) -> RuntimeState:
|
|
21
|
+
path = self.directory / f"{run_id}.json"
|
|
22
|
+
if not path.exists():
|
|
23
|
+
raise FileNotFoundError(f"No checkpoint found for run_id: {run_id}")
|
|
24
|
+
|
|
25
|
+
content = await asyncio.to_thread(path.read_text, encoding="utf-8")
|
|
26
|
+
raw = json.loads(content)
|
|
27
|
+
|
|
28
|
+
return RuntimeState(
|
|
29
|
+
run_id=raw["run_id"],
|
|
30
|
+
messages=[Message(**m) for m in raw["messages"]],
|
|
31
|
+
status=raw["status"],
|
|
32
|
+
tool_results=[ToolResult(**r) for r in raw.get("tool_results", [])],
|
|
33
|
+
pending_approvals=[ToolCall(**a) for a in raw.get("pending_approvals", [])],
|
|
34
|
+
metadata=raw.get("metadata", {}),
|
|
35
|
+
created_at=raw.get("created_at", ""),
|
|
36
|
+
)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import redis
|
|
3
|
+
import asyncio
|
|
4
|
+
from solidstate.checkpointing.base import Checkpointer
|
|
5
|
+
from solidstate.types import RuntimeState
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class RedisCheckpointer(Checkpointer):
|
|
9
|
+
"""Distributed, high-performance checkpointer using Redis."""
|
|
10
|
+
|
|
11
|
+
def __init__(self, host: str = "localhost", port: int = 6379, db: int = 0, password: str | None = None):
|
|
12
|
+
self.client = redis.Redis(host=host, port=port, db=db, password=password, decode_responses=True)
|
|
13
|
+
|
|
14
|
+
async def save(self, state: RuntimeState) -> None:
|
|
15
|
+
data = state.to_dict()
|
|
16
|
+
# Set with expiration (e.g., 24 hours) to keep Redis clean
|
|
17
|
+
await asyncio.to_thread(
|
|
18
|
+
self.client.setex,
|
|
19
|
+
f"state:{state.run_id}",
|
|
20
|
+
86400,
|
|
21
|
+
json.dumps(data)
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
async def load(self, run_id: str) -> RuntimeState:
|
|
25
|
+
data_json = await asyncio.to_thread(self.client.get, f"state:{run_id}")
|
|
26
|
+
if not data_json:
|
|
27
|
+
raise ValueError(f"No state found in Redis for run_id: {run_id}")
|
|
28
|
+
|
|
29
|
+
data = json.loads(data_json)
|
|
30
|
+
return RuntimeState.from_dict(data)
|