Building Agents that can Use Tools, APIs, and Reason.
Part 1: Key Concepts
Agents vs Chatbots
A Chatbot reads and writes. An Agent can Act. It has "Tools" (like Python
functions) that it can call to get real-time data or perform tasks.
MCP (Model Context Protocol)
The standard way to connect LLMs to external data. Instead of hardcoding API calls, we run a small
local server (MCP Server) that exposes tools to the AI in a safe, standardized way.
Part 2: The Lab - "The Finance Analyst"
The Mission
You are a Quantitative Analyst. You need to build a custom AI agent that can fetch LIVE stock data using
the YFinance API and give you immediate investment advice.
Prerequisites
Ensure your Python MCP Server is running:
python mcp_server.py
Part 3: The Prompt Library
Level 1: Basic Tool Call
Goal: Verify the Agent can call the tool.
What is the current stock price of Apple (AAPL)?
Watch: Look at the "Thought Chain". You should see `Action: get_stock_price("AAPL")`.
Level 2: Comparison (Multi-Step)
Goal: Force the agent to make multiple calls.
Compare the price of Apple (AAPL) and Microsoft (MSFT). Which one
is more expensive per share right now?
Level 3: Analysis & Synthesis
Goal: Combine Data with Reasoning.
Fetch the last 5 days of data for Tesla (TSLA). Is the trend
bullish or bearish? Explain your reasoning based on the moving average.
Level 4: Handling Errors (Robustness)
Goal: Test error recovery.
Check the price of a fake company called 'XYZABC'. If it fails,
check Google (GOOGL) instead.
Insight: The Agent should receive an error from the first call, catch it, and proceed
to the second instruction autonomously.