The goal: a working ticker bot
Over the last four lessons, you learned system prompts, structured outputs with Pydantic, and multi-turn chat. Now you'll tie them together into a real, end-to-end project.
In this lesson, you'll build a CLI bot that runs like this:
$ python ticker_bot.py RELIANCE.NS Briefing for RELIANCE.NS Price: ₹2,847.50 (↑ 2.3%) Headlines: 1. Reliance Energy Division targets ₹50k cr investment 2. RIL Q1 profit beats analyst expectations 3. Jio 5G rollout accelerates in Indian metros Sentiment: Bullish Summary: Strong fundamentals with positive sector outlook.
Then ask a follow-up: "Why is it up?" — and the bot remembers the briefing data and reasons through it using the multi-turn session from Lesson 04.
The 3-step pipeline: fetch → reason → output
Every agent follows the same pattern. Data comes in messy; you structure it; you send it to the LLM; it returns JSON.
Arjun is building a stock tracking app for traders in Hyderabad. Every morning, he wants a one-liner briefing on RELIANCE.NS or HDFCBANK.NS—price snapshot, sentiment, key news. He'll plug this into his Slack bot. The output must be JSON so his backend can save it and resend it.
Step 1: Fetch price data with yfinance
yfinance is a wrapper around Yahoo Finance. No API key needed. It returns real OHLC (Open, High, Low, Close) data for any public ticker.
RELIANCE.NS Price: ₹2,847.50 Change: 2.30% SAFCOM.NR (Safaricom Kenya) Price: KSh 32.45
Step 2: Define the output structure with Pydantic
Before you call the LLM, define exactly what you want back. Use Pydantic (from Lesson 03) to enforce the structure.
Step 3: System prompt that generates JSON
The system prompt tells the LLM: "You are an agent that analyzes tickers. Return only valid JSON matching this schema."
Putting it together: end-to-end ticker bot
Here's the complete, runnable CLI bot that fetches data, prompts the LLM, and saves the briefing to JSON.
$ python ticker_bot.py RELIANCE.NS Fetching briefing for RELIANCE.NS... Briefing for RELIANCE.NS Price: ₹2,847.50 (+2.30%) Headlines: 1. Reliance Energy Division targets ₹50k cr investment 2. RIL Q1 profit beats analyst expectations 3. Jio 5G rollout accelerates in Indian metros Sentiment: Bullish Summary: Strong fundamentals with positive sector outlook. Saved to briefings/2026-04-16-RELIANCE.NS.json
Extend it: multi-turn Q&A using ChatSession
Once you have the briefing, use the ChatSession from Lesson 04 to answer follow-up questions. The bot remembers the ticker data across turns.
Bot: The stock is up due to strong Q1 earnings that beat expectations and the accelerating 5G rollout, which drives future revenue. Bot: RELIANCE is an energy giant with diversified revenue (oil, gas, retail, digital). HDFCBANK is a financial services play. Both are strong performers, but they're in different sectors. Bot: Based on strong fundamentals and positive sector outlook, RELIANCE looks like a hold if you own it; a buy if you're looking to accumulate over time.
Stretch: build a mini archive and analytics dashboard
Save briefings to a timestamped JSON archive. Then build a simple dashboard that reads all briefings and shows trends.
How real agents work
This ticker bot is a tiny agent. In production, agents are far more complex: they call APIs (Stripe for payments, Slack for notifications), maintain persistent databases, and reason through multi-step tasks. But the core pattern never changes: data → LLM → structured output. Every AI system from financial trading bots to medical diagnostic tools to customer service agents follows this 3-step pipeline. You've built the real thing.
Task: Run the ticker bot for TCS.NS (Tata Consultancy Services). Then ask a follow-up question using ChatSession: "Is TCS a good long-term hold given its growth in digital services?"
Verify that:
1. The bot fetches real price data for TCS.NS
2. The structured JSON includes a bullish/bearish/neutral sentiment
3. The ChatSession remembers TCS context in the follow-up
Hint: Run `python ticker_bot.py TCS.NS`, then create a ChatSession with the returned briefing object. Use the briefing data as context in the system prompt, then call `session.chat("Is TCS a good long-term hold...")`. The bot will reference the briefing context automatically.
Test your knowledge
You've built a real agent.
Now scale it to production systems.
Join the Best AI Program: The AI-Era Agentic Engineer — 5 months, fully online, with placement assistance. Week 1 is free.
Explore The AI-Era Agentic Engineer →