An open API service indexing awesome lists of open source software.

https://github.com/tb8412/qae-langgraph-example

QAE safety certification integrated into LangGraph agent workflows — certify tool calls before execution
https://github.com/tb8412/qae-langgraph-example

agent-framework ai-agents ai-safety autonomous-agents certification deterministic langchain langgraph python qae risk-management safety tool-use

Last synced: 22 days ago
JSON representation

QAE safety certification integrated into LangGraph agent workflows — certify tool calls before execution

Awesome Lists containing this project

README

          

# QAE + LangGraph: Certified Agent Actions

Add deterministic safety certification to LangGraph agent workflows. This example demonstrates how to integrate the QAE safety kernel into a multi-step agent pipeline, certifying tool calls before execution and blocking/escalating unsafe actions.

## Architecture

```
Agent State Graph

Propose Tool Call (LLM)

QAE Certification Node
├─→ Extract state deltas from tool call
├─→ Run through SafetyCertifier
└─→ Decision: Certified / CertifiedWithWarning / EscalateToHuman / Blocked

Execute Tool (or pause/reject)

Observe → Loop or Complete
```

## Quick Start

1. **Install dependencies:**

```bash
pip install -r requirements.txt
```

2. **Run the basic certified agent example:**

```bash
python -m src.certified_agent
```

Expected output: Agent proposes a tool call, QAE certifies it, and displays the certificate decision.

3. **Run the custom domain adapter example:**

```bash
python -m src.custom_domain_example
```

Demonstrates how to create domain-specific constraint channels.

## What's Inside

- **`src/certified_agent.py`** — LangGraph state graph with QAE certification node
- **`src/custom_domain_example.py`** — Custom DomainAdapter and ConstraintChannel subclasses
- **`requirements.txt`** — Python dependencies

## Key Concepts

### SafetyCertifier

Stateful certifier wrapping a DomainAdapter:

```python
from qae_safety import AgenticAdapter, SafetyCertifier, SimpleAction, StateDelta

adapter = AgenticAdapter(budget_limit=100.0, rate_limit=50.0)
certifier = SafetyCertifier(adapter)

action = SimpleAction(
action_id="tool-call-1",
agent_id="agent-1",
state_deltas=[
StateDelta(dimension="scope_score", from_value=1.0, to_value=0.8),
]
)

cert = certifier.certify(action)
print(f"Decision: {cert.decision}")
print(f"Zone: {cert.zone}")
print(f"Margins: {cert.margins}")
```

### Decision Zones

| Margin Range | Zone | Decision | Action |
|-------------|------|----------|--------|
| > 0.6 | Safe | Certified | Execute immediately |
| (0.3, 0.6] | Caution | CertifiedWithWarning | Execute with logs/warnings |
| (0.1, 0.3] | Danger | EscalateToHuman | Pause for human review |
| ≤ 0.1 | Danger | Blocked | Reject |

### Custom Domain Adapters

Extend the safety kernel for your domain:

```python
from qae_safety import DomainAdapter, ConstraintChannel

class MyConstraint(ConstraintChannel):
def name(self):
return "my_constraint"

def evaluate(self, state):
# Return margin in [0, 1]
return 0.75

def dimension_names(self):
return ["my_dimension"]

class MyAdapter(DomainAdapter):
def domain_name(self):
return "my_domain"

def constraint_channels(self):
return [MyConstraint()]

def map_action_to_state(self, action):
return [1.0]

def detect_regime_change(self, current, proposed):
return False
```

## Research

For the theory behind QAE, see:

- **Paper**: "Deterministic Portfolio Risk Certification" (DOI: [10.6084/m9.figshare.31742857](https://doi.org/10.6084/m9.figshare.31742857))
- **Website**: [qaesubstrate.com](https://qaesubstrate.com)

## License

This example is provided as part of the QAE project. See `LICENSE` in the root repository.