Per-person briefings (Eric + Angela) with configurable weather locations
This commit is contained in:
+40
-29
@@ -1,34 +1,32 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Daily Briefing Agent (Orchestrator)
|
||||
Calls sub-agents (weather, etc.), collates their output into a single
|
||||
markdown briefing, and posts it to the Outline wiki.
|
||||
|
||||
Hierarchy: Eric's Daily Briefing → {Year} → {Month} → Daily Briefing — {date}
|
||||
Daily Briefing Engine (Reusable)
|
||||
Collects sub-agent data, composes a markdown briefing, and posts to wiki.
|
||||
Called by person-specific wrappers (eric_briefing.py, angela_briefing.py, etc.)
|
||||
with a config dict specifying location, wiki parent, and agent ID.
|
||||
"""
|
||||
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from shared import (
|
||||
MT, WIKI_API, WIKI_COLLECTION_ID, WIKI_PARENT_DOC_ID, MONTH_NAMES,
|
||||
MT, WIKI_API, WIKI_COLLECTION_ID, MONTH_NAMES,
|
||||
api_request, log_run, wiki_headers, find_child_doc, ensure_child_doc,
|
||||
)
|
||||
|
||||
AGENT_ID = "daily-briefing"
|
||||
|
||||
|
||||
def collect_sections():
|
||||
def collect_sections(config):
|
||||
"""Run each sub-agent and collect markdown sections.
|
||||
|
||||
Returns a list of (section_name, markdown, summary) tuples.
|
||||
Failed sub-agents are logged but don't stop the briefing.
|
||||
"""
|
||||
sections = []
|
||||
location = config.get("location")
|
||||
|
||||
# --- Weather ---
|
||||
try:
|
||||
from weather_agent import run as weather_run
|
||||
md, summary = weather_run()
|
||||
md, summary = weather_run(location=location)
|
||||
sections.append(("Weather", md, summary))
|
||||
print(f" Weather: {summary}")
|
||||
except Exception as e:
|
||||
@@ -36,42 +34,49 @@ def collect_sections():
|
||||
sections.append(("Weather", "## Weather\n\n*Weather data unavailable.*\n", f"error: {e}"))
|
||||
|
||||
# --- Future sub-agents go here ---
|
||||
# Each can receive config params as needed
|
||||
# try:
|
||||
# from calendar_agent import run as calendar_run
|
||||
# md, summary = calendar_run()
|
||||
# md, summary = calendar_run(calendar_id=config.get("calendar_id"))
|
||||
# sections.append(("Calendar", md, summary))
|
||||
# except Exception as e:
|
||||
# sections.append(("Calendar", "## Calendar\n\n*Calendar data unavailable.*\n", f"error: {e}"))
|
||||
# sections.append(("Calendar", "## Calendar\n\n*Unavailable.*\n", f"error: {e}"))
|
||||
|
||||
return sections
|
||||
|
||||
|
||||
def compose_briefing(sections):
|
||||
def compose_briefing(config, sections):
|
||||
"""Compose the full daily briefing markdown from sub-agent sections."""
|
||||
now = datetime.now(MT)
|
||||
date_str = now.strftime("%A, %B %d, %Y")
|
||||
person = config.get("person", "")
|
||||
location = config.get("location", {})
|
||||
loc_label = location.get("name", "")
|
||||
if location.get("state"):
|
||||
loc_label += f", {location['state']}"
|
||||
|
||||
md = f"# Daily Briefing\n"
|
||||
md += f"**{date_str}** | Providence, Utah\n\n"
|
||||
md = f"# {person}'s Daily Briefing\n"
|
||||
md += f"**{date_str}** | {loc_label}\n\n"
|
||||
md += "---\n\n"
|
||||
|
||||
for _name, section_md, _summary in sections:
|
||||
md += section_md + "\n\n"
|
||||
|
||||
md += "---\n"
|
||||
md += f"*Generated at {now.strftime('%I:%M %p MT')} by Daily Briefing Agent*\n"
|
||||
md += f"*Generated at {now.strftime('%I:%M %p MT')} by {person}'s Daily Briefing Agent*\n"
|
||||
|
||||
return md
|
||||
|
||||
|
||||
def post_to_wiki(markdown, date_str):
|
||||
def post_to_wiki(config, markdown, date_str):
|
||||
"""Post the briefing to wiki under Year/Month hierarchy."""
|
||||
wiki_parent_id = config["wiki_parent_doc_id"]
|
||||
now = datetime.now(MT)
|
||||
year_str = str(now.year)
|
||||
month_str = MONTH_NAMES[now.month]
|
||||
|
||||
year_id = ensure_child_doc(
|
||||
WIKI_PARENT_DOC_ID, year_str,
|
||||
wiki_parent_id, year_str,
|
||||
f"Daily briefings for {year_str}.",
|
||||
)
|
||||
month_id = ensure_child_doc(
|
||||
@@ -106,22 +111,32 @@ def post_to_wiki(markdown, date_str):
|
||||
return result["data"]["id"], "created"
|
||||
|
||||
|
||||
def main():
|
||||
def run(config):
|
||||
"""Run the full daily briefing pipeline for a given config.
|
||||
|
||||
Config keys:
|
||||
person (str): Person's name (e.g., "Eric")
|
||||
agent_id (str): Dashboard agent ID (e.g., "eric-daily-briefing")
|
||||
wiki_parent_doc_id (str): Outline doc ID for this person's briefing root
|
||||
location (dict): {name, state, country, lat, lon}
|
||||
"""
|
||||
agent_id = config["agent_id"]
|
||||
|
||||
try:
|
||||
print("Collecting sub-agent data...")
|
||||
sections = collect_sections()
|
||||
print(f"Collecting sub-agent data for {config['person']}...")
|
||||
sections = collect_sections(config)
|
||||
|
||||
print("Composing briefing...")
|
||||
markdown = compose_briefing(sections)
|
||||
markdown = compose_briefing(config, sections)
|
||||
date_str = datetime.now(MT).strftime("%Y-%m-%d")
|
||||
|
||||
print("Posting to wiki...")
|
||||
doc_id, action = post_to_wiki(markdown, date_str)
|
||||
doc_id, action = post_to_wiki(config, markdown, date_str)
|
||||
print(f"Wiki doc {action}: {doc_id}")
|
||||
|
||||
summaries = "; ".join(f"{name}: {s}" for name, _, s in sections)
|
||||
output = f"Briefing {action}. {summaries}"
|
||||
log_run(AGENT_ID, "success", output=output, metadata={
|
||||
log_run(agent_id, "success", output=output, metadata={
|
||||
"wiki_doc_id": doc_id,
|
||||
"action": action,
|
||||
"sub_agents": [name for name, _, _ in sections],
|
||||
@@ -131,9 +146,5 @@ def main():
|
||||
except Exception as e:
|
||||
err_msg = f"{type(e).__name__}: {e}"
|
||||
print(f"Error: {err_msg}", file=sys.stderr)
|
||||
log_run(AGENT_ID, "failed", err=err_msg)
|
||||
log_run(agent_id, "failed", err=err_msg)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user