Raunak's Blog

how to build an ai agent

what is an AI Agent?

An AI agent figures out how to achieve a goal by following a process and making decisions in a loop until the task is done. Think of it like an AI you can delegate to, not just chat with.

3 layers of Agentic AI

layer 1: workflows

This layer is a recipe. The agent reads the recipe and follows the instructions. Workflows will be markdown files in the project.

layer 2: agent

This layer is Claude Code itself. After "reading the recipe", Claude will reason on its own to solve the task.

layer 3: tools

This is what the agent uses to get things done. Actions such as reading/writing to files, running commands, and searching the web are all built in tools to Claude. If you want additional capabilities such as connecting with other software, utilize mcp (model context protocol).

The best way to understand the three layers is to build your own ai agent.

tutorial

I am interested in researching stocks. I do it all the time, and lately, I've been using LLMs to run full stock analyses on companies I am interested in learning more about. Let's build an AI agent that gives a full stock analysis for a given stock.

prerequisites

Open VSCode and set up a project folder

Create CLAUDE.MD file. Claude Code reads it every time the project starts up, and it informs who you are, what the project is about, and how you want things done. Here is a sample CLAUDE.MD file:

# Project Context

This is my ai agent workspace. I use it for research, content creation, and productivity workflows.

# About me

I create content about technology and productivity. My audience is people who want to learn about technology and want practical, no-nonsense tutorials. I prefer clear, jargon-free output.

# Rules

- Always ask clarifying questions before starting a complex task
- Show your plan and steps before executing
- Keep reports and summaries concise. Bullet points over paragraphs.
- Save all output files to the output folder.
- Cite sources when doing research. 

# Project Structure

- workflows/ - Workflow instruction files (plain english recipes the agent follows)
- output/ - finished deliverables (reports, drafts, analysis)
- resources/ - Reference docs and templates

Open up a chat window, and put in plan mode (shift+enter twice)

Describe what you want to achieve. Claude will reference the CLAUDE.MD file for the instructions, and it will create a workflow for you to review. If you are satisfied, hit yes and auto-accept. if you want to add more or refine the expected output, hit keep planning. Here is a sample prompt I sent to create a workflow:

i want to build a workflow where i can give you any stock, and you'll research it thoroughly, do the fundamental analysis, organize the findings, and produce a clean, structured report. At the top of the report, give a score out of 100. Before you start researching, you should ask me clarifying questions about the scope, the audience and what I specifically want to know.

Claude starting reasoning on its own, exploring the project directory, and asking questions:

Read c:\Users\rauns\first-agent\CLAUDE.MD

Agent:Explore project structure

I have a good picture of the project. It's a fresh workspace β€” only CLAUDE.MD exists, no folders yet. Let me ask a few questions before I write the plan.
User has answered your questions: 
- "What investment style should the analysis default to?"="All-purpose (Recommended)"
- "How should the 100-point score be structured?"="Single holistic score"
- "Should the report include an explicit Buy / Hold / Sell recommendation?"="Yes β€” include it (Recommended)"
- "Who will typically read these reports?"="Personal use"

You can now continue with the user's answers in mind.

Then, it created a workflow. Pro-tip: if you want to see the markdown rendered fully formatted hit ctrl+shift+v:

Good, I have everything I need. Let me write the plan now.

Write C:\Users\rauns\.claude\plans\i-want-to-build-purrfect-milner.md
128 lines

Claude’s Plan C:\Users\rauns\.claude\plans\i-want-to-build-purrfect-milner.md
Stayed in plan mode

I realized I want to add a "one-liner" on what the business does and also an analysis on the ideal entry point, so I told Claude, and it updated the workflow:

also include a recommendation for entry points for a position in the stock in the report. after tldr and before business overview, i want a one-liner on what the business does.

Then I reviewed the workflow and approved. Claude will exit plan mode and start to build the project directory.

Edit C:\Users\rauns\.claude\plans\i-want-to-build-purrfect-milner.md
Added 2 lines
Done. Ready to proceed when you are.

Claude’s Plan C:\Users\rauns\.claude\plans\i-want-to-build-purrfect-milner.md
User approved the plan
Plan approved. Creating the three directories and two files now.

Here is a sample of the workflow markdown file:

# Stock Analysis Workflow

## Purpose
Research any stock thoroughly, perform fundamental analysis, and produce a structured report
with a score out of 100, a Buy/Hold/Sell recommendation, and entry point guidance.
Reports are saved to `output/` and are written for personal use β€” dense, bullet-first, no fluff.

---

## Step 1 β€” Ask Clarifying Questions

Before doing any research, ask the user these four questions:

1. **Focus** β€” What specifically do you want to understand about this company?
   (e.g., growth story / financial health / competitive position / recent news / all of the above)

2. **Horizon** β€” What's your investment horizon for this analysis?
   (short-term trade / 1–3 years / long-term hold)

