Skip to content

An LLM Agent based personal diary that manages the purchase and selling of the stocks using natural language.

License

Notifications You must be signed in to change notification settings

Kirushikesh/investors-diary

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Investors Diary

An intelligent LLM Agent-based personal diary that manages stock purchases and sales using natural language interaction. The application leverages advanced language models to understand user intent, process requests, and maintain detailed records of stock transactions along with reasoning behind investment decisions.

TLDR

Investors-Diary-An-LLM-Powered-S.mp4

If you a great listener than reader and love to know about this repo within few minutes. Listen to this podcast explaining why this is great and add more reasons why you should star this repository. Note: The Podcast made by NotebookLM by google may be inaccurate and factually incorrect sometimes nonetheless enjoy the podcast.

🌟 Features

Natural Language Interaction

  • Communicate with the assistant using everyday language
  • Intelligent parsing of transaction details
  • Context-aware responses and clarifications
  • Multi-turn conversations for complex queries

Transaction Management

  • Record stock purchases and sales with detailed metadata
  • Track transaction dates, quantities, and prices
  • Store reasoning behind investment decisions
  • Automatic calculation of total transaction amounts
  • Support for multiple transaction types (buy/sell)

Investment Analysis

  • Review historical transaction patterns
  • Generate insights from past investment decisions
  • Search and filter transactions by various parameters
  • Track performance across different sectors
  • Analyze investment distribution

Market Research

  • Integrated stock research capabilities
  • Real-time market data integration
  • Company information lookup
  • Sector-specific analysis
  • Automated research summaries

Data Management

  • Secure SQLite database storage
  • Vector-based search for transaction notes
  • Efficient data retrieval and querying
  • Data backup and export capabilities

πŸš€ Technology Stack

  • Backend Framework: FastAPI
  • Frontend: Streamlit
  • Database: SQLite with FAISS vector store
  • AI/ML:
    • LangChain Framework
    • OpenAI GPT Models
  • Development:
    • Python 3.10+
    • Poetry for dependency management

πŸ“‹ Prerequisites

  • Python 3.10 or higher
  • OpenAI API key
  • Poetry package manager
  • Git (for version control)

πŸ’» Installation

  1. Clone the repository:
git clone https://github.com/kirushikesh/investors-diary.git
cd investors-diary
  1. Install dependencies using Poetry:
poetry install
  1. Set up environment variables:
OPENAI_API_KEY=sk-...
TAVILY_API_KEY=tvly-...

🎯 Usage

  1. Start the FastAPI server:
poetry run python src/app/server.py
  1. Launch the Streamlit interface:
poetry run python src/app/client.py

(OR)

  1. Run the Agent in CLI
poetry run python src/core/graph_builder.py

Example interactions:

  • "I Bought 100 shares of AAPL at $150 each today"
  • "Show me all my Tesla transactions from last month"
  • "What was my reasoning for selling Microsoft shares?"
  • "Research the current market position of Amazon"
  • ....

πŸ—οΈ Project Structure

investors-diary/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ agents/              # LLM agent implementations
β”‚   β”‚   β”œβ”€β”€ analysis_agent.py
β”‚   β”‚   β”œβ”€β”€ research_agent.py
β”‚   β”‚   └── transaction_agent.py
|   |   ...
β”‚   β”œβ”€β”€ database/            # Database models and operations
β”‚   β”œβ”€β”€ tools/               # Custom tools for agents
β”‚   β”œβ”€β”€ prompts/             # Prompt templates
β”‚   └── utils/               # Helper utilities
β”œβ”€β”€ tests/                   # Test suite
β”œβ”€β”€ data/                    # Data storage
└── notebooks/              # Development notebooks

πŸ—οΈ Technical Architecture

LangGraph Implementation

The project leverages LangGraph, a powerful framework for building stateful, multi-agent workflows, to create a sophisticated investment management system. LangGraph facilitates:

  • State management across multiple agent interactions
  • Directed graph-based workflow orchestration
  • Conditional routing between different agents
  • Structured message passing between components

Supervisor Design Pattern

The main application follows the Supervisor design pattern, implemented using LangGraph's StateGraph:

builder = StateGraph(MainState)

Core Components:

  1. Primary Assistant (Supervisor)
  • Acts as the central coordinator
  • Routes user requests to specialized agents
  • Manages workflow transitions
  • Handles task delegation and completion
  1. Specialized Agents
  • Transaction Agent: Handles stock purchases and sales
  • Analysis Agent: Processes transaction analysis requests
  • RAG Agent: Manages retrieval of user stock notes
  • Research Agent: Conducts stock market research

Workflow Management:

builder.add_conditional_edges(
    "primary_assistant",
    route_primary_assistant,
    [
        "enter_add_transactions",
        "enter_retrieve_transactions",
        "enter_find_notes",
        "enter_research_stock_news",
        "primary_assistant_tools",
        END,
    ],
)

Stock Researcher's Reflexion Pattern

The Stock Research component uniquely implements the Reflexion design pattern, enabling self-improvement through iterative refinement:

sub_builder = StateGraph(SUBState)
sub_builder.add_node("draft", ResearchAgent)
sub_builder.add_node("execute_tools", create_tool_node_with_fallback(research_agents_tools))
sub_builder.add_node("revise", RevisorAgent)

Key Features:

  1. Initial Draft
  • Creates initial research response
  • Utilizes available tools and context
  1. Self-Reflection
  • Analyzes response quality
  • Identifies missing information
  • Evaluates response completeness
  1. Iterative Improvement
  • Conducts additional research based on reflection
  • Refines answer through multiple iterations
  • Maximum iterations controlled: MAX_ITERATIONS = 2

State Management

Uses LangGraph's state management to maintain context across interactions Implements checkpointing using MemorySaver:

memory = MemorySaver()
main_graph = builder.compile(
    checkpointer=memory,
)

Tool Integration

  • Custom tools for each agent type
  • Fallback mechanisms for error handling
  • Structured tool responses using Pydantic models

Key Benefits of This Architecture

  1. Modularity: Each agent handles specific responsibilities
  2. Scalability: Easy to add new agents and functionalities
  3. Maintainability: Clear separation of concerns
  4. Reliability: Built-in error handling and fallback mechanisms
  5. Flexibility: Easy to modify workflow routing and agent behavior This architecture enables the system to handle complex investment-related queries while maintaining context and providing accurate, well-researched responses through a combination of specialized agents and sophisticated control flow management.

Future Directions

Enhanced Analytics

  1. Portfolio performance visualization
  2. Custom reporting capabilities
  3. Real-time price alerts and notifications
  4. Multi-user support with authentication
  5. Integration with financial news APIs
  6. Adding Long-Term memory for each user for customized interactions

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ References

About

An LLM Agent based personal diary that manages the purchase and selling of the stocks using natural language.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published