Skip to content

100+ AI Agents, Agent Skills and RAG Apps - Free and Open Source.

Add Gmail delivery to HN briefing agent

Shubhamsabooca3a3d374386
diff --git a/always_on_agents/always_on_hn_briefing_agent/README.md b/always_on_agents/always_on_hn_briefing_agent/README.md
index 41fb511b..1b37582f 100644
--- a/always_on_agents/always_on_hn_briefing_agent/README.md
+++ b/always_on_agents/always_on_hn_briefing_agent/README.md
@@ -2,9 +2,9 @@
AgentScout is an always-on Hacker News briefing agent built with Google ADK. It scans Hacker News for high-signal stories about AI agents, MCP, coding agents, workflow automation, and LLM apps, then turns the best links into a concise engineering brief.
-The app can run as an interactive ADK agent or as a scheduled backend service. Use ADK Web to ask for a brief manually, or run the FastAPI scheduler hook so Cloud Scheduler can trigger a daily Hacker News briefing and send the rendered payload to email, Slack, Linear, Jira, or an internal digest workflow.
+The app can run as an interactive ADK agent or as a scheduled backend service. Use ADK Web to ask for a brief manually, or run the FastAPI scheduler hook so Cloud Scheduler can trigger a daily Hacker News briefing and send it through Gmail, Slack, Linear, Jira, or an internal digest workflow.
-![Always-on Hacker News Briefing Agent architecture](assets/agent-scout-architecture.svg)
+![Always-on Hacker News Briefing Agent architecture](assets/always-on-hn-briefing-agent.png)
## Features
@@ -13,7 +13,8 @@ The app can run as an interactive ADK agent or as a scheduled backend service. U
- **Brief generation**: Produces a clean text and HTML briefing with summaries, links, and next actions.
- **Google ADK agent**: Exposes a `root_agent` so users can request briefs in ADK Web.
- **Scheduler-ready backend**: Includes HTTP and Pub/Sub endpoints for Cloud Scheduler or other automation systems.
-- **Safe delivery flow**: Defaults to dry-run mode and only posts to a webhook when `dry_run=false`.
+- **Gmail and webhook delivery**: Sends briefs through Gmail API or a generic webhook when `dry_run=false`.
+- **Safe delivery flow**: Defaults to dry-run mode and skips delivery unless credentials are explicitly configured.
## How It Works
@@ -22,13 +23,14 @@ The app can run as an interactive ADK agent or as a scheduled backend service. U
3. It ranks the most useful stories for engineers and product builders.
4. It renders a daily briefing in text and HTML.
5. ADK Web, an HTTP trigger, or a Pub/Sub push endpoint returns the result.
-6. If delivery is enabled, the scheduler API posts the brief to `AGENTSCOUT_WEBHOOK_URL`.
+6. If delivery is enabled, the scheduler API sends the brief through Gmail or posts it to `AGENTSCOUT_WEBHOOK_URL`.
## Requirements
- Python 3.10+
-- Gemini API key for Google ADK
-- Optional webhook URL for scheduled delivery
+- Gemini API key for ADK Web
+- Optional Gmail OAuth credentials for direct email delivery
+- Optional webhook URL for Slack, Linear, Jira, GitHub Issues, SendGrid, or internal workflows
## Installation
@@ -39,7 +41,9 @@ pip install -r requirements.txt
export GOOGLE_API_KEY="your_gemini_api_key"
```
-## Run in ADK Web
+## Option 1: Run in ADK Web
+
+Use ADK Web when you want to chat with the agent and ask for a brief manually.
```bash
adk web .
@@ -61,7 +65,9 @@ Scout the top 3 Hacker News stories about AI agents and LLM apps.
Show me the highest-signal Hacker News items about MCP, coding agents, and workflow automation.
```
-## Run the Scheduler API
+## Option 2: Run the Scheduler API Locally
+
+Use the scheduler API when you want AgentScout to run like an always-on backend service. This is the same surface you can deploy behind Cloud Run and trigger from Cloud Scheduler.
Start the scheduler backend:
@@ -69,13 +75,13 @@ Start the scheduler backend:
uvicorn scheduler_api:app --host 0.0.0.0 --port 8000
```
-Preview a scheduled run without delivery:
+In another terminal, preview a scheduled run without delivery:
```bash
curl "http://127.0.0.1:8000/agent-scout/dry-run?top_n=3&live=false"
```
-Trigger the scheduler path:
+Trigger the scheduler path in dry-run mode:
```bash
curl -X POST "http://127.0.0.1:8000/agent-scout/trigger" \
@@ -83,15 +89,57 @@ curl -X POST "http://127.0.0.1:8000/agent-scout/trigger" \
-d '{"dry_run": true, "top_n": 5, "live": false}'
```
-Enable live Hacker News scanning:
+Dry-run mode returns the rendered brief and delivery status, but it does not send anything.
+
+Enable live Hacker News scanning for the current process:
```bash
export AGENTSCOUT_LIVE_HN=true
```
-Enable webhook delivery:
+You can also override live mode per request:
```bash
+curl -X POST "http://127.0.0.1:8000/agent-scout/trigger" \
+ -H "Content-Type: application/json" \
+ -d '{"dry_run": true, "top_n": 5, "live": true}'
+```
+
+## Option 3: Enable Scheduled Delivery
+
+Delivery is opt-in. AgentScout will not send email or call a webhook unless the request body includes `"dry_run": false` and one delivery method is configured.
+
+Delivery mode behavior:
+
+- `AGENTSCOUT_DELIVERY=gmail` sends through Gmail API.
+- `AGENTSCOUT_DELIVERY=webhook` posts to `AGENTSCOUT_WEBHOOK_URL`.
+- If `AGENTSCOUT_DELIVERY` is not set, AgentScout uses Gmail when Gmail is fully configured, otherwise webhook when a webhook URL is configured.
+
+### Gmail Delivery
+
+Use Gmail when you want AgentScout to send the daily brief directly to an inbox. Create a Google OAuth client with Gmail API access, generate a refresh token with the `https://www.googleapis.com/auth/gmail.send` scope, then set:
+
+```bash
+export AGENTSCOUT_DELIVERY="gmail"
+export AGENTSCOUT_EMAIL_TO="[email protected]"
+export AGENTSCOUT_EMAIL_FROM="[email protected]"
+export AGENTSCOUT_GMAIL_CLIENT_ID="your_google_oauth_client_id"
+export AGENTSCOUT_GMAIL_CLIENT_SECRET="your_google_oauth_client_secret"
+export AGENTSCOUT_GMAIL_REFRESH_TOKEN="your_gmail_refresh_token"
+
+curl -X POST "http://127.0.0.1:8000/agent-scout/trigger" \
+ -H "Content-Type: application/json" \
+ -d '{"dry_run": false, "top_n": 5, "live": true}'
+```
+
+AgentScout sends a multipart email with both plain text and HTML versions of the brief.
+
+### Webhook Delivery
+
+Use webhook delivery when you want to route the brief to Slack, Linear, Jira, GitHub Issues, SendGrid, or your own internal workflow.
+
+```bash
+export AGENTSCOUT_DELIVERY="webhook"
export AGENTSCOUT_WEBHOOK_URL="https://example.com/agent-brief-webhook"
export AGENTSCOUT_WEBHOOK_TOKEN="optional_bearer_token"
@@ -104,7 +152,7 @@ The webhook receives `subject`, `text`, `html`, `stories`, and `next_actions`.
## Cloud Scheduler Hook
-Deploy the scheduler API behind Cloud Run or another HTTP service, then call one of these endpoints from Cloud Scheduler.
+Deploy the scheduler API behind Cloud Run or another HTTP service, configure Gmail or webhook delivery in that environment, then call one of these endpoints from Cloud Scheduler.
Direct HTTP trigger:
@@ -122,6 +170,8 @@ Request body:
}
```
+Set `dry_run` to `true` while testing the schedule. Set it to `false` only after Gmail or webhook delivery is configured.
+
Recommended weekday briefing schedule:
```text
diff --git a/always_on_agents/always_on_hn_briefing_agent/assets/agent-scout-architecture.svg b/always_on_agents/always_on_hn_briefing_agent/assets/agent-scout-architecture.svg
deleted file mode 100644
index b0dda890..00000000
--- a/always_on_agents/always_on_hn_briefing_agent/assets/agent-scout-architecture.svg
+++ /dev/null
@@ -1,139 +0,0 @@
-<svg width="1600" height="900" viewBox="0 0 1600 900" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-labelledby="title desc">
- <title id="title">Always-on Hacker News Briefing Agent architecture</title>
- <desc id="desc">A left-to-right architecture image showing Hacker News stories flowing into AgentScout, then filtering, ranking, briefing, and webhook delivery.</desc>
- <defs>
- <linearGradient id="bg" x1="0" y1="0" x2="1600" y2="900" gradientUnits="userSpaceOnUse">
- <stop stop-color="#111827"/>
- <stop offset="0.48" stop-color="#171717"/>
- <stop offset="1" stop-color="#2A160C"/>
- </linearGradient>
- <linearGradient id="orange" x1="0" y1="0" x2="1" y2="1">
- <stop stop-color="#FF8A00"/>
- <stop offset="1" stop-color="#FF5C00"/>
- </linearGradient>
- <linearGradient id="teal" x1="0" y1="0" x2="1" y2="1">
- <stop stop-color="#6EE7B7"/>
- <stop offset="1" stop-color="#22D3EE"/>
- </linearGradient>
- <filter id="shadow" x="-20%" y="-20%" width="140%" height="140%">
- <feDropShadow dx="0" dy="24" stdDeviation="24" flood-color="#000000" flood-opacity="0.32"/>
- </filter>
- <filter id="softGlow" x="-50%" y="-50%" width="200%" height="200%">
- <feGaussianBlur stdDeviation="20" result="blur"/>
- <feColorMatrix in="blur" type="matrix" values="1 0 0 0 1 0 0.32 0 0 0.42 0 0 0 0 0.08 0 0 0 1 0"/>
- </filter>
- <style>
- .label { font: 700 32px Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; fill: #F8FAFC; }
- .small { font: 600 20px Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; fill: #CBD5E1; }
- .tiny { font: 500 16px Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; fill: #94A3B8; }
- .mono { font: 600 18px ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; fill: #FED7AA; }
- .stroke { stroke: rgba(255,255,255,0.12); }
- </style>
- </defs>
-
- <rect width="1600" height="900" fill="url(#bg)"/>
- <circle cx="1340" cy="140" r="260" fill="#FF6B00" opacity="0.08" filter="url(#softGlow)"/>
- <circle cx="230" cy="780" r="280" fill="#22D3EE" opacity="0.06" filter="url(#softGlow)"/>
- <path d="M0 710C220 650 430 705 640 650C890 585 1100 570 1600 645V900H0V710Z" fill="#FFFFFF" opacity="0.035"/>
-
- <text x="92" y="98" class="label">Always-on Hacker News Briefing Agent</text>
- <text x="94" y="136" class="small">AgentScout scans Hacker News, ranks AI agent signals, and ships a daily engineering brief.</text>
-
- <g transform="translate(82 236)" filter="url(#shadow)">
- <rect width="250" height="350" rx="26" fill="#151A23" class="stroke"/>
- <rect x="22" y="22" width="64" height="64" rx="14" fill="url(#orange)"/>
- <text x="39" y="64" font-family="Inter, Arial, sans-serif" font-size="30" font-weight="800" fill="white">HN</text>
- <text x="104" y="50" class="small">Hacker News</text>
- <text x="104" y="78" class="tiny">live front page</text>
- <g transform="translate(22 120)">
- <rect width="206" height="54" rx="12" fill="#202938"/>
- <circle cx="23" cy="27" r="7" fill="#FF8A00"/>
- <text x="44" y="25" class="tiny">AI agent framework</text>
- <text x="44" y="43" class="tiny">428 pts · 116 comments</text>
- </g>
- <g transform="translate(22 190)">
- <rect width="206" height="54" rx="12" fill="#202938"/>
- <circle cx="23" cy="27" r="7" fill="#22D3EE"/>
- <text x="44" y="25" class="tiny">MCP tools</text>
- <text x="44" y="43" class="tiny">312 pts · 84 comments</text>
- </g>
- <g transform="translate(22 260)">
- <rect width="206" height="54" rx="12" fill="#202938"/>
- <circle cx="23" cy="27" r="7" fill="#A78BFA"/>
- <text x="44" y="25" class="tiny">Coding agents</text>
- <text x="44" y="43" class="tiny">256 pts · 73 comments</text>
- </g>
- </g>
-
- <g transform="translate(407 284)">
- <path d="M0 127H112" stroke="#64748B" stroke-width="3" stroke-linecap="round"/>
- <path d="M96 111L112 127L96 143" stroke="#64748B" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
- <text x="12" y="100" class="tiny">scheduled scan</text>
- </g>
-
- <g transform="translate(530 236)" filter="url(#shadow)">
- <rect width="300" height="350" rx="30" fill="#111827" stroke="rgba(255,255,255,0.14)"/>
- <circle cx="150" cy="104" r="58" fill="url(#teal)" opacity="0.18"/>
- <circle cx="150" cy="104" r="36" fill="#0F172A" stroke="#67E8F9" stroke-width="3"/>
- <path d="M133 106L146 119L169 87" stroke="#67E8F9" stroke-width="7" stroke-linecap="round" stroke-linejoin="round"/>
- <text x="72" y="196" class="label">AgentScout</text>
- <text x="48" y="232" class="small">Google ADK root_agent</text>
- <rect x="42" y="268" width="216" height="46" rx="13" fill="#1F2937"/>
- <text x="62" y="298" class="mono">preview_agent_builder_brief</text>
- </g>
-
- <g transform="translate(878 284)">
- <path d="M0 127H106" stroke="#64748B" stroke-width="3" stroke-linecap="round"/>
- <path d="M90 111L106 127L90 143" stroke="#64748B" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
- <text x="0" y="100" class="tiny">briefing pipeline</text>
- </g>
-
- <g transform="translate(1010 202)" filter="url(#shadow)">
- <rect width="250" height="186" rx="24" fill="#172033" stroke="rgba(255,255,255,0.13)"/>
- <text x="32" y="52" class="small">Filter + Rank</text>
- <rect x="32" y="82" width="184" height="14" rx="7" fill="#334155"/>
- <rect x="32" y="112" width="128" height="14" rx="7" fill="#334155"/>
- <rect x="32" y="142" width="160" height="14" rx="7" fill="#334155"/>
- <circle cx="205" cy="112" r="32" fill="#FF8A00" opacity="0.18"/>
- <path d="M191 113L202 124L221 96" stroke="#FDBA74" stroke-width="6" stroke-linecap="round" stroke-linejoin="round"/>
- </g>
-
- <g transform="translate(1010 438)" filter="url(#shadow)">
- <rect width="250" height="186" rx="24" fill="#172033" stroke="rgba(255,255,255,0.13)"/>
- <text x="32" y="52" class="small">Text + HTML Brief</text>
- <rect x="32" y="82" width="186" height="14" rx="7" fill="#334155"/>
- <rect x="32" y="112" width="154" height="14" rx="7" fill="#334155"/>
- <rect x="32" y="142" width="112" height="14" rx="7" fill="#334155"/>
- <path d="M199 79H222V156H177V101L199 79Z" fill="#0F172A" stroke="#67E8F9" stroke-width="2"/>
- <path d="M199 79V101H222" stroke="#67E8F9" stroke-width="2"/>
- </g>
-
- <g transform="translate(1304 334)">
- <path d="M0 113H82" stroke="#64748B" stroke-width="3" stroke-linecap="round"/>
- <path d="M66 97L82 113L66 129" stroke="#64748B" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
- <text x="-8" y="86" class="tiny">dry_run=false</text>
- </g>
-
- <g transform="translate(1402 276)" filter="url(#shadow)">
- <rect width="142" height="260" rx="26" fill="#151A23" stroke="rgba(255,255,255,0.14)"/>
- <text x="30" y="52" class="small">Delivery</text>
- <g transform="translate(34 86)">
- <rect width="74" height="34" rx="10" fill="#202938"/>
- <text x="21" y="23" class="tiny">Email</text>
- </g>
- <g transform="translate(34 132)">
- <rect width="74" height="34" rx="10" fill="#202938"/>
- <text x="22" y="23" class="tiny">Slack</text>
- </g>
- <g transform="translate(34 178)">
- <rect width="74" height="34" rx="10" fill="#202938"/>
- <text x="18" y="23" class="tiny">Tickets</text>
- </g>
- </g>
-
- <g transform="translate(92 688)">
- <rect width="1350" height="92" rx="24" fill="rgba(15,23,42,0.72)" stroke="rgba(255,255,255,0.12)"/>
- <text x="30" y="38" class="small">Scheduler-ready hooks</text>
- <text x="30" y="68" class="tiny">GET /agent-scout/dry-run · POST /agent-scout/trigger · POST /agent-scout/pubsub · AGENTSCOUT_WEBHOOK_URL</text>
- </g>
-</svg>
diff --git a/always_on_agents/always_on_hn_briefing_agent/assets/always-on-hn-briefing-agent.png b/always_on_agents/always_on_hn_briefing_agent/assets/always-on-hn-briefing-agent.png
new file mode 100644
index 00000000..55002b35
Binary files /dev/null and b/always_on_agents/always_on_hn_briefing_agent/assets/always-on-hn-briefing-agent.png differ
diff --git a/always_on_agents/always_on_hn_briefing_agent/delivery.py b/always_on_agents/always_on_hn_briefing_agent/delivery.py
index 8234c1c3..83509dd5 100644
--- a/always_on_agents/always_on_hn_briefing_agent/delivery.py
+++ b/always_on_agents/always_on_hn_briefing_agent/delivery.py
@@ -2,13 +2,140 @@
from __future__ import annotations
+import base64
import json
import os
import urllib.error
+import urllib.parse
import urllib.request
+from email.message import EmailMessage
from typing import Any
+GMAIL_REQUIRED_ENV = [
+ "AGENTSCOUT_EMAIL_TO",
+ "AGENTSCOUT_EMAIL_FROM",
+ "AGENTSCOUT_GMAIL_CLIENT_ID",
+ "AGENTSCOUT_GMAIL_CLIENT_SECRET",
+ "AGENTSCOUT_GMAIL_REFRESH_TOKEN",
+]
+
+
+def send_brief(payload: dict[str, Any]) -> dict[str, Any]:
+ """Send a rendered brief through Gmail or a webhook.
+
+ Delivery is intentionally opt-in. If AGENTSCOUT_DELIVERY is unset, Gmail is
+ preferred when fully configured, then webhook delivery, then a skipped status.
+ """
+
+ delivery_mode = os.environ.get("AGENTSCOUT_DELIVERY", "auto").lower()
+ if delivery_mode == "gmail":
+ return send_gmail(payload)
+ if delivery_mode == "webhook":
+ return send_webhook(payload)
+ if _gmail_configured():
+ return send_gmail(payload)
+ if os.environ.get("AGENTSCOUT_WEBHOOK_URL"):
+ return send_webhook(payload)
+ return {
+ "configured": False,
+ "sent": False,
+ "status": "skipped_no_delivery",
+ "detail": (
+ "Set Gmail environment variables or AGENTSCOUT_WEBHOOK_URL to deliver "
+ "scheduled briefs."
+ ),
+ }
+
+
+def _gmail_configured() -> bool:
+ return all(os.environ.get(name) for name in GMAIL_REQUIRED_ENV)
+
+
+def _missing_gmail_config() -> list[str]:
+ return [name for name in GMAIL_REQUIRED_ENV if not os.environ.get(name)]
+
+
+def _fetch_gmail_access_token() -> str:
+ request = urllib.request.Request(
+ "https://oauth2.googleapis.com/token",
+ data=urllib.parse.urlencode(
+ {
+ "client_id": os.environ["AGENTSCOUT_GMAIL_CLIENT_ID"],
+ "client_secret": os.environ["AGENTSCOUT_GMAIL_CLIENT_SECRET"],
+ "refresh_token": os.environ["AGENTSCOUT_GMAIL_REFRESH_TOKEN"],
+ "grant_type": "refresh_token",
+ }
+ ).encode("utf-8"),
+ headers={"Content-Type": "application/x-www-form-urlencoded"},
+ method="POST",
+ )
+ with urllib.request.urlopen(request, timeout=20) as response:
+ token_payload = json.loads(response.read().decode("utf-8"))
+ return str(token_payload["access_token"])
+
+
+def send_gmail(payload: dict[str, Any]) -> dict[str, Any]:
+ """Send the rendered brief through the Gmail API."""
+
+ missing = _missing_gmail_config()
+ if missing:
+ return {
+ "provider": "gmail",
+ "configured": False,
+ "sent": False,
+ "status": "skipped_missing_gmail_config",
+ "missing": missing,
+ }
+
+ try:
+ access_token = _fetch_gmail_access_token()
+ message = EmailMessage()
+ message["To"] = os.environ["AGENTSCOUT_EMAIL_TO"]
+ message["From"] = os.environ["AGENTSCOUT_EMAIL_FROM"]
+ message["Subject"] = payload["subject"]
+ message.set_content(payload["text"])
+ message.add_alternative(payload["html"], subtype="html")
+
+ encoded_message = base64.urlsafe_b64encode(message.as_bytes()).decode("ascii")
+ request = urllib.request.Request(
+ "https://gmail.googleapis.com/gmail/v1/users/me/messages/send",
+ data=json.dumps({"raw": encoded_message}).encode("utf-8"),
+ headers={
+ "Authorization": f"Bearer {access_token}",
+ "Content-Type": "application/json",
+ },
+ method="POST",
+ )
+ with urllib.request.urlopen(request, timeout=20) as response:
+ response_payload = json.loads(response.read().decode("utf-8"))
+ return {
+ "provider": "gmail",
+ "configured": True,
+ "sent": True,
+ "status": "sent",
+ "message_id": response_payload.get("id"),
+ "thread_id": response_payload.get("threadId"),
+ }
+ except urllib.error.HTTPError as exc:
+ detail = exc.read().decode("utf-8", errors="replace")
+ return {
+ "provider": "gmail",
+ "configured": True,
+ "sent": False,
+ "status": exc.code,
+ "error": detail[:500],
+ }
+ except (KeyError, urllib.error.URLError, TimeoutError) as exc:
+ return {
+ "provider": "gmail",
+ "configured": True,
+ "sent": False,
+ "status": "connection_error",
+ "error": str(exc),
+ }
+
+
def send_webhook(payload: dict[str, Any]) -> dict[str, Any]:
"""Send a rendered brief to a configured webhook.
@@ -19,6 +146,7 @@ def send_webhook(payload: dict[str, Any]) -> dict[str, Any]:
webhook_url = os.environ.get("AGENTSCOUT_WEBHOOK_URL")
if not webhook_url:
return {
+ "provider": "webhook",
"configured": False,
"sent": False,
"status": "skipped_no_webhook",
@@ -49,6 +177,7 @@ def send_webhook(payload: dict[str, Any]) -> dict[str, Any]:
with urllib.request.urlopen(request, timeout=20) as response:
response_text = response.read().decode("utf-8", errors="replace")
return {
+ "provider": "webhook",
"configured": True,
"sent": 200 <= response.status < 300,
"status": response.status,
@@ -57,6 +186,7 @@ def send_webhook(payload: dict[str, Any]) -> dict[str, Any]:
except urllib.error.HTTPError as exc:
detail = exc.read().decode("utf-8", errors="replace")
return {
+ "provider": "webhook",
"configured": True,
"sent": False,
"status": exc.code,
@@ -64,6 +194,7 @@ def send_webhook(payload: dict[str, Any]) -> dict[str, Any]:
}
except urllib.error.URLError as exc:
return {
+ "provider": "webhook",
"configured": True,
"sent": False,
"status": "connection_error",
diff --git a/always_on_agents/always_on_hn_briefing_agent/scheduler_api.py b/always_on_agents/always_on_hn_briefing_agent/scheduler_api.py
index 6d88ee52..0c170798 100644
--- a/always_on_agents/always_on_hn_briefing_agent/scheduler_api.py
+++ b/always_on_agents/always_on_hn_briefing_agent/scheduler_api.py
@@ -14,10 +14,10 @@ from typing import Any, Optional
from fastapi import FastAPI, Request
try:
- from .delivery import send_webhook
+ from .delivery import send_brief
from .scout import run_ambient_scout
except ImportError:
- from delivery import send_webhook
+ from delivery import send_brief
from scout import run_ambient_scout
app = FastAPI(
@@ -52,7 +52,7 @@ def run_scheduled_scout(payload: dict[str, Any] | None = None) -> dict[str, Any]
"""Run AgentScout from a scheduler payload.
Payload fields:
- dry_run: defaults to true. Set false to call the configured webhook.
+ dry_run: defaults to true. Set false to call configured delivery.
live: optional override for live Hacker News mode.
top_n: number of stories, clamped to 1-10.
"""
@@ -67,10 +67,10 @@ def run_scheduled_scout(payload: dict[str, Any] | None = None) -> dict[str, Any]
"attempted": False,
"sent": False,
"status": "dry_run",
- "detail": "Set dry_run=false to call AGENTSCOUT_WEBHOOK_URL.",
+ "detail": "Set dry_run=false to use configured Gmail or webhook delivery.",
}
if dry_run is False:
- delivery = {"attempted": True, **send_webhook(brief)}
+ delivery = {"attempted": True, **send_brief(brief)}
return {
"dry_run": dry_run,
diff --git a/always_on_agents/always_on_hn_briefing_agent/tests/unit/test_scheduler_api.py b/always_on_agents/always_on_hn_briefing_agent/tests/unit/test_scheduler_api.py
index b6ddf1ef..aac1136a 100644
--- a/always_on_agents/always_on_hn_briefing_agent/tests/unit/test_scheduler_api.py
+++ b/always_on_agents/always_on_hn_briefing_agent/tests/unit/test_scheduler_api.py
@@ -49,3 +49,38 @@ def test_trigger_endpoint_tolerates_empty_body():
assert response.status_code == 200
assert response.json()["delivery"]["status"] == "dry_run"
+
+
+def test_scheduled_scout_reports_missing_delivery_config(monkeypatch):
+ for name in [
+ "AGENTSCOUT_DELIVERY",
+ "AGENTSCOUT_WEBHOOK_URL",
+ "AGENTSCOUT_EMAIL_TO",
+ "AGENTSCOUT_EMAIL_FROM",
+ "AGENTSCOUT_GMAIL_CLIENT_ID",
+ "AGENTSCOUT_GMAIL_CLIENT_SECRET",
+ "AGENTSCOUT_GMAIL_REFRESH_TOKEN",
+ ]:
+ monkeypatch.delenv(name, raising=False)
+
+ result = run_scheduled_scout({"dry_run": False, "top_n": 1, "live": False})
+
+ assert result["delivery"]["attempted"] is True
+ assert result["delivery"]["status"] == "skipped_no_delivery"
+
+
+def test_explicit_gmail_delivery_reports_missing_config(monkeypatch):
+ monkeypatch.setenv("AGENTSCOUT_DELIVERY", "gmail")
+ for name in [
+ "AGENTSCOUT_EMAIL_TO",
+ "AGENTSCOUT_EMAIL_FROM",
+ "AGENTSCOUT_GMAIL_CLIENT_ID",
+ "AGENTSCOUT_GMAIL_CLIENT_SECRET",
+ "AGENTSCOUT_GMAIL_REFRESH_TOKEN",
+ ]:
+ monkeypatch.delenv(name, raising=False)
+
+ result = run_scheduled_scout({"dry_run": False, "top_n": 1, "live": False})
+
+ assert result["delivery"]["provider"] == "gmail"
+ assert result["delivery"]["status"] == "skipped_missing_gmail_config"