agent-alerts 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.
- agent_alerts-0.1.0/LICENSE +21 -0
- agent_alerts-0.1.0/PKG-INFO +161 -0
- agent_alerts-0.1.0/README.md +143 -0
- agent_alerts-0.1.0/pyproject.toml +33 -0
- agent_alerts-0.1.0/setup.cfg +4 -0
- agent_alerts-0.1.0/src/agent_alerts.egg-info/PKG-INFO +161 -0
- agent_alerts-0.1.0/src/agent_alerts.egg-info/SOURCES.txt +26 -0
- agent_alerts-0.1.0/src/agent_alerts.egg-info/dependency_links.txt +1 -0
- agent_alerts-0.1.0/src/agent_alerts.egg-info/entry_points.txt +2 -0
- agent_alerts-0.1.0/src/agent_alerts.egg-info/requires.txt +10 -0
- agent_alerts-0.1.0/src/agent_alerts.egg-info/top_level.txt +1 -0
- agent_alerts-0.1.0/src/alerts/__init__.py +110 -0
- agent_alerts-0.1.0/src/alerts/channels/__init__.py +14 -0
- agent_alerts-0.1.0/src/alerts/channels/agent.py +178 -0
- agent_alerts-0.1.0/src/alerts/channels/base.py +16 -0
- agent_alerts-0.1.0/src/alerts/channels/email.py +85 -0
- agent_alerts-0.1.0/src/alerts/channels/imessage.py +119 -0
- agent_alerts-0.1.0/src/alerts/channels/telegram.py +62 -0
- agent_alerts-0.1.0/src/alerts/config.py +203 -0
- agent_alerts-0.1.0/src/alerts/evaluator.py +205 -0
- agent_alerts-0.1.0/src/alerts/feedback.py +39 -0
- agent_alerts-0.1.0/src/alerts/gateway_client.py +221 -0
- agent_alerts-0.1.0/src/alerts/mcp_server.py +61 -0
- agent_alerts-0.1.0/src/alerts/models.py +67 -0
- agent_alerts-0.1.0/src/alerts/prompt_builder.py +60 -0
- agent_alerts-0.1.0/src/alerts/quiet_hours.py +61 -0
- agent_alerts-0.1.0/src/alerts/rate_limiter.py +36 -0
- agent_alerts-0.1.0/src/alerts/router.py +121 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Henry Chien LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-alerts
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Structured alert routing to humans and AI agents
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/henrychien/agent-alerts
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: PyYAML>=6.0
|
|
11
|
+
Provides-Extra: mcp
|
|
12
|
+
Requires-Dist: fastmcp>=0.1.0; extra == "mcp"
|
|
13
|
+
Provides-Extra: agent
|
|
14
|
+
Requires-Dist: httpx>=0.27.0; extra == "agent"
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: pytest; extra == "dev"
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# agent-alerts
|
|
20
|
+
|
|
21
|
+
Structured alert routing to humans and AI agents.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install agent-alerts
|
|
27
|
+
pip install "agent-alerts[mcp]"
|
|
28
|
+
pip install "agent-alerts[agent]"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Python imports stay under `alerts`.
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
Send a simple alert directly to Telegram:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from alerts import send
|
|
39
|
+
|
|
40
|
+
send("Screen complete: 4 names passed", channel="telegram")
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
That reads `TELEGRAM_BOT_TOKEN` and `TELEGRAM_CHAT_ID` from your environment unless you pass `token=` and `chat_id=` explicitly.
|
|
44
|
+
|
|
45
|
+
Use `AlertRouter` for structured routing, thresholds, quiet hours, and agent follow-up:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from alerts import Alert, AlertCategory, AlertLevel, AlertRouter
|
|
49
|
+
|
|
50
|
+
router = AlertRouter(config_path="alerting.yaml")
|
|
51
|
+
|
|
52
|
+
result = router.send(
|
|
53
|
+
Alert(
|
|
54
|
+
title="Estimate revisions turning negative",
|
|
55
|
+
body="NVDA revisions rolled over after guidance.",
|
|
56
|
+
level=AlertLevel.HIGH,
|
|
57
|
+
category=AlertCategory.SIGNAL,
|
|
58
|
+
source="portfolio-system",
|
|
59
|
+
source_type="estimate_revisions",
|
|
60
|
+
metadata={"passed_count": 1},
|
|
61
|
+
)
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
print(result.delivered_channels)
|
|
65
|
+
print(result.agent_dispatched)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Channels
|
|
69
|
+
|
|
70
|
+
| Channel | Purpose | Required config |
|
|
71
|
+
| --- | --- | --- |
|
|
72
|
+
| `telegram` | Fast human notification | `TELEGRAM_BOT_TOKEN`, `TELEGRAM_CHAT_ID` |
|
|
73
|
+
| `imessage` | Local macOS delivery | `IMESSAGE_TARGET` or `channels.imessage.recipient`; optional `backend`, `service` |
|
|
74
|
+
| `email` | SMTP delivery | `smtp_host`, `smtp_port`, `from`, `to` plus `EMAIL_USERNAME`, `EMAIL_PASSWORD` |
|
|
75
|
+
| `agent` | Background agent analysis with human feedback | `gateway_url`, `gateway_api_key_env`; optional `model`, `feedback_channel` |
|
|
76
|
+
|
|
77
|
+
## Router Config
|
|
78
|
+
|
|
79
|
+
Example `alerting.yaml`:
|
|
80
|
+
|
|
81
|
+
```yaml
|
|
82
|
+
schema_version: 2
|
|
83
|
+
on_config_error: use_last_good
|
|
84
|
+
|
|
85
|
+
channels:
|
|
86
|
+
telegram:
|
|
87
|
+
enabled: true
|
|
88
|
+
imessage:
|
|
89
|
+
enabled: false
|
|
90
|
+
recipient: "+15555551212"
|
|
91
|
+
backend: applescript
|
|
92
|
+
email:
|
|
93
|
+
enabled: false
|
|
94
|
+
smtp_host: smtp.gmail.com
|
|
95
|
+
smtp_port: 587
|
|
96
|
+
from: alerts@example.com
|
|
97
|
+
to:
|
|
98
|
+
- user@example.com
|
|
99
|
+
agent:
|
|
100
|
+
enabled: true
|
|
101
|
+
gateway_url: "http://127.0.0.1:8002"
|
|
102
|
+
gateway_api_key_env: "ALERTS_GATEWAY_API_KEY"
|
|
103
|
+
model: "claude-sonnet-4-6"
|
|
104
|
+
feedback_channel: telegram
|
|
105
|
+
|
|
106
|
+
routing:
|
|
107
|
+
critical: [telegram, agent]
|
|
108
|
+
high: [telegram, agent]
|
|
109
|
+
normal: [telegram]
|
|
110
|
+
low: []
|
|
111
|
+
by_category:
|
|
112
|
+
signal:
|
|
113
|
+
critical: [telegram, agent]
|
|
114
|
+
screen_result:
|
|
115
|
+
high: [telegram, agent]
|
|
116
|
+
|
|
117
|
+
quiet_hours:
|
|
118
|
+
enabled: true
|
|
119
|
+
start: "22:00"
|
|
120
|
+
end: "07:00"
|
|
121
|
+
timezone: "America/New_York"
|
|
122
|
+
per_channel:
|
|
123
|
+
agent:
|
|
124
|
+
enabled: false
|
|
125
|
+
|
|
126
|
+
rate_limits:
|
|
127
|
+
enabled: true
|
|
128
|
+
global_max_per_hour: 20
|
|
129
|
+
agent_max_per_hour: 5
|
|
130
|
+
|
|
131
|
+
thresholds:
|
|
132
|
+
_default:
|
|
133
|
+
min_passed_count: 1
|
|
134
|
+
default_level: normal
|
|
135
|
+
max_per_hour: 3
|
|
136
|
+
estimate_revisions:
|
|
137
|
+
min_passed_count: 1
|
|
138
|
+
level_rules:
|
|
139
|
+
- when:
|
|
140
|
+
passed_count_gte: 3
|
|
141
|
+
level: critical
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## MCP Server
|
|
145
|
+
|
|
146
|
+
The package exposes an MCP server entry point:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
alerts-mcp
|
|
150
|
+
python -m alerts.mcp_server
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
It provides three tools:
|
|
154
|
+
|
|
155
|
+
- `notify_send`
|
|
156
|
+
- `notify_list_channels`
|
|
157
|
+
- `notify_test_channel`
|
|
158
|
+
|
|
159
|
+
## License
|
|
160
|
+
|
|
161
|
+
MIT
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# agent-alerts
|
|
2
|
+
|
|
3
|
+
Structured alert routing to humans and AI agents.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install agent-alerts
|
|
9
|
+
pip install "agent-alerts[mcp]"
|
|
10
|
+
pip install "agent-alerts[agent]"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Python imports stay under `alerts`.
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
Send a simple alert directly to Telegram:
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from alerts import send
|
|
21
|
+
|
|
22
|
+
send("Screen complete: 4 names passed", channel="telegram")
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
That reads `TELEGRAM_BOT_TOKEN` and `TELEGRAM_CHAT_ID` from your environment unless you pass `token=` and `chat_id=` explicitly.
|
|
26
|
+
|
|
27
|
+
Use `AlertRouter` for structured routing, thresholds, quiet hours, and agent follow-up:
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from alerts import Alert, AlertCategory, AlertLevel, AlertRouter
|
|
31
|
+
|
|
32
|
+
router = AlertRouter(config_path="alerting.yaml")
|
|
33
|
+
|
|
34
|
+
result = router.send(
|
|
35
|
+
Alert(
|
|
36
|
+
title="Estimate revisions turning negative",
|
|
37
|
+
body="NVDA revisions rolled over after guidance.",
|
|
38
|
+
level=AlertLevel.HIGH,
|
|
39
|
+
category=AlertCategory.SIGNAL,
|
|
40
|
+
source="portfolio-system",
|
|
41
|
+
source_type="estimate_revisions",
|
|
42
|
+
metadata={"passed_count": 1},
|
|
43
|
+
)
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
print(result.delivered_channels)
|
|
47
|
+
print(result.agent_dispatched)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Channels
|
|
51
|
+
|
|
52
|
+
| Channel | Purpose | Required config |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| `telegram` | Fast human notification | `TELEGRAM_BOT_TOKEN`, `TELEGRAM_CHAT_ID` |
|
|
55
|
+
| `imessage` | Local macOS delivery | `IMESSAGE_TARGET` or `channels.imessage.recipient`; optional `backend`, `service` |
|
|
56
|
+
| `email` | SMTP delivery | `smtp_host`, `smtp_port`, `from`, `to` plus `EMAIL_USERNAME`, `EMAIL_PASSWORD` |
|
|
57
|
+
| `agent` | Background agent analysis with human feedback | `gateway_url`, `gateway_api_key_env`; optional `model`, `feedback_channel` |
|
|
58
|
+
|
|
59
|
+
## Router Config
|
|
60
|
+
|
|
61
|
+
Example `alerting.yaml`:
|
|
62
|
+
|
|
63
|
+
```yaml
|
|
64
|
+
schema_version: 2
|
|
65
|
+
on_config_error: use_last_good
|
|
66
|
+
|
|
67
|
+
channels:
|
|
68
|
+
telegram:
|
|
69
|
+
enabled: true
|
|
70
|
+
imessage:
|
|
71
|
+
enabled: false
|
|
72
|
+
recipient: "+15555551212"
|
|
73
|
+
backend: applescript
|
|
74
|
+
email:
|
|
75
|
+
enabled: false
|
|
76
|
+
smtp_host: smtp.gmail.com
|
|
77
|
+
smtp_port: 587
|
|
78
|
+
from: alerts@example.com
|
|
79
|
+
to:
|
|
80
|
+
- user@example.com
|
|
81
|
+
agent:
|
|
82
|
+
enabled: true
|
|
83
|
+
gateway_url: "http://127.0.0.1:8002"
|
|
84
|
+
gateway_api_key_env: "ALERTS_GATEWAY_API_KEY"
|
|
85
|
+
model: "claude-sonnet-4-6"
|
|
86
|
+
feedback_channel: telegram
|
|
87
|
+
|
|
88
|
+
routing:
|
|
89
|
+
critical: [telegram, agent]
|
|
90
|
+
high: [telegram, agent]
|
|
91
|
+
normal: [telegram]
|
|
92
|
+
low: []
|
|
93
|
+
by_category:
|
|
94
|
+
signal:
|
|
95
|
+
critical: [telegram, agent]
|
|
96
|
+
screen_result:
|
|
97
|
+
high: [telegram, agent]
|
|
98
|
+
|
|
99
|
+
quiet_hours:
|
|
100
|
+
enabled: true
|
|
101
|
+
start: "22:00"
|
|
102
|
+
end: "07:00"
|
|
103
|
+
timezone: "America/New_York"
|
|
104
|
+
per_channel:
|
|
105
|
+
agent:
|
|
106
|
+
enabled: false
|
|
107
|
+
|
|
108
|
+
rate_limits:
|
|
109
|
+
enabled: true
|
|
110
|
+
global_max_per_hour: 20
|
|
111
|
+
agent_max_per_hour: 5
|
|
112
|
+
|
|
113
|
+
thresholds:
|
|
114
|
+
_default:
|
|
115
|
+
min_passed_count: 1
|
|
116
|
+
default_level: normal
|
|
117
|
+
max_per_hour: 3
|
|
118
|
+
estimate_revisions:
|
|
119
|
+
min_passed_count: 1
|
|
120
|
+
level_rules:
|
|
121
|
+
- when:
|
|
122
|
+
passed_count_gte: 3
|
|
123
|
+
level: critical
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## MCP Server
|
|
127
|
+
|
|
128
|
+
The package exposes an MCP server entry point:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
alerts-mcp
|
|
132
|
+
python -m alerts.mcp_server
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
It provides three tools:
|
|
136
|
+
|
|
137
|
+
- `notify_send`
|
|
138
|
+
- `notify_list_channels`
|
|
139
|
+
- `notify_test_channel`
|
|
140
|
+
|
|
141
|
+
## License
|
|
142
|
+
|
|
143
|
+
MIT
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "agent-alerts"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Structured alert routing to humans and AI agents"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
requires-python = ">=3.10"
|
|
8
|
+
dependencies = ["PyYAML>=6.0"]
|
|
9
|
+
|
|
10
|
+
[project.optional-dependencies]
|
|
11
|
+
mcp = ["fastmcp>=0.1.0"]
|
|
12
|
+
agent = ["httpx>=0.27.0"]
|
|
13
|
+
dev = ["pytest"]
|
|
14
|
+
|
|
15
|
+
[project.urls]
|
|
16
|
+
Homepage = "https://github.com/henrychien/agent-alerts"
|
|
17
|
+
|
|
18
|
+
[project.scripts]
|
|
19
|
+
alerts-mcp = "alerts.mcp_server:main"
|
|
20
|
+
|
|
21
|
+
[build-system]
|
|
22
|
+
requires = ["setuptools>=68", "wheel"]
|
|
23
|
+
build-backend = "setuptools.build_meta"
|
|
24
|
+
|
|
25
|
+
[tool.setuptools.packages.find]
|
|
26
|
+
where = ["src"]
|
|
27
|
+
include = ["alerts*"]
|
|
28
|
+
exclude = ["alerts.tests"]
|
|
29
|
+
|
|
30
|
+
[tool.pytest.ini_options]
|
|
31
|
+
testpaths = ["src/alerts/tests"]
|
|
32
|
+
python_files = ["test_*.py"]
|
|
33
|
+
addopts = ["-ra", "--tb=short"]
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-alerts
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Structured alert routing to humans and AI agents
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/henrychien/agent-alerts
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: PyYAML>=6.0
|
|
11
|
+
Provides-Extra: mcp
|
|
12
|
+
Requires-Dist: fastmcp>=0.1.0; extra == "mcp"
|
|
13
|
+
Provides-Extra: agent
|
|
14
|
+
Requires-Dist: httpx>=0.27.0; extra == "agent"
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: pytest; extra == "dev"
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# agent-alerts
|
|
20
|
+
|
|
21
|
+
Structured alert routing to humans and AI agents.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install agent-alerts
|
|
27
|
+
pip install "agent-alerts[mcp]"
|
|
28
|
+
pip install "agent-alerts[agent]"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Python imports stay under `alerts`.
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
Send a simple alert directly to Telegram:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from alerts import send
|
|
39
|
+
|
|
40
|
+
send("Screen complete: 4 names passed", channel="telegram")
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
That reads `TELEGRAM_BOT_TOKEN` and `TELEGRAM_CHAT_ID` from your environment unless you pass `token=` and `chat_id=` explicitly.
|
|
44
|
+
|
|
45
|
+
Use `AlertRouter` for structured routing, thresholds, quiet hours, and agent follow-up:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from alerts import Alert, AlertCategory, AlertLevel, AlertRouter
|
|
49
|
+
|
|
50
|
+
router = AlertRouter(config_path="alerting.yaml")
|
|
51
|
+
|
|
52
|
+
result = router.send(
|
|
53
|
+
Alert(
|
|
54
|
+
title="Estimate revisions turning negative",
|
|
55
|
+
body="NVDA revisions rolled over after guidance.",
|
|
56
|
+
level=AlertLevel.HIGH,
|
|
57
|
+
category=AlertCategory.SIGNAL,
|
|
58
|
+
source="portfolio-system",
|
|
59
|
+
source_type="estimate_revisions",
|
|
60
|
+
metadata={"passed_count": 1},
|
|
61
|
+
)
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
print(result.delivered_channels)
|
|
65
|
+
print(result.agent_dispatched)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Channels
|
|
69
|
+
|
|
70
|
+
| Channel | Purpose | Required config |
|
|
71
|
+
| --- | --- | --- |
|
|
72
|
+
| `telegram` | Fast human notification | `TELEGRAM_BOT_TOKEN`, `TELEGRAM_CHAT_ID` |
|
|
73
|
+
| `imessage` | Local macOS delivery | `IMESSAGE_TARGET` or `channels.imessage.recipient`; optional `backend`, `service` |
|
|
74
|
+
| `email` | SMTP delivery | `smtp_host`, `smtp_port`, `from`, `to` plus `EMAIL_USERNAME`, `EMAIL_PASSWORD` |
|
|
75
|
+
| `agent` | Background agent analysis with human feedback | `gateway_url`, `gateway_api_key_env`; optional `model`, `feedback_channel` |
|
|
76
|
+
|
|
77
|
+
## Router Config
|
|
78
|
+
|
|
79
|
+
Example `alerting.yaml`:
|
|
80
|
+
|
|
81
|
+
```yaml
|
|
82
|
+
schema_version: 2
|
|
83
|
+
on_config_error: use_last_good
|
|
84
|
+
|
|
85
|
+
channels:
|
|
86
|
+
telegram:
|
|
87
|
+
enabled: true
|
|
88
|
+
imessage:
|
|
89
|
+
enabled: false
|
|
90
|
+
recipient: "+15555551212"
|
|
91
|
+
backend: applescript
|
|
92
|
+
email:
|
|
93
|
+
enabled: false
|
|
94
|
+
smtp_host: smtp.gmail.com
|
|
95
|
+
smtp_port: 587
|
|
96
|
+
from: alerts@example.com
|
|
97
|
+
to:
|
|
98
|
+
- user@example.com
|
|
99
|
+
agent:
|
|
100
|
+
enabled: true
|
|
101
|
+
gateway_url: "http://127.0.0.1:8002"
|
|
102
|
+
gateway_api_key_env: "ALERTS_GATEWAY_API_KEY"
|
|
103
|
+
model: "claude-sonnet-4-6"
|
|
104
|
+
feedback_channel: telegram
|
|
105
|
+
|
|
106
|
+
routing:
|
|
107
|
+
critical: [telegram, agent]
|
|
108
|
+
high: [telegram, agent]
|
|
109
|
+
normal: [telegram]
|
|
110
|
+
low: []
|
|
111
|
+
by_category:
|
|
112
|
+
signal:
|
|
113
|
+
critical: [telegram, agent]
|
|
114
|
+
screen_result:
|
|
115
|
+
high: [telegram, agent]
|
|
116
|
+
|
|
117
|
+
quiet_hours:
|
|
118
|
+
enabled: true
|
|
119
|
+
start: "22:00"
|
|
120
|
+
end: "07:00"
|
|
121
|
+
timezone: "America/New_York"
|
|
122
|
+
per_channel:
|
|
123
|
+
agent:
|
|
124
|
+
enabled: false
|
|
125
|
+
|
|
126
|
+
rate_limits:
|
|
127
|
+
enabled: true
|
|
128
|
+
global_max_per_hour: 20
|
|
129
|
+
agent_max_per_hour: 5
|
|
130
|
+
|
|
131
|
+
thresholds:
|
|
132
|
+
_default:
|
|
133
|
+
min_passed_count: 1
|
|
134
|
+
default_level: normal
|
|
135
|
+
max_per_hour: 3
|
|
136
|
+
estimate_revisions:
|
|
137
|
+
min_passed_count: 1
|
|
138
|
+
level_rules:
|
|
139
|
+
- when:
|
|
140
|
+
passed_count_gte: 3
|
|
141
|
+
level: critical
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## MCP Server
|
|
145
|
+
|
|
146
|
+
The package exposes an MCP server entry point:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
alerts-mcp
|
|
150
|
+
python -m alerts.mcp_server
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
It provides three tools:
|
|
154
|
+
|
|
155
|
+
- `notify_send`
|
|
156
|
+
- `notify_list_channels`
|
|
157
|
+
- `notify_test_channel`
|
|
158
|
+
|
|
159
|
+
## License
|
|
160
|
+
|
|
161
|
+
MIT
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/agent_alerts.egg-info/PKG-INFO
|
|
5
|
+
src/agent_alerts.egg-info/SOURCES.txt
|
|
6
|
+
src/agent_alerts.egg-info/dependency_links.txt
|
|
7
|
+
src/agent_alerts.egg-info/entry_points.txt
|
|
8
|
+
src/agent_alerts.egg-info/requires.txt
|
|
9
|
+
src/agent_alerts.egg-info/top_level.txt
|
|
10
|
+
src/alerts/__init__.py
|
|
11
|
+
src/alerts/config.py
|
|
12
|
+
src/alerts/evaluator.py
|
|
13
|
+
src/alerts/feedback.py
|
|
14
|
+
src/alerts/gateway_client.py
|
|
15
|
+
src/alerts/mcp_server.py
|
|
16
|
+
src/alerts/models.py
|
|
17
|
+
src/alerts/prompt_builder.py
|
|
18
|
+
src/alerts/quiet_hours.py
|
|
19
|
+
src/alerts/rate_limiter.py
|
|
20
|
+
src/alerts/router.py
|
|
21
|
+
src/alerts/channels/__init__.py
|
|
22
|
+
src/alerts/channels/agent.py
|
|
23
|
+
src/alerts/channels/base.py
|
|
24
|
+
src/alerts/channels/email.py
|
|
25
|
+
src/alerts/channels/imessage.py
|
|
26
|
+
src/alerts/channels/telegram.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
alerts
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Any, Mapping
|
|
5
|
+
|
|
6
|
+
from .channels.email import send_email
|
|
7
|
+
from .channels.imessage import send_imessage
|
|
8
|
+
from .channels.telegram import send_telegram
|
|
9
|
+
from .config import _load_dotenv, get_imessage_target, get_telegram_config
|
|
10
|
+
from .evaluator import AlertDecision, AlertEvaluator
|
|
11
|
+
from .models import Alert, AlertCategory, AlertLevel, AlertResult, coerce_alert_category, coerce_alert_level
|
|
12
|
+
from .router import AlertRouter, DEFAULT_CONFIG_PATH
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def send(message: str, channel: str = "telegram", **kwargs) -> dict | bool:
|
|
16
|
+
env = _resolve_env(kwargs.pop("env", None), kwargs.pop("env_file", None))
|
|
17
|
+
|
|
18
|
+
if channel == "telegram":
|
|
19
|
+
token = kwargs.pop("token", None)
|
|
20
|
+
chat_id = kwargs.pop("chat_id", None)
|
|
21
|
+
if not token or not chat_id:
|
|
22
|
+
env_token, env_chat_id = get_telegram_config(env)
|
|
23
|
+
token = token or env_token
|
|
24
|
+
chat_id = chat_id or env_chat_id
|
|
25
|
+
return send_telegram(message, token, chat_id, **kwargs)
|
|
26
|
+
|
|
27
|
+
if channel == "imessage":
|
|
28
|
+
target = kwargs.pop("target", None) or get_imessage_target(env)
|
|
29
|
+
service = kwargs.pop("service", "imessage")
|
|
30
|
+
backend = kwargs.pop("backend", None)
|
|
31
|
+
return send_imessage(message, target, service=service, backend=backend)
|
|
32
|
+
|
|
33
|
+
if channel == "email":
|
|
34
|
+
channel_config = kwargs.pop("channel_config", None)
|
|
35
|
+
return send_email(message, channel_config=channel_config, env=env)
|
|
36
|
+
|
|
37
|
+
raise ValueError(f"Unknown channel: {channel}")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def send_alert(
|
|
41
|
+
alert: Alert,
|
|
42
|
+
*,
|
|
43
|
+
router: AlertRouter | None = None,
|
|
44
|
+
config_path: str | Path | None = None,
|
|
45
|
+
env_file: str | Path | None = None,
|
|
46
|
+
env: Mapping[str, str] | None = None,
|
|
47
|
+
) -> AlertResult:
|
|
48
|
+
active_router = router or AlertRouter(config_path=_require_config_path(config_path), env_file=env_file, env=env)
|
|
49
|
+
return active_router.send(alert)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def send_alert_message(
|
|
53
|
+
message: str,
|
|
54
|
+
*,
|
|
55
|
+
title: str = "",
|
|
56
|
+
level: AlertLevel | str = AlertLevel.NORMAL,
|
|
57
|
+
category: AlertCategory | str = AlertCategory.CUSTOM,
|
|
58
|
+
source: str = "",
|
|
59
|
+
source_type: str = "",
|
|
60
|
+
metadata: dict[str, Any] | None = None,
|
|
61
|
+
channel: str | None = None,
|
|
62
|
+
router: AlertRouter | None = None,
|
|
63
|
+
config_path: str | Path | None = None,
|
|
64
|
+
env_file: str | Path | None = None,
|
|
65
|
+
env: Mapping[str, str] | None = None,
|
|
66
|
+
) -> AlertResult:
|
|
67
|
+
alert = Alert(
|
|
68
|
+
title=title,
|
|
69
|
+
body=message,
|
|
70
|
+
level=coerce_alert_level(level),
|
|
71
|
+
category=coerce_alert_category(category),
|
|
72
|
+
source=source,
|
|
73
|
+
source_type=source_type,
|
|
74
|
+
metadata=dict(metadata or {}),
|
|
75
|
+
)
|
|
76
|
+
active_router = router or AlertRouter(config_path=_require_config_path(config_path), env_file=env_file, env=env)
|
|
77
|
+
if channel:
|
|
78
|
+
return active_router.send_channel(alert, channel=channel, level=alert.level)
|
|
79
|
+
return active_router.send(alert)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _resolve_env(env: Mapping[str, str] | None, env_file: str | Path | None) -> Mapping[str, str] | None:
|
|
83
|
+
if env is not None:
|
|
84
|
+
return dict(env)
|
|
85
|
+
if env_file is not None:
|
|
86
|
+
return _load_dotenv(env_file)
|
|
87
|
+
return None
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _require_config_path(config_path: str | Path | None) -> str | Path:
|
|
91
|
+
return config_path or DEFAULT_CONFIG_PATH
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
__all__ = [
|
|
95
|
+
"Alert",
|
|
96
|
+
"AlertCategory",
|
|
97
|
+
"AlertDecision",
|
|
98
|
+
"AlertEvaluator",
|
|
99
|
+
"AlertLevel",
|
|
100
|
+
"AlertResult",
|
|
101
|
+
"AlertRouter",
|
|
102
|
+
"get_imessage_target",
|
|
103
|
+
"get_telegram_config",
|
|
104
|
+
"send",
|
|
105
|
+
"send_alert",
|
|
106
|
+
"send_alert_message",
|
|
107
|
+
"send_email",
|
|
108
|
+
"send_imessage",
|
|
109
|
+
"send_telegram",
|
|
110
|
+
]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from .base import ChannelAdapter
|
|
2
|
+
from .email import EmailChannel, send_email
|
|
3
|
+
from .imessage import IMessageChannel, send_imessage
|
|
4
|
+
from .telegram import TelegramChannel, send_telegram
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"ChannelAdapter",
|
|
8
|
+
"EmailChannel",
|
|
9
|
+
"IMessageChannel",
|
|
10
|
+
"TelegramChannel",
|
|
11
|
+
"send_email",
|
|
12
|
+
"send_imessage",
|
|
13
|
+
"send_telegram",
|
|
14
|
+
]
|