The GenAI Playbook by Yasir Gaji — Part 4: The Strategist
18 January 2026

In Part 3, I wrote about how I built a digital employee, an autonomous agent that fetches gold prices and posts to X/Twitter without human intervention.
But that agent is unidirectional. It talks at users, not with them.
For The Gold Metrics to be a true platform, it needs to offer personalised advice. A static chart tells you the price is $2,680. It doesn’t tell you whether to buy physical coins or digital ETFs. It doesn’t know you have ₦50,000 to invest.
In Part 4, I’d tell you how I built “The Gold Consultant” a context-aware AI strategist that remembers your conversation, knows the live market data, and gives specific advice.
The Problem: Generic AI Requires Work
If you ask ChatGPT: “Is now a good time to buy gold?”
You’ll get a solid answer, but only after you:
- Tell it to search for current prices
- Remind them of your budget from earlier
- Ask it to convert currencies
- Prompt it to check market hours
Generic AI can do all of this. But you’re the one doing the orchestration. You’re the prompt engineer.
The Gold Consultant does this automatically. Every response is pre-loaded with live prices, market status, and your conversation history. No prompting required. It’s the difference between a Swiss Army knife and a scalpel; both cut, but one is purpose-built for the job.
To build a useful consultant, we need to solve three problems:
- Live Data: Inject current prices into the AI’s context
- Conversation Memory: Remember what the user said earlier
- Persona Constraints: Keep the AI focused on Gold finance, not general chat
The Architecture: Context-Augmented Generation
You may have heard of RAG (Retrieval-Augmented Generation), the pattern where you search a vector database for relevant documents and inject them into the prompt.
What we’re building is a simplified variant. Instead of semantic vector search, we’re doing direct database lookups:
User Question → Fetch Live Price (Supabase) → Inject into Prompt → Generate Response
The principle is identical: retrieve context, then generate. We just skip the embedding step because our data is structured (prices, timestamps), not unstructured (documents).
The Stack
We need two libraries working together:
Library Role LangChain (@langchain/google-genai) The "Brain" handles prompt templates, chains, and the Gemini model AI SDK (ai, @ai-sdk/react, @ai-sdk/langchain) The "Body" handles streaming, UI hooks, and the bridge between LangChain and the frontend
npm install ai @ai-sdk/react @ai-sdk/langchain @langchain/google-genai @langchain/core
Why LangChain instead of the AI SDK’s native Google provider?
LangChain gives us LCEL (LangChain Expression Language), a composable way to build chains:
const chain = prompt.pipe(model); // Prompt → Model
This makes it trivial to add memory, tools, or multi-step reasoning later. The AI SDK’s @ai-sdk/langchain package bridges LangChain streams to the AI SDK's streaming protocol.
Step 1: The Persona (System Prompt)
This is where 90% of AI products fail. They leave the AI as a “Helpful Assistant.” Generic assistants are boring and unhelpful.
We want a Senior Gold Market Strategist:
Key design decisions:
{chat_history}solves the "amnesia problem", the AI sees what was said before{price}and{market_status}are injected live from the database- The “Context Matters” rule explicitly tells the model to use prior information
Step 2: The Chain (LangChain + Gemini)
We build a simple chain: Prompt → Model.
Why no StringOutputParser?
The AI SDK’s toUIMessageStream expects AIMessageChunk objects (with .content property), not raw strings. By omitting the parser, the chain outputs the correct format for streaming.
The temperature setting (0.3) controls response determinism, which means lower values produce more focused, instruction-following outputs, which is critical for financial advice
Step 3: The API Route (The Orchestrator)
This is where the “CAG” happens. We intercept the user’s message, fetch live data, build the chat history, and stream the response.
The flow:
- Parse incoming messages
- Build chat history string from previous messages
- Fetch live gold price from Supabase
- Determine if the market is open (weekday check)
- Stream the LangChain output back to the client
Step 4: The Frontend (Streaming + Markdown)
We use @ai-sdk/react's useChat hook for streaming, and react-markdown for rendering formatted responses.
Why Markdown?
A financial advisor should use bullet points, bold text for emphasis, and a clear structure. When the AI responds with:
It renders as a clean, scannable comparison, not a wall of text.

The Result
We now have a context-aware consultant that:
- Knows the live price: Fetched from Supabase on every request
- Remembers the conversation: Chat history is injected into the prompt
- Stays in character : The persona keeps it focused on gold/finance
- Streams responses : Real-time typing effect via AI SDK
Example conversation:


Conlusion
We have given our consultant a brain (LangChain) and eyes (Live Prices). It knows what the price is, but it doesn’t know why it’s moving.
It cannot read the news, it cannot analyze Fed minutes, and it cannot cite historical reports. It is numerically precise but contextually blind.
In Part 5, we will tackle the final frontier: True RAG with Vector Embeddings. We will build the ‘Knowledge Engine’ teaching our AI to ingest unstructured financial news, store it in a Vector Database (pgvector), and retrieve the exact narrative context needed to explain the market. We are moving from ‘What happened?’ to ‘Why it happened.
I expect questions, corrections, and criticisms. Share. Thank you.
References
Also published on Medium.