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.
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.
- Communicate with the assistant using everyday language
- Intelligent parsing of transaction details
- Context-aware responses and clarifications
- Multi-turn conversations for complex queries
- 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)
- 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
- Integrated stock research capabilities
- Real-time market data integration
- Company information lookup
- Sector-specific analysis
- Automated research summaries
- Secure SQLite database storage
- Vector-based search for transaction notes
- Efficient data retrieval and querying
- Data backup and export capabilities
- 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
- Python 3.10 or higher
- OpenAI API key
- Poetry package manager
- Git (for version control)
- Clone the repository:
git clone https://github.com/kirushikesh/investors-diary.git
cd investors-diary
- Install dependencies using Poetry:
poetry install
- Set up environment variables:
OPENAI_API_KEY=sk-...
TAVILY_API_KEY=tvly-...
- Start the FastAPI server:
poetry run python src/app/server.py
- Launch the Streamlit interface:
poetry run python src/app/client.py
(OR)
- 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"
- ....
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
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
The main application follows the Supervisor design pattern, implemented using LangGraph's StateGraph:
builder = StateGraph(MainState)
- Primary Assistant (Supervisor)
- Acts as the central coordinator
- Routes user requests to specialized agents
- Manages workflow transitions
- Handles task delegation and completion
- 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,
],
)
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:
- Initial Draft
- Creates initial research response
- Utilizes available tools and context
- Self-Reflection
- Analyzes response quality
- Identifies missing information
- Evaluates response completeness
- Iterative Improvement
- Conducts additional research based on reflection
- Refines answer through multiple iterations
- Maximum iterations controlled: MAX_ITERATIONS = 2
Uses LangGraph's state management to maintain context across interactions Implements checkpointing using MemorySaver:
memory = MemorySaver()
main_graph = builder.compile(
checkpointer=memory,
)
- Custom tools for each agent type
- Fallback mechanisms for error handling
- Structured tool responses using Pydantic models
- Modularity: Each agent handles specific responsibilities
- Scalability: Easy to add new agents and functionalities
- Maintainability: Clear separation of concerns
- Reliability: Built-in error handling and fallback mechanisms
- 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.
- Portfolio performance visualization
- Custom reporting capabilities
- Real-time price alerts and notifications
- Multi-user support with authentication
- Integration with financial news APIs
- Adding Long-Term memory for each user for customized interactions
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.
This project is licensed under the MIT License - see the LICENSE file for details.
- LangGraph Supervisor design pattern: https://langchain-ai.github.io/langgraph/tutorials/customer-support/customer-support/
- LangGraph Reflexion pattern: https://langchain-ai.github.io/langgraph/tutorials/reflexion/reflexion/
- LangServe Connectivity: https://python.langchain.com/docs/langserve/