Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.mavera.io/llms.txt

Use this file to discover all available pages before exploring further.

Scenario

Your leadership team sees the same industry headlines but interprets them differently — your CMO cares about brand impact, your CTO cares about technology shifts, your CFO worries about market risk. This job pulls today’s top headlines for your industry, then runs each story through Mavera Speak sessions with distinct executive personas. The output is a single digest where every story carries three different lenses of analysis. Flow: NewsAPI GET /top-headlines → Mavera POST /personasPOST /speak per story → Multi-perspective digest

Code

import os, requests, time, json

NA_KEY = os.environ["NEWSAPI_KEY"]
NA_BASE = "https://newsapi.org/v2"
NA_H = {"X-Api-Key": NA_KEY}
MV = os.environ["MAVERA_API_KEY"]
MV_BASE = "https://app.mavera.io/api/v1"
MV_H = {"Authorization": f"Bearer {MV}", "Content-Type": "application/json"}

INDUSTRY = "technology"
COUNTRY = "us"

# 1. Fetch top headlines
r = requests.get(f"{NA_BASE}/top-headlines", headers=NA_H, params={
    "category": INDUSTRY, "country": COUNTRY, "pageSize": 10,
})
r.raise_for_status()
articles = r.json().get("articles", [])
print(f"Fetched {len(articles)} headlines for {INDUSTRY}/{COUNTRY}")

# 2. Create executive personas
EXECS = [
    {"name": "CMO Lens", "desc": "Chief Marketing Officer. Evaluates news for brand impact, competitive positioning, consumer sentiment shifts, and content opportunities."},
    {"name": "CTO Lens", "desc": "Chief Technology Officer. Evaluates news for technology disruption, infrastructure implications, build-vs-buy decisions, and engineering talent market."},
    {"name": "CFO Lens", "desc": "Chief Financial Officer. Evaluates news for market risk, revenue impact, cost implications, investor sentiment, and regulatory exposure."},
]
persona_ids = []
for ex in EXECS:
    p = requests.post(f"{MV_BASE}/personas", headers=MV_H, json={
        "name": f"News Digest: {ex['name']}",
        "description": ex["desc"],
    }).json()
    persona_ids.append({"id": p["id"], "name": ex["name"]})
    time.sleep(0.3)

# 3. Run each story through each persona via Speak
digest = []
for article in articles[:7]:
    story_block = f"**{article['title']}**\n{article.get('description','')}\nSource: {article.get('source',{}).get('name','')}"
    perspectives = {}

    for persona in persona_ids:
        speak = requests.post(f"{MV_BASE}/speak", headers=MV_H, json={
            "persona_id": persona["id"],
            "input": [
                {"role": "system", "content": f"You are a {persona['name']}. Analyze this news story in 2-3 sentences from your executive perspective. Focus on actionable implications."},
                {"role": "user", "content": story_block},
            ],
            "mode": "interview",
        }).json()
        answer = ""
        for ex in speak.get("exchanges", speak.get("messages", [])):
            if ex.get("role") == "assistant":
                answer = ex["content"]
        perspectives[persona["name"]] = answer[:300]
        time.sleep(0.3)

    digest.append({"title": article["title"], "source": article.get("source",{}).get("name",""),
                   "perspectives": perspectives})

# 4. Print digest
for i, story in enumerate(digest, 1):
    print(f"\n{'='*60}\n{i}. {story['title']} ({story['source']})\n{'='*60}")
    for lens, analysis in story["perspectives"].items():
        print(f"\n  [{lens}]\n  {analysis}")

Example Output

Fetched 10 headlines for technology/us

============================================================
1. Apple Announces New AI Chip for Consumer Devices (TechCrunch)
============================================================

  [CMO Lens]
  Messaging window opens — "AI-powered" positioning hits mainstream. Refresh
  product copy to lead with on-device intelligence before competitors adopt
  the same language. Content opportunity: comparison guide.

  [CTO Lens]
  On-device inference shifts build calculus. Evaluate whether our cloud-first
  ML pipeline should add edge deployment. Talent implication: need engineers
  with NPU experience within 12 months.

  [CFO Lens]
  Apple's capex signals hardware margin compression. Our cloud API costs may
  decrease as inference moves client-side. Watch for licensing model changes
  that affect our COGS.

Error Handling

Free-tier articles return only 200 chars of content. Use description field as primary input, or upgrade to Business for full content.
Free tier: 100 req/day. This job uses 1 (headlines) + N×3 (Speak) calls to Mavera. Cache NewsAPI responses to avoid redundant calls on re-runs.
Valid categories: business, entertainment, general, health, science, sports, technology. Use /everything with q param for custom topics.