3. **Concerns** β€” Any specific concerns, claims, or rumors you want verified?

4. **Scope** β€” Anything to focus extra on, or skip entirely?

Do not begin research until these questions are answered.

---

## Step 2 β€” Research

Use WebSearch and WebFetch to gather data. Work through each area below in order.
**Cite every source with a URL** β€” no unsourced claims in the final report.

| Area | What to find |
|---|---|
| Business overview | Business model, products/services, revenue segments, company history |
| Recent financials | Revenue, EPS, operating margins, free cash flow β€” last 4 quarters |
| Balance sheet | Cash on hand, total debt, debt/equity ratio, interest coverage |
| Valuation | P/E, P/S, EV/EBITDA β€” current vs 5-year average and vs closest peers |
| Growth | Revenue and earnings growth rate, forward analyst estimates, guidance |
| Competitive moat | Market position, key competitors, differentiation, switching costs |
| Management | CEO track record, capital allocation history, insider ownership % |
| Recent news | Last 3–6 months: earnings beats/misses, guidance changes, M&A, macro impact |
| Analyst consensus | Buy/Hold/Sell count, average price target, current price, implied upside/downside |
| Risks | Regulatory, competitive, macro, balance sheet, and company-specific risks |
| Entry points | Current price, 52-week range, 50-day and 200-day moving averages, key support/resistance levels, upcoming catalysts (earnings dates, product launches, regulatory decisions) |

---

## Step 3 β€” Score and Recommendation

After completing research, assign:

**Score (out of 100)** β€” A single holistic number reflecting overall investment quality.
Write 1–2 sentences justifying the score. Do not show the internal rubric in the report.

Internal scoring guidance (do not include in report):
- **80–100** Exceptional β€” strong business, healthy financials, attractive valuation, clear catalysts
- **60–79** Solid β€” good business with moderate risk or a valuation concern
- **40–59** Mixed β€” meaningful risks or weak financials offset real positives
- **Below 40** Avoid β€” poor fundamentals, stretched valuation, or serious red flags

**Recommendation** β€” State one of: **BUY / HOLD / SELL** with a one-line rationale.

---

## Step 4 β€” Write the Report

Fill in the template at `resources/stock-report-template.md`.

Save the completed report to:

output/[TICKER]-analysis-[YYYY-MM-DD].md


Confirm the save path with the user when done.

---

## Quality Checklist

Before saving, verify:
- [ ] All 11 report sections are populated (no placeholders remaining)
- [ ] Score and recommendation appear at the very top
- [ ] "What they do" one-liner is present after TL;DR
- [ ] Entry points section includes current price, zones, and suggested approach
- [ ] Every factual claim has a source URL in the Sources section
- [ ] Filename follows the `[TICKER]-analysis-[YYYY-MM-DD].md` format

And now we are ready to run the agent:

run the stock analysis workflow on Nvidia

After completing the report, the agent saved the results under output/Nvidia-analysis-2026-04-30.md

# NVIDIA Corporation (NVDA) β€” Stock Analysis
Date: 2026-04-30

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
SCORE: 78/100  |  BUY
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
World-class AI compute monopoly with near-irreplaceable software moat; forward P/E of ~24x sits well below its own 5-year historical average, making valuation far more defensible than the headline trailing multiple implies. Primary risks β€” China export headwind (~$8B/quarter in lost revenue) and gradual custom-silicon displacement at inference workloads β€” are real but manageable on a 1–3 year horizon.

---

## TL;DR
- FY2026 revenue hit $215.9B (+65% YoY); FY2027 analyst consensus is $369B (+71%) driven by Blackwell ramp and Vera Rubin introduction.
- Data center is 90% of revenue ($193.7B in FY2026); hyperscaler capex still accelerating.
- China export controls permanently removed ~$8B/quarter in addressable revenue β€” this is now priced in, not a new surprise.
- Forward P/E of ~24x is below the 5-year average of 68x; the stock is cheaper on a growth-adjusted basis than it has been in years.
- Custom silicon (Google TPU, Amazon Trainium, Microsoft Maia) is a real long-term threat to inference share, but CUDA's ecosystem lock-in keeps training spend anchored at Nvidia for the foreseeable future.

**What they do:** Nvidia designs and sells GPUs and accelerated computing platforms β€” primarily to hyperscalers and enterprises for AI model training and inference β€” with its proprietary CUDA software stack creating deep switching costs that make it the default infrastructure layer for AI development.

For the purpose of this article, I have truncated the results. However, the report followed the exact template detailed in workflows.md and gives me a repeatable, predictable report format for any stock I would like to research in the future!

This was a very simple agent to get my feet wet with building an AI agent. While building, I started to see the utility and my mind started to race with other possible use cases. I'm eager to continue building with AI agents to see what other cool problems I can solve.

mistakes to avoid

reference

#ai #claude #tech