Metadata-Version: 2.4
Name: semantic-action-grammar
Version: 1.0.1
Summary: Semantic Action Grammar — a DSL for structured inter-agent communication, with parsing, validation, correlation, and fold-based context compression.
Project-URL: Homepage, https://github.com/phrocker/sag
Project-URL: Repository, https://github.com/phrocker/sag
Project-URL: Issues, https://github.com/phrocker/sag/issues
Author-email: Marc Parisi <marc.parisi@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Marc Parisi
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: agent,antlr,dsl,grammar,llm,multi-agent,sag
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Compilers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Requires-Dist: antlr4-python3-runtime==4.13.1
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Provides-Extra: publish
Requires-Dist: build>=1.0; extra == 'publish'
Requires-Dist: twine>=5.0; extra == 'publish'
Description-Content-Type: text/markdown

# semantic-action-grammar

Semantic Action Grammar (SAG) — a DSL for structured inter-agent communication.

SAG provides parsing, schema validation, correlation, sanitization, and a
grammar-level fold/unfold protocol for context compression. This package is
the Python implementation; the canonical grammar lives in the
[main repository](https://github.com/phrocker/sag).

## Install

```bash
pip install semantic-action-grammar
```

The Python import name is `sag`:

```python
from sag import SAGMessageParser
```

## Quick start

```python
from sag import SAGMessageParser, MessageMinifier

parser = SAGMessageParser()
message = parser.parse('[id=1 src=A dst=B] DO deploy("app1", version=42) BECAUSE balance>1000;')

print(message.header.id)          # "1"
print(message.statements[0].verb) # "deploy"

# Re-serialize to the compact wire format
print(MessageMinifier().minify(message))
```

## What's in the box

- **Parser** — `SAGMessageParser`, ANTLR4-backed
- **Schema validation** — `SchemaRegistry`, `VerbSchema`, `SchemaValidator`
- **Guardrails** — `BECAUSE`-clause expressions evaluated against a `Context`
- **Sanitizer** — four-layer firewall (parse → routing → schema → guardrail)
- **Fold protocol** — `FoldEngine` for lossless conversation compression
- **Knowledge engine** — versioned topic-based fact propagation
- **Tree / Grove** — multi-agent topology and bottom-up orchestration
- **Accounting** — token and cost tracking for grove executions

See the main repository for benchmarks, the chatbot demo, and the full
specification.

## License

MIT — see `LICENSE`.
