MarketMind Agent Tutorial
A Hands-on Introduction to Building AI Agents
1 Building MarketMind: A Hands-on Tutorial for Creating Your Own AI Financial Assistant Agent

New to building AI agents? This tutorial teaches the fundamentals through hands-on coding—concepts that apply to any LLM provider. Think of it as learning to drive in a parking lot before navigating city traffic.
Welcome to the MarketMind tutorial! Today, we’re embarking on a journey to build something exciting: an AI financial assistant that can retrieve real-time stock data, analyze company information, and engage in meaningful conversations about the markets. Whether you’re new to AI or looking to expand your skills, this tutorial will guide you through creating a practical, functional agent that works with real-world data.
1.1 Is This Tutorial Right for You?
Before we dive in, let’s take a moment to consider if this tutorial aligns with your interests and experience level.
1.1.1 This Tutorial Is For You If…
You’re a Python developer new to building AI agents. Perhaps you’ve used ChatGPT or other AI tools and wondered, “How could I build something like this myself?” You don’t need prior agent experience—just working Python knowledge.
You’re a practical learner who prefers hands-on experience over theoretical discussions. Rather than just reading about concepts, you want to implement them, see them work, and understand how the pieces fit together. You appreciate real-world applications that solve genuine problems, not just toy examples.
You’re an AI enthusiast excited about cutting-edge technologies. The field of AI is evolving rapidly, and you want to stay current with the latest developments. Beyond just using these tools, you’re curious about how they work under the hood and why certain design decisions are made.
1.1.2 This Tutorial Is NOT For You If…
You’re an expert already building advanced AI agents professionally. We’ll be covering fundamentals that you likely already understand. This tutorial is designed as an entry point to open the door to more advanced AI projects.
You’re seeking a quick solution without learning the underlying concepts. If you just want code to copy without understanding how it works, this tutorial will feel unnecessary. We believe in building a solid foundation of understanding, which takes a bit more time but yields greater capabilities in the long run.
1.2 “But Can’t AI Just Write This Code For Me?”
It’s a fair question. With today’s coding assistants, couldn’t you just ask an AI to build a financial assistant for you?
“Vibe coding”—using AI to generate code from high-level descriptions—has its place in modern development. However, when building complex systems like AI agents, understanding the fundamentals remains crucial.
When developing agents, you’ll inevitably face issues: tools misbehaving, queries being misunderstood, or systems acting unpredictably. Without understanding how your agent works, troubleshooting becomes much harder. You’re often left with a black box you can’t effectively debug.
Understanding the fundamentals also helps you communicate better with AI tools. You’ll write more effective prompts, identify issues faster, and implement more sophisticated solutions. Instead of being limited by what AI can generate from vague descriptions, you can truly collaborate with AI.
Our approach combines learning by doing with understanding core concepts. Once you’ve mastered these basics, you’ll be well-equipped to leverage AI for advanced use cases, extending your agent far beyond what simple code generation could achieve.
So as you work through the code, don’t get caught up memorizing every function signature or import statement—that’s exactly what AI assistants excel at helping you with. Instead, pay attention to the underlying patterns: How does an agent decide which tool to call? What information does a good tool definition need to include? How does context flow from one turn of conversation to the next? These are the questions that matter. The specific APIs will evolve, but the fundamentals—agents that take action, reason about their options, and maintain context—will remain constant across any framework you encounter.
1.3 What You’ll Build: The MarketMind Financial Assistant
Before we dive into the step-by-step implementation, let’s take a look at what we’ll be building. MarketMind is a powerful financial assistant that can retrieve real-time stock data, analyze company information, and engage in meaningful conversations about the markets.
1.3.1 Final Project Structure
market-mind-agent-tutorial/
├── src/
│ ├── common/ # Shared components
│ │ ├── config.py # Centralized configuration
│ │ └── tools_yf.py # Yahoo Finance data tools
│ ├── agent_from_scratch/ # Agent implementation from scratch
│ │ ├── agent_chat.py # Chat Completion API implementation
│ │ ├── agent_response.py # Response API implementation
│ │ └── tool_manager.py # Tool registration and execution
│ ├── openai_agent_sdk/ # OpenAI Agent SDK implementation
│ │ ├── agent.py # Agent implementation
│ │ └── memory.py # Conversation memory handling
│ └── cli/ # Command-line interface
│ └── main.py # CLI commands and entry points
├── tests/ # Tests
│ ├── test_tools.py # Test the tools
│ ├── test_agent.py # Basic tests for the agent
│ └── test_agent_comprehensive.py # More tests for the agent
├── .env.example # Environment template
├── .gitignore # Git ignore rules
├── LICENSE # MIT License
├── pyproject.toml # Project configuration
└── README.md # Project documentation
1.3.2 Capabilities and Features
The MarketMind agent will be able to:
- Retrieve Financial Data
- Get current stock prices: “What’s Apple trading at today?”
- Fetch historical data: “Show me Tesla’s performance over the last week”
- Provide company information: “Tell me about Netflix’s business model”
- Display financial metrics: “What’s Microsoft’s P/E ratio?”
- Maintain Conversation Context
- Remember previously mentioned stocks: “How does it compare to Google?”
- Track discussion topics across multiple turns
- Understand follow-up questions without repetition
- Provide a User-Friendly Interface
- Command-line interface with color-coded responses
- Progress indicators during tool execution
- Detailed logging for debugging
1.3.3 Try It Yourself (Optional)
Want to see the finished agent in action before building it? You can try it right now:
git clone https://github.com/agenteer/market-mind-agent-tutorial.git
cd market-mind-agent-tutorial
uv venv && source .venv/bin/activate
uv pip install -e .
cp .env.example .env # Add your OpenAI API key (see tip below)
market-mind openai-agent-sdkSee OpenAI API Key Setup for instructions. The cost to run this entire tutorial is typically less than $1.
1.3.4 Preview of the MarketMind Agent in action
Here’s an example conversation with the finished agent:
The prices shown below are from when this tutorial was written (April 2025). When you run the agent, you’ll see current market prices.
🤖 MarketMind Financial Assistant
Ask me about stocks, companies, or financial metrics. Type 'exit' to quit.
You: What's the current price of Tesla stock?
MarketMind is thinking...
🤔 Processing query and deciding on actions...
🔍 Getting stock price for TSLA
✅ Analysis complete, generating response...
MarketMind: Tesla, Inc. (TSLA) is currently trading at $237.97, up 4.60% today.
You: How about Apple?
MarketMind is thinking...
🤔 Processing query and deciding on actions...
🔍 Getting stock price for AAPL
✅ Analysis complete, generating response...
MarketMind: Apple Inc. (AAPL) is currently trading at $209.28, up 0.44% today.
You: Compare their financial metrics
MarketMind is thinking...
🤔 Processing query and deciding on actions...
💰 Getting financial metrics for TSLA
💰 Getting financial metrics for AAPL
✅ Analysis complete, generating response...
MarketMind: Here's a comparison of Tesla and Apple's key financial metrics:
| Metric | Tesla (TSLA) | Apple (AAPL) |
|--------|--------------|--------------|
| Market Cap | $917.81 billion | $3.14 trillion |
| P/E Ratio | 163.76 | 33.22 |
| Revenue | $95.72 billion | $395.76 billion |
| Profit Margin | 6.38% | 24.30% |1.4 Our Learning Path
The concepts you’ll learn—tool design, context management, agent architecture—apply to building agents with any LLM provider. We use OpenAI’s APIs as our implementation platform, giving you hands-on experience with three different approaches:
🚀 OpenAI Agent SDK We will start with an implementation using the OpenAI Agent SDK. This gives you a working agent right away, helping you understand what we’re building toward. While we’ll still need to implement the actual tool functions, the SDK simplifies the integration of these tools with the language model. It’s like learning to drive by experiencing what a car can do before studying engine mechanics. We will also dive into how to incorporate conversational history and custom memory context into the Agent.
🛠️ OpenAI Chat Completion API Next, we’ll build from scratch using the Chat Completion API. This fundamental approach helps you understand the core architecture of an AI agent—how it processes requests, makes decisions, and manages context. You’ll implement not just the tool functions but also the entire tool calling orchestration, giving you insight into what the SDK was handling for you.
🌟 OpenAI Response API Finally, we’ll explore the Response API approach. This API offers built-in state management and efficient conversation handling, and by comparing it with our previous implementations, you’ll develop a nuanced understanding of the tradeoffs between different approaches.
This balanced progression—from high-level frameworks to low-level implementations to alternative APIs—gives you both practical skills and deeper understanding of AI agent development.
1.5 The ABC Framework for Agent Design
Throughout this tutorial, we’ll use a structured approach called the ABC Framework to organize our thinking about agent development:

Action is how our agent interacts with the external world. For MarketMind, this means calling financial APIs to get stock data, executing various tools based on user requests, and formatting information for presentation. The Action component is what makes our agent useful—it’s how it accomplishes real tasks rather than just having conversations.
Brain is the reasoning and decision-making center of our agent. Powered by large language models, the Brain understands user queries, decides which tools to use, generates natural language responses, and plans multi-step processes when needed. This is where the “intelligence” of our agent resides.
Context manages information and memory for our agent. It tracks conversation history so the agent remembers what you’ve discussed, stores retrieved financial data for quick reference, and maintains the overall state of the interaction. Without good context management, our agent would be forgetful and frustrating to use.
This ABC Framework helps us organize our agent’s architecture and ensures we’re addressing all essential aspects of functionality. As we build MarketMind, you’ll see how these components work together to create a cohesive, intelligent system.
You can learn more about the ABC Framework and how it serves as a blueprint for AI Agent Engineering at Agenteer.com.
Now Let’s begin our journey to build MarketMind, your own AI-powered financial assistant!