Share E-Book
(First 20 pages)

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Page 1
Building AI Agents for Finance BUILDING AI AGENTS FOR Hanane Dupouy Fayssal El Mofatiche Design & deploy finance AI agents with robust architectures, advanced reasoning patterns, and Python FINANCE Build and deploy robust fi nancial agentic systems with advanced reasoning, architectures, and Python Hanane Dupouy Fayssal El Mofatiche H a n a n e D u p o u y F a y ssa l E l M o fa tic h e Master core AI agent design patterns and apply them to finance Compare major AI agentic frameworks and learn how to select the right one Explore reasoning paradigms used in agentic workflows Design multi-agent orchestration using various architectural styles Build financial use cases with hands-on Python labs Evaluate and test AI agent behavior effectively Implement guardrails, tracing, and observability Apply AI agents across fundamental analysis, trading, research, and compliance WHAT YOU WILL LEARN AI agents are rapidly changing how fi nancial systems analyze information, make decisions, and automate complex workfl ows. While many resources explain agentic AI concepts, few show how to design and deploy AI agents that work reliably in fi nance. This book fi lls that gap. You will start by learning what AI agents are, how they diff er from non- agentic systems, and when agentic architectures are appropriate. You’ll use Python with Claude and OpenAI models across hands-on labs covering design patt erns, memory, agentic RAG, framework selection, reasoning paradigms such as ReAct, refl ection, self-consistency, and Language Agent Tree Search, and multi-agent collaboration. You’ll then take a deep dive into fi nancial use cases, including fundamental analysis, deep research, trading, insurance, and compliance, using technologies such as LangGraph, Claude Skills, the OpenAI Agents SDK, and LlamaIndex. You will learn to evaluate agent behavior, calibrate LLM judges, detect drift, and produce model risk reports. Finally, you will focus on operationalizing AI agents responsibly, covering the agent harness and execution loop, observability and tracing, deployment and versioning, guardrails, and governance with human oversight. By the end, you’ll be able to design, evaluate, and deploy fi nancial AI agents that deliver real business value. www.packtpub.com Get a free PDF of this book packtpub.com/unlock/9781837022298 Building AI Agents for Finance Hanane Dupouy Fayssal El Mofatiche
Page 2
Building AI Agents for Finance Build and deploy robust financial agentic systems with advanced reasoning, architectures, and Python Hanane Dupouy Fayssal El Mofatiche
Page 3
Building AI Agents for Finance Copyright © 2026 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors nor Packt Publishing, nor its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. This book was written by the authors. Generative AI tools were used under the authors' direction only to assist with ideation, phrasing, and diagram drafts, and all technical content and code were created, verified, and tested by the authors and Packt's editorial team. Packt does not accept AI-generated content that replaces expert authorship. Portfolio Director: Gebin George Relationship Lead: Ali Abidi Project Manager: Prajakta Naik Content Engineer: Mark D'Souza Technical Editor: Rahul Limbachiya Indexer: Hemangini Bari Production Designer: Salma Patel Growth Lead: Dipali Malwatkar First published: August 2026 Production reference: 1240826 Published by Packt Publishing Ltd. Grosvenor House 11 St Paul's Square Birmingham B3 1RB, UK ISBN 978-1-83702-229-8 packtpub.com
Page 4
I would like to dedicate this book to my mother, for her sacrifices and her endless determination to help each one of us rise; to my big brother, Said, for always being there for me; to my husband, Nicolas, for his love and support every single day; and to my daughters, Nora, Chloé, and Julia: you are my raison d'être and my motivation. – Hanane Dupouy To the memory of my father, and to my mother and my siblings—whose sacrifices I can never repay and which I only truly understood once I had children of my own. To my wife, Verena, and to Jakob and Sara—for their love and patience through the evenings and weekends this book took. And finally, to the builders and the insatiable learners who turn what impresses into what works. – Fayssal El Mofatiche
Page 5
Contributors About the authors Hanane Dupouy has spent over 16 years in financial markets as an algorithmic trader, quant researcher, and leader of data science and BI teams in investment banking. Based in Paris, she knows what finance professionals need from AI: systems that hold up in production and satisfy risk committees. She now trains professionals and companies on AI agents in finance, insurance, and beyond, focusing on production-ready multi-agent systems. She co-authored three SSRN white papers on generative AI in finance and is a regular keynote speaker at international conferences and private corporate events. She trained at Arts et Métiers (engineering), ESSEC (finance), and Télécom Paris (data science). She shares her work at ai- agent-in-finance.com. I would like to extend my deepest gratitude to my closest friends, especially Christophe B, for their support; to my former boss, Olivier C., for his continued support at work; and to my colleague, Sylvain S., for giving me the right push at exactly the right time. I would also like to thank the Packt team for their patience and support throughout this particularly busy year. Fayssal El Mofatiche, CAIA, is the founder and CEO of Flowistic, a financial markets engineering firm building production-grade AI, HPC, and trading systems for financial institutions. Previously, he spent more than 14 years at Allianz Global Investors across Multi Asset and Quantitative Advisory, working on quantitative platforms and data-driven investment technology. He is also the founder of Finteda, the practitioner community behind the AI in Finance summit series across London, Paris, Frankfurt, and New York, and has regularly chaired and spoken at the AI summits at QuantMinds, one of the industry's leading quantitative finance conferences. I would like to thank my co-author, Hanane, who carried this project with rigor and good humor through a demanding year; the Packt team — Mark, Prajakta, and Ali — for their patience and precision; Rahul, our technical editor, whose comments made this a much better book; and the Finteda community, in whose rooms many of this book's questions were first asked. My deepest thanks go to my family and friends, who supported me throughout and put up with the evenings and weekends that this book quietly took.
Page 6
About the reviewer Arvind Shashtry is a technology entrepreneur, founder, and senior business leader with over 18 years of experience across artificial intelligence, cloud computing, digital strategy, and business transformation. His career spans global technology companies, including Amazon Web Services, high-growth startups, and the public sector. He has led complex technology, commercial, and transformation initiatives, combining strategic thinking with hands-on experience in cloud economics, AI, and data-driven decision-making. He is focused on building innovative technology products that solve complex enterprise challenges, simplify decision- making, create measurable business value, and reshape the future of work and enterprise operations.
Page 7
(This page has no text content)
Page 8
Table of Contents Preface xxvii Free benefits with your book .............................................................................................. xxxiv Chapter 1: What Are AI Agents? 1 Technical requirements ............................................................................................................. 3 Introducing LLMs ..................................................................................................................... 4 What are Transformers? • 5 What are the different tasks LLMs can perform? • 5 Various input types • 6 Open-source vs. closed-source models • 7 Reasoning vs. non-reasoning LLMs • 10 Overview of specialized LLMs and tools in finance .................................................................. 11 Open-source LLMs • 11 Commercial/proprietary finance LLMs • 13 Open-source datasets • 13 Hands-on lab: API calls • 14 Interacting with closed-source models • 15 Interacting with an open-source model • 18 LLM limitations and solutions ................................................................................................. 21 LLM limitations • 21 Knowledge cutoffs • 21 Lack of domain-specific knowledge • 22 Access to proprietary data • 22 Dependency on training data quality • 22 LLM solutions • 23 Crafting instructions - Prompting • 23 Fine-tuning • 27 RAG • 30 AI agents • 32 Hands-on lab: Knowledge cutoff example • 32
Page 9
What are AI agents? ................................................................................................................. 33 Non-agentic vs. agentic systems • 35 When should we use an agent? • 36 Hands-on lab: Non-agentic vs. agentic workflow with tool calling • 37 Interacting with a non-agentic system • 38 Interacting with an agentic system • 38 Summary ................................................................................................................................ 41 Bibliography ........................................................................................................................... 42 Chapter 2: Exploring Design Patterns for AI Agents 45 Technical requirements ........................................................................................................... 47 Capability patterns ................................................................................................................. 48 Tool use • 48 Hands-on lab: Retrieving fundamental ratios for Apple • 48 Memory • 53 Short-term (working) memory • 53 Long-term memory • 61 Episodic memory • 61 Semantic memory • 70 Procedural memory • 71 Retrieval-augmented generation (RAG) • 72 Reasoning patterns ................................................................................................................. 74 Task-level reasoning patterns • 74 Planning • 74 ReAct • 78 Thought-based reasoning patterns • 81 Chain-of-thought: CoT • 81 Self-consistency • 81 Quality patterns ...................................................................................................................... 83 Reflection • 84 LLM-as-a-judge • 85 Hands-on lab: Implementing a financial news agent with the evaluator–optimizer pattern • 86 Guardrails • 92 Orchestration patterns ............................................................................................................ 93 What is a sequential multi-agent orchestration? • 94 Table of Contents viii
Page 10
Hands-on lab: Investment recommendation using profitability and valuation ratios • 94 System architecture • 95 Implementation and run • 95 Challenges in designing AI agents ......................................................................................... 102 Context engineering • 102 Key contextual elements • 103 Selecting the right context • 104 Ensuring context fits within the limits of the context window • 104 Memory management • 106 Implementation mechanisms of memory • 106 Forgetting and memory maintenance • 107 Summary .............................................................................................................................. 107 Bibliography ......................................................................................................................... 108 Chapter 3: AI Agent Frameworks in Finance 109 Technical requirements .......................................................................................................... 110 The rise of AI agent frameworks in finance ............................................................................. 111 Why AI agent frameworks matter in finance • 111 From prompts to agents • 112 Criteria that matter in finance • 113 Understanding framework similarities and differences ......................................................... 113 Common framework capabilities • 113 Core orchestration • 114 Agent coordination • 114 Data integration • 115 Safety and validation • 115 Observability • 115 What differentiates frameworks • 116 Survey of key frameworks ...................................................................................................... 116 LangChain/LangGraph: Modular orchestration and RAG • 117 Key features and strengths • 117 Limitations • 118 Finance use cases • 119 Decision fit • 119 Google ADK (Agent Development Kit) • 119 ix Table of Contents
Page 11
Key features and strengths • 120 Limitations • 121 Finance use cases • 121 Decision fit • 121 CrewAI: Role-based multi-agent collaboration • 121 Key features and strengths • 122 Limitations • 123 Finance use cases • 123 Decision fit • 123 AutoGen: Conversational orchestration for finance • 124 Key features and strengths • 124 Limitations • 126 Finance use cases • 126 Decision fit • 126 OpenAI Agents SDK • 127 Key features and strengths • 127 Limitations • 128 Finance use cases • 128 Decision fit • 129 PydanticAI: Type-safe agents for structured financial data • 129 Key features and strengths • 129 Limitations • 130 Finance use cases • 130 Decision fit • 130 Mistral AI agents: Lightweight, open-weight performance • 131 Key features and strengths • 132 Limitations • 132 Finance use cases • 132 Decision fit • 133 smolagents (Hugging Face): Minimalist code-first agents • 133 Key features and strengths • 133 Limitations • 134 Finance use cases • 134 Decision fit • 135 Claude Agent SDK (Anthropic): Safe-by-design agentic workflows • 135 Table of Contents x
Page 12
Key features and strengths • 135 Limitations • 137 Finance use cases • 137 Decision fit • 137 LlamaIndex: Data-centric agents for finance • 138 Key features and strengths • 138 Limitations • 139 Finance use cases • 139 Decision fit • 140 Positioning the frameworks • 140 Decision framework: How to pick the right one ..................................................................... 143 Evaluation method at a glance • 143 Decision dimensions (what to score) • 144 Scoring rubric (0–5) • 145 Compact decision matrix (starter view) • 147 Scenario playbooks • 150 Governance and risk checklist • 151 Anti-patterns (what to avoid) • 152 Migration and hybrid patterns • 152 Request for Proposal and architecture questions (copy for vendors) • 153 Understanding and optimizing token costs • 154 Case study: Comparing frameworks on a single task .............................................................. 157 OpenAI Agents SDK • 159 LangChain • 160 AutoGen • 161 PydanticAI • 163 Framework comparison and summary • 164 Summary ............................................................................................................................... 165 Bibliography ......................................................................................................................... 166 Framework documentation • 166 Industry deployments referenced in this chapter • 167 Chapter 4: Building a Fundamental Analysis Agentic System 169 Technical requirements ......................................................................................................... 170 Understanding the basics of fundamental analysis ................................................................ 171 xi Table of Contents
Page 13
The three financial statements • 172 The income statement • 172 The balance sheet • 173 The cash flow statement • 173 Key ratios and what they signify • 174 Valuation ratios • 174 Profitability ratios • 175 Liquidity and leverage ratios • 176 Growth metrics • 176 Cash flow ratios • 177 Dividend ratios • 177 Qualitative factors • 178 Why fundamental analysis is hard to automate, and why agents help • 179 Designing the agentic architecture ....................................................................................... 180 Single-agent vs. multi-agent: Why specialization wins • 180 The agentic system architecture • 181 Building the specialized agents ............................................................................................. 183 FinancialDataAgent • 183 NewsAndSentimentAgent • 187 RiskAgent • 191 ValuationAgent • 194 ReportWriterAgent • 200 OrchestratorAgent • 205 The orchestration pattern: Agents as tools • 210 Building the tools ................................................................................................................... 212 Financial tools (tools/financial_tools.py) • 212 Tool 1: Get income statement • 213 Tools 2 and 3: Get balance sheet and cash flow • 215 Tool 4: Compute key ratios • 216 Valuation tools (tools/valuation_tools.py) • 219 Tool 1: DCF model • 219 Tool 2: Peer multiples comparison • 223 News tools (tools/news_tools.py) • 226 Tool 1: Search recent news • 226 Tool 2: Analyze sentiment • 228 Table of Contents xii
Page 14
Running the agentic system .................................................................................................. 232 Running the pipeline with the SDK runner • 233 The entry point • 235 Sample output: Apple Inc. (AAPL) • 236 Behind the scenes: Issues encountered and how we fixed them ............................................ 239 LLMs should not classify values they did not compute • 239 Instructions placed after the output they govern are often ignored • 239 Agents must be instructed to keep sections self-contained • 239 LLMs add editorial interpretations that are not sourced from the data • 240 Shared tools should be cached to avoid redundant API calls • 240 Parallel execution must be verified, not assumed • 240 Chain-of-thought reasoning should be built into agent instructions, not left implicit • 240 Agents versus humans in investment decision making ......................................................... 241 What to build next ................................................................................................................ 241 Summary .............................................................................................................................. 242 Chapter 5: Deep Search – Analyst-Grade Research with AI Agents 245 Technical requirements ......................................................................................................... 246 What is deep search? ............................................................................................................. 247 Deep search vs. basic RAG • 247 Why deep search matters in finance • 249 The deep research landscape • 250 Decoding the anatomy of a deep search agent ........................................................................ 251 The core loop • 251 Key architectural components • 252 Three architectural approaches • 254 Approach 1: Single agent with ReAct loop • 254 Approach 2: Multi-agent with specialized roles • 254 Approach 3: Deep orchestrator with MCP • 255 Financial data: The real challenge ......................................................................................... 257 The data landscape • 257 Why financial data is "adversarial" • 258 Key lessons for building financial data tools • 260 Tool integration patterns • 261 Building a deep search agent step by step .............................................................................. 262 xiii Table of Contents
Page 15
Architecture decisions • 263 Data models • 264 The planner • 265 The tool layer • 267 The researcher (task executor) • 267 The validator • 268 The synthesizer • 269 The orchestrator: Putting it all together • 270 Assessing production considerations .................................................................................... 272 Lessons from production: Fintool • 272 Context management at scale • 273 Cost optimization • 274 Evaluation: How do you know your agent is correct? • 275 Learning from open-source deep research agents ................................................................. 277 Dexter – Autonomous financial research agent • 277 AI Alliance Deep Research Agent • 278 ai-hedge-fund – Multi-agent investment analysis • 280 Commercial platforms • 281 Hands-on lab: Building a financial deep search agent ........................................................... 282 Goals, prerequisites, and structure • 283 Setting up • 284 Running the agent • 284 Code walkthrough • 285 Sample output • 286 Extension ideas • 287 Summary .............................................................................................................................. 288 Bibliography ......................................................................................................................... 288 Open-source projects • 288 Articles and blog posts • 288 Research papers • 289 Commercial platforms • 289 Benchmarks • 289 Documentation and APIs • 289 291 Table of Contents xiv
Page 16
Chapter 6: Implementing Reasoning Paradigms for Financial Agents Technical requirements ......................................................................................................... 293 Self-refine (reflection) ........................................................................................................... 294 Mechanism • 294 Self-refine in finance • 296 Hands-on lab: Self-refine investment thesis generator • 297 Step 1: Defining the generator • 298 Step 2: Defining the feedback provider • 298 Step 3: Defining the refiner • 300 Step 4: Running the self-refine loop • 301 Lab results • 302 Self-consistency .................................................................................................................... 306 Mechanism • 306 Sampling algorithms • 308 Self-consistency in finance • 309 Hands-on lab: Self-consistency investment recommendation • 310 Step 1: Configuring the model and the CoT system prompt • 311 Step 2: Sampling a single reasoning path • 312 Step 3: Aggregating the majority vote • 313 Step 4: Running the workflow • 314 Lab results • 315 ReAct ...................................................................................................................................... 317 Mechanism • 318 ReAct in finance • 319 Hands-on lab: ReAct valuation agent • 320 Tools • 321 The ReAct format • 324 The agent loop • 324 Running the agent • 325 Lab results • 326 CRITIC .................................................................................................................................. 329 Mechanism • 329 CRITIC in finance • 331 Reflexion ............................................................................................................................... 332 xv Table of Contents
Page 17
Mechanism • 333 Reflexion in finance • 334 Tree-of-thoughts .................................................................................................................. 336 Mechanism • 338 Hands-on lab: Two-level ToT for a pre-earnings equity hedge • 338 Lab results • 344 Language Agent Tree Search (LATS) ...................................................................................... 348 Mechanism • 349 Selection • 349 Expansion • 350 Evaluation • 350 Simulation • 350 Backpropagation • 351 Reflection • 351 Hands-on lab: LATS for a tech-sector trim • 352 Lab results • 361 Choosing a reasoning paradigm ............................................................................................ 367 Summary .............................................................................................................................. 368 Bibliography ......................................................................................................................... 369 Chapter 7: Multi-Agent Systems and Architectural Styles 371 Technical requirements ......................................................................................................... 372 Defining multi-agent systems ............................................................................................... 373 Understanding the limits of single agents ............................................................................. 373 Deciding when multi-agent systems are worth it • 374 Design patterns vs. architectural styles • 376 Architectural styles for multi-agent financial systems .......................................................... 377 Sequential (pipeline) • 377 Financial use case: Fundamental analysis pipeline • 377 Strengths • 378 Weaknesses • 378 When to use • 378 Leader-follower (orchestrator–worker) • 378 Financial use case: Portfolio analysis with a manager agent • 379 Strengths • 379 Table of Contents xvi
Page 18
Weaknesses • 379 When to use • 380 Hierarchical • 380 Financial use case: Enterprise risk management • 381 Strengths • 381 Weaknesses • 382 When to use • 382 Peer-to-peer (decentralized) • 382 Financial use case: Multi-perspective investment analysis • 383 Strengths • 384 Weaknesses • 384 When to use • 385 Parallelization • 385 Financial use case: Multi-company earnings analysis • 385 Strengths • 386 Weaknesses • 386 When to use • 387 Evaluator–optimizer (LLM-as-a-judge) • 387 Financial use case: Trading strategy code refinement • 387 Strengths • 388 Weaknesses • 388 When to use • 388 Contract-net marketplace (mediator + bids) • 388 Financial use case: Dynamic research routing • 389 Why this matters in finance • 389 Strengths • 389 Weaknesses • 390 When to use • 390 Additional patterns: Brief overview • 391 Choosing and combining architectural styles ........................................................................ 391 Matching scenarios to architectural styles • 392 Combining styles: Hybrid patterns in practice • 392 Evolving your architecture: A phased approach • 395 Communicating and coordinating between agents ............................................................... 396 How agents talk: Message passing vs. shared state • 396 xvii Table of Contents
Page 19
Handoffs: Transferring control between agents • 398 Resolving conflicts: When agents disagree • 399 Controlling flow: Static vs. dynamic coordination • 401 Negotiating for shared resources • 402 Mapping architectural styles to financial domains ................................................................ 402 Designing for domain-specific constraints • 403 Implementing multi-agent patterns: A framework walkthrough ........................................ 404 The reference task: Multi-agent financial health analysis • 405 Implementation 1: LlamaIndex AgentWorkflow (sequential pipeline with handoffs) • 406 Implementation 2: OpenAI Agents SDK (leader-follower with dynamic routing) • 407 Implementation 3: AutoGen (conversational multi-agent) • 408 Comparing the three approaches • 410 Taking multi-agent systems to production ........................................................................... 412 Observing and tracing multi-agent behavior • 412 Handling errors across agent boundaries • 413 Managing context across agents • 414 Controlling token costs • 415 Testing multi-agent systems • 416 Knowing when to stop adding agents • 416 Hands-on lab: Building a multi-agent financial health analyzer ............................................ 417 Lab overview • 417 Setting up the environment • 418 Building the multi-agent system • 418 Step 1: Defining the shared state and tools • 419 Step 2: Defining financial health thresholds • 419 Step 3: Configuring the agents • 420 Step 4: Creating and running the workflow • 421 Step 5: Executing and observing • 421 Extension: Adding the evaluator–optimizer pattern • 422 Extension: Parallel multi-company analysis • 423 Summary .............................................................................................................................. 424 Bibliography ......................................................................................................................... 425 Table of Contents xviii
Page 20
Chapter 8: Designing Multi-Agent Trading Systems: From Investment Committee to Adversarial Debate 427 Technical requirements ......................................................................................................... 429 Part A – Building a multi-agent investment committee with LangGraph .............................. 430 How investment decisions are really made • 430 What an efficient market already prices in • 430 The four canonical information lenses • 432 Why no single lens is enough • 436 The investment committee as a multi-agent system • 437 Why orchestration fits regulated finance • 438 The six roles in the model committee • 438 Translating the committee into LangGraph • 439 State as a shared workspace • 440 Fan-out to specialists, fan-in to the portfolio manager • 441 Case study: A multi-agent analysis of TESLA • 442 Hands-on lab: Implementing the committee • 443 Importing dependencies and configuring models • 444 Defining the shared state • 445 Retrieving deterministic market data • 445 Implementing the four specialist analyst nodes • 449 Synthesizing recommendations with the portfolio manager • 452 Validating recommendations with the risk officer • 454 Assembling and running the graph • 455 Orchestrating the agentic workflow • 456 Backtesting the architecture (and what a research-grade version would require) • 457 Why LLM-agent backtests are different • 457 What to measure • 459 Walk-forward as the right backtesting approach • 459 Hands-on lab: A minimal backtest harness • 460 Where this backtest simplifies reality • 465 Where the committee pattern reaches its limits • 465 Part B - Stress-testing the committee with an adversarial debate layer ................................. 466 Why a committee alone is not enough • 466 Confirmation bias within a single hierarchy • 466 xix Table of Contents
The above is a preview of the first 20 pages. Register to read the complete e-book.

Recommended for You

Loading recommended books...
Failed to load, please try again later

Tip the Site

Scan the WeChat Pay or Alipay code to tip. No login required.

WeChat Pay
Alipay
Back to List