
Weekend Creative Agent Challenge: Market Mood Agent with AWS Bedrock
Market Mood Agent is a daily AI agent that turns real stock market data into a mood score, a short narrative, and an abstract painting, then grades its own next-day volatility forecast against what actually happened. Airflow orchestrates a 6-task daily DAG, Amazon Bedrock (Nova Lite for narrative, Stability stable-image-core for art) generates the content, and S3/Snowflake store and track results over time. Streamlit serves a read-only gallery UI.
Market Mood Agent: an Airflow + Bedrock pipeline that grades its own forecasts
What I built
Market Mood Agent is an Airflow DAG that runs daily against real SPY market data, computes a mood score, generates a narrative and an abstract image via AWS Bedrock, persists everything to S3 and Snowflake, and, on each subsequent run, scores its own prior-day volatility prediction against what actually happened.
The DAG has six tasks:
query_mood_signals → compute_mood_score → generate_narrative → generate_art → persist → score_yesterdayquery_mood_signals computes three numbers from a rolling window of OHLCV data:- volatility: 10-day stddev of daily returns
- volume_anomaly: today's volume vs. the mean of the fetched window
- momentum_pct: 5-day % price change
compute_mood_score turns those into a score in [-1, 1] :score = clip(
0.5 * normalized_momentum
- 0.3 * normalized_volatility
+ 0.2 * normalized_volume_anomaly * momentum_direction
)with a label bucket (
euphoric / calm / anxious / volatile / bearish ) assigned by threshold. generate_narrative and generate_art call Bedrock. persist writes the image + a metrics JSON to S3 and upserts a row into a Snowflake MOOD_HISTORY table. score_yesterday is the actual point of the project: it pulls the most recent prior row's predicted_next_day_vol , compares it to today's just-computed volatility , and writes accuracy_delta back onto that prior row.Every row stores a prediction; every subsequent run grades the previous prediction against reality. Nine of ten backfilled days now have a real, computed
accuracy_delta . The tenth is today, ungraded until tomorrow's run closes the loop.Why
This was meant to sit alongside an existing
real-time-stock-data-pipeline project (Kafka → Postgres → Snowflake), adding a creative/scoring layer on top of real market data rather than mocked data. For this build specifically, it pulls its own OHLCV data directly via yfinance into a dedicated Snowflake database ( STOCKS_MMA_DB ), keeping it fully decoupled from the ingestion pipeline.Architecture

Airflow runs standalone (webserver + scheduler + triggerer in one process) in Docker, backed by its own Postgres for metadata, entirely separate from the market data. Streamlit reads
MOOD_HISTORY directly for the gallery/charts.What broke
1. The image model the whole art step was designed around is dead
amazon.nova-canvas-v1:0 is LEGACY in every region that lists it ( us-east-1 , ap-northeast-1 ), with invoke access auto-revoked after 30 days of account inactivity:botocore.errorfactory.ResourceNotFoundException: An error occurred
(ResourceNotFoundException) when calling the InvokeModel operation:
Access denied. This Model is marked by provider as Legacy and you
have not been actively using the model in the last 30 days. Please
upgrade to an active model on Amazon BedrockAWS also just retired the manual "Model access" console page in favor of auto-enable-on-first-invoke. That doesn't apply to legacy models; re-invoking after the change produced the identical error. There was no active Amazon text-to-image model anywhere in the account (Titan Image Generator isn't even in the catalog).
Fix: Stability AI's
stable-image-core-v1:1 is active, but only in us-west-2 , not us-east-1 where everything else runs. mood/art.py opens a second, region-pinned bedrock-runtime client:IMAGE_REGION = os.environ.get("BEDROCK_IMAGE_REGION", "us-west-2")
def get_client():
return boto3.client("bedrock-runtime", region_name=IMAGE_REGION)The two models also have completely different request shapes. Nova Canvas:
{
"taskType": "TEXT_IMAGE",
"textToImageParams": {"text": "..."},
"imageGenerationConfig": {"numberOfImages": 1, "height": 1024, "width": 1024}
}Stability:
{
"prompt": "...",
"aspect_ratio": "1:1",
"mode": "text-to-image",
"output_format": "png"
}2. Newly registered DAGs are paused by default, silently
airflow dags trigger market_mood_agent succeeds and queues a DagRun . Nothing then happens. No error, no log line pointing at the cause, the run just sits at queued indefinitely, because the scheduler doesn't create TaskInstance s for a paused DAG's runs regardless of whether the run was triggered manually. The tell is easy to miss because it's a missing action, not a failure:$ airflow dags list
dag_id | is_paused
market_mood_agent | True
$ airflow dags unpause market_mood_agent
market_mood_agent | False3. Two DAG runs, same trading day, two rows
A manual trigger plus an auto-created catch-up run (both firing right after the unpause above) both computed signals for the same
run_date and both INSERT ed. MOOD_HISTORY had no uniqueness constraint, so both landed:MERGE INTO MOOD_HISTORY AS target
USING (SELECT %s AS run_date, %s AS ticker) AS source
ON target.run_date = source.run_date AND target.ticker = source.ticker
WHEN MATCHED THEN UPDATE SET ...
WHEN NOT MATCHED THEN INSERT (...)Verified idempotency by triggering a third run and confirming the row count held at one.
4. Backfill almost leaked future data into past predictions
The initial
fetch_ohlcv always pulled the latest N rows regardless of which historical day was being backfilled, meaning day 11's volatility calculation would have silently included days 12 through 20. Fixed with an as_of_date parameter constraining the query to trade_date <= as_of_date , which is the difference between a backtest and a leak:def fetch_ohlcv(ticker, lookback_days=30, as_of_date=None):
...
if as_of_date is not None:
query += " AND trade_date <= %s"Result
- 10 real backfilled trading days, 3 with generated art (full generation on every backfill day is unnecessary Bedrock spend for a fixed demo set)
- A live DAG on a
30 21 * * 1-5UTC schedule,catchup=False, adding one graded day at a time
- A Streamlit gallery, deployed with a credential-free demo mode (no AWS/Snowflake secrets exposed to the third-party host): market-mood-agent.streamlit.app
- Full source, DAG code, and the complete phase-by-phase build log: github.com/aiwithqasim/market-mood-agent
Takeaway
The image-model failure was an assumption I didn't verify before writing code against it: that a specific Bedrock model ID was live in the target region. That's a single CLI call (
aws bedrock list-foundation-models --query "...modelLifecycle.status" ) that would have cost thirty seconds instead of the hour it actually cost mid-build. The other three issues (paused DAGs, missing idempotency, backfill data leakage) are the kind of thing that only shows up by actually running the pipeline end-to-end against real infrastructure, which is exactly why each one got fixed and verified before moving to the next phase instead of after.Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article