9 AI agents
This chapter advances the book’s theme of turning large language models into practical research partners by showing how to build agentic, repeatable workflows for investment analysis. It reframes simple one-shot prompting into iterative, goal-directed processes that rely on three pillars: memory (via retrieval-augmented generation to inject fresh or private context), language/data access (through web search, APIs, and standardized connectors), and strategy (orchestration across multiple specialized models with peer review). It introduces four agentic design patterns—reflection, tool use, planning, and multi-agent collaboration—and maps them onto a reference research flow that begins with a trigger, gathers relevant context, generates and reviews analyses, and ends with durable storage of results.
Before reaching for frameworks, the chapter shows how to get most of the benefits with a notebook-based setup. You create a prompt repository—prompts with stable IDs, variables, and tags—so research stays comparable across companies, sectors, and catalysts. You connect to multiple LLMs, run structured studies, and centralize all outputs in Notion using its API, chunking long texts to respect limits. A reference workflow illustrates how an orchestrator can pull context from several sources—RAG databases that you maintain, live web search, and model context protocol endpoints—then query one or more LLMs with identical or complementary prompts, optionally add a reviewer step, and finally persist everything to a searchable knowledge base.
With frameworks, the chapter contrasts no-code builders like n8n with a code-first approach using LangChain. LangChain standardizes LLM calls across providers, integrates tools (for example, market news), and makes it straightforward to compose agents. A hands-on RAG example loads earnings-call transcripts, chunks and embeds them into a vector store, and executes a retrieve-then-generate graph (via LangGraph) to answer investment questions. By injecting investor preferences (such as pro/con LIDAR) into the context, the agent produces differentiated recommendations, demonstrating how tool use, planning, and structured memory yield more precise, auditable outputs. The takeaway: combine reusable prompts, disciplined storage, and agentic patterns to build adaptive AI research assistants that are comparable across studies and ready for production.
A reference workflow for an AI agent.
Shows a Notion journal with some reference entries. You can use Notion as a unified storage for all responses from multiple LLMs.
Reference content of an investment research that stores responses in Notion.
The execution graph from the RAG engines, which contains information retrieval from the RAG and output generation using RAG and LLM data.
Summary
- Communication with humans and artificial intelligence has parallels. You can enhance your communication skills by utilizing the right tools.
- To communicate more effectively, we can gain access to specific information sources that would otherwise be inaccessible, allowing us to strategize more effectively when communicating.
- We can store prompts in a simple database to reuse them later.
- If you want to research special topics, you can collect all prompts in a database and tag them to find them on demand.
- Notion is a note-taking tool that allows you to export all your research to one place.
- Without specialized frameworks to facilitate AI agents, working with LLMs requires a significant amount of custom work. For example, accessing specific data sources for retrieval-augmented generation requires writing a substantial amount of code to connect the data to an LLM.
- AI agents help automate and streamline conversations with AI.
- AI agents often have providers for additional data sources, which enables us to orchestrate LLMs to gain new insights.
- N8n is a no-code framework that orchestrates workflows using AI agents.
- LangChain is a framework for developing applications powered by large language models (LLMs). It can integrate different data sources into AI Agent workflows.
- LangChain streamlines access to LLMs. All calls to invoke prompts are therefore syntactically similar.
- LangChain has an extensive list of existing providers and provides an interface to programmers to add additional providers.
- Using LangChain, we can create AI agents that query recent financial news and then invoke a prompt in an LLM, incorporating the retrieved information into the analysis.
- LangChain provides a mechanism for logging the workflow of AI agents during their execution, offering valuable insights into how these agents operate.
- Retrieval-augmented generation (RAG) is an approach to providing an LLM with additional data beyond its training data.
- We can hold additional information for response generation in a vector database. For this, we need to prepare the data by converting it into specific data structures, known as vector embeddings.
- In many complex use cases, we need a data platform such as an RAG database. For simple use cases, an in-memory vector database is fine.
- We can create execution workflows as a graph that orchestrates workflows.
FAQ
How do AI agents improve investment research compared to basic one-shot LLM prompting?
Agents move beyond single Q&A toward structured, multi-step workflows. They can plan, retrieve fresh data, use tools/APIs, coordinate multiple models, and export results to a unified store (for example, Notion). This delivers more reliable, comparable, and reusable research than ad hoc prompts.What are the four agentic design patterns and why do they matter?
- Reflection: Iteratively evaluate outputs against goals and refine next steps (like a trading bot reviewing KPIs after market close).- Tool use: Call external tools/APIs (price feeds, news, sentiment) to expand capabilities beyond the base model.
- Planning: Create and adapt multi-step plans dynamically based on objectives and constraints.
- Multi-agent collaboration: Combine specialized agents (optimist, skeptic, adjudicator) to improve robustness and synthesis.
How can I give an LLM “memory” or access to fresh/private data?
- Use retrieval-augmented generation (RAG): store documents as embeddings in a vector database and retrieve relevant chunks at query time.- Web search: integrate search tools to inject recent public information.
- MCPs (Model Context Protocol): standardized, real-time access to data/services purpose-built for LLMs, reducing custom ingestion jobs.
These approaches supplement model knowledge without retraining.
What does a typical end-to-end AI-agent workflow for portfolio research look like?
- Trigger: scheduled job, user query (even via messengers), or market alert.- Retrieval: pull context via RAG DBs, web search, and/or MCP tools.
- Generation: run one or multiple LLMs (same prompt for diversity, or role-specific prompts such as bull/bear).
- Review: optional peer-review/aggregation by a separate LLM.
- Output: persist results to a system like Notion for organization, tagging, and later fact-checking.
How do I build agentic workflows without specialized frameworks?
- Maintain a prompt repository (IDs, prompt text, variables/placeholders) in a simple DB like SQLite.- Connect to one or more LLM providers and run prompts from a notebook.
- Export all inputs/outputs to a central store (for example, Notion) so research isn’t scattered across chat UIs.
How should I structure a reusable prompt repository?
- Table prompt: id (for example, swot_analysis), prompt (text with placeholders like {company}).- Table tag: tag_name, prompt_id for n:m tagging (industry, catalyst, event types like earnings_call).
- Benefits: reuse across companies, comparable outputs, easier discovery by context.
How can I capture and organize LLM outputs in Notion?
- Create pages via Notion’s REST API using your database_id (from the page URL).- Build a title property and create the page (POST /v1/pages).
- Write content blocks (PATCH /v1/blocks/{page_id}/children). Notion limits writes to about 2,000 characters per operation, so chunk the text.
- Store both the prompt and the answer for auditability and later review.
What does LangChain add beyond native LLM SDKs?
- Unified interface: invoke() works consistently across providers (OpenAI, Anthropic, etc.).- Agents and tools: easy integration of external tools such as Yahoo Finance news; the agent selects tools and incorporates observations into answers.
- Composability: chains, memory, and integrations that simplify building complex, multi-step applications.
How do I build a minimal RAG pipeline with LangChain for earnings research?
- Load documents: earnings call transcripts and investor context (for example, pro/con LIDAR stance).- Chunk: split text (for example, RecursiveCharacterTextSplitter) for retrieval granularity.
- Embed and index: create embeddings (for example, text-embedding-3-large) and store in a vector store (for example, InMemoryVectorStore for demos).
- Retrieve + Generate: retrieve top-matching chunks by similarity, then pass the question and retrieved context to the LLM to produce the answer.
- Orchestrate: compose steps in a simple graph/state machine (retrieve → generate) and invoke with the user’s question.
Should I use a no-code tool like n8n or a code framework like LangChain?
- No-code (n8n): faster to prototype via UI, good for teams with limited programming capacity, integrates common services quickly.- Code (LangChain): greater flexibility, custom logic, fine-grained control, and easier production-hardening for complex/unique workflows.
Choose based on complexity, customization needs, and available engineering resources.
Investing for Programmers ebook for free