Commit Graph

80 Commits

Author SHA1 Message Date
Surapong Kanoktipsatharporn 3fcc24e8bf Add Z.AI GLM and TNG DeepSeek R1T2 Chimera models to OpenRouter
- Added Z.AI GLM 4.5 Air (free) and GLM 4.6 to quick-thinking options
- Added Z.AI GLM 4.5 Air (free) and GLM 4.6 to deep-thinking options
- Added TNG DeepSeek R1T2 Chimera (free and paid) for advanced reasoning
- Improved Google Gemini 2.0 Flash Exp description for consistency

These models provide additional OpenRouter options for:
- Cost-effective reasoning with free GLM 4.5 Air
- Advanced versatile performance with GLM 4.6
- Specialized reasoning capabilities with DeepSeek R1T2 Chimera
2025-10-20 17:13:32 +07:00
Surapong Kanoktipsatharporn bc221c1e74 feat: integrate comprehensive logging system into CLI
- Enhanced cli/main.py with structured logging throughout
- Added logging to MessageBuffer class for agent tracking
- Integrated performance monitoring and API call tracking
- Enhanced error handling with full stack traces
- Added contextual logging to all key operations

Features:
- Session start/end logging with statistics
- User selection and configuration logging
- Agent status transition tracking
- Tool call logging with arguments
- Report generation tracking with metadata
- Performance timing for operations
- Automatic log rotation to prevent disk space issues

Documentation:
- Created comprehensive CLI logging integration guide
- Added logging quick reference card
- Included integration summary with examples

Testing:
- Added test_cli_logging.py for validation
- All tests passing with proper log file generation

Benefits:
- Better debugging with structured, contextual logs
- Performance monitoring and bottleneck identification
- Complete audit trail for compliance
- API cost tracking and optimization
- Production-ready with enterprise-grade logging
- Maintains backward compatibility with legacy log files
2025-10-20 16:24:31 +07:00
Surapong Kanoktipsatharporn cfc0250f95 Update .gitignore with comprehensive Python project patterns 2025-10-20 16:16:28 +07:00
Surapong Kanoktipsatharporn d73397480e fix: Add proper API key validation for all LLM providers
- Add explicit API key retrieval and validation for OpenRouter, OpenAI, Anthropic, and Google providers
- Pass api_key parameter explicitly to ChatOpenAI, ChatAnthropic, and ChatGoogleGenerativeAI constructors
- Provide helpful error messages with instructions when API keys are missing
- Fixes 401 Authentication Error when using OpenRouter without OPENROUTER_API_KEY set

Previously, ChatOpenAI would default to looking for OPENAI_API_KEY even when using OpenRouter,
causing authentication failures. Now each provider correctly uses its own API key.

Resolves authentication issues across all supported LLM providers.
2025-10-20 16:10:21 +07:00
Surapong Kanoktipsatharporn c8a056e1a4 docs: Add comprehensive feature branch summary
Complete summary of all work done on feature/separate-embedding-client branch:

## Summary Highlights
- 3 major features implemented (embedding separation, logging, configuration)
- 19 files changed (13 new, 6 modified)
- ~4,600 lines of code added
- 4,200+ lines of documentation
- 8 commits with clean history
- 100% backward compatible
- Production ready

## Features Delivered
1. Embedding provider separation (primary feature)
2. Comprehensive logging system (bonus)
3. Complete configuration documentation (enhanced UX)

## Documentation
- 9 comprehensive markdown files
- 7 deployment scenarios with examples
- Complete API reference
- Troubleshooting guides
- Best practices

## Tools Created
- Environment setup checker
- Config verifier
- Logging system test
- Integration test suite

Ready for code review and merge to main.
2025-10-20 15:53:50 +07:00
Surapong Kanoktipsatharporn 08bad661c3 docs: Comprehensive .env.example and configuration guide
Major updates to environment configuration:

## .env.example Updates (291 lines)
- Added 7 deployment scenarios with complete examples
- Scenario 1: OpenAI Everything (Production)
- Scenario 2: OpenRouter + OpenAI Embeddings (Cost Optimized)
- Scenario 3: All Local with Ollama (Privacy/Offline)
- Scenario 4: Anthropic + OpenAI Embeddings (High Quality)
- Scenario 5: Google Gemini + OpenAI Embeddings (Balanced)
- Scenario 6: OpenRouter + No Memory (Minimal)
- Scenario 7: Mixed Models (Advanced)

Each scenario includes:
- Complete configuration example
- Use case description
- Pros/cons analysis
- Cost estimates
- Prerequisites

## New Documentation
- docs/CONFIGURATION_GUIDE.md (691 lines)
  - Complete setup guide for all scenarios
  - API key acquisition instructions
  - CLI vs Module usage comparison
  - Environment variable reference
  - Troubleshooting section
  - Security best practices

## Additional Features
- API key sources and links
- Security notes and best practices
- Troubleshooting common issues
- Configuration validation checklist
- Multiple deployment patterns
- Cost optimization strategies

Makes it easy for users to:
- Choose the right setup for their needs
- Understand cost implications
- Configure mixed provider scenarios
- Troubleshoot authentication issues
- Switch between CLI and module usage
2025-10-20 15:52:02 +07:00
Surapong Kanoktipsatharporn 3eab3e81cb docs: Add comprehensive logging implementation summary 2025-10-20 15:48:56 +07:00
Surapong Kanoktipsatharporn c9d3eff62e feat: Implement comprehensive logging system
Adds a production-ready logging system with the following features:

## Core Features
- Structured logging with rich context and metadata
- Multiple log levels (DEBUG, INFO, WARNING, ERROR, CRITICAL)
- File and console output with separate handlers
- Automatic log rotation (prevents disk space issues)
- Component-specific loggers for different parts of the system
- Performance tracking with built-in metrics
- API call tracking with cost and token monitoring

## New Components
- tradingagents/utils/logging_config.py: Core logging module
  - TradingAgentsLogger: Main logger class
  - StructuredFormatter: Custom formatter with context
  - APICallLogger: Dedicated API call tracking
  - PerformanceLogger: Operation timing and metrics

## Log Files Created (in logs/ directory)
- tradingagents.log: All application logs (10MB rotation, 5 backups)
- errors.log: Errors only (5MB rotation, 3 backups)
- api_calls.log: API call tracking
- memory.log: Memory operations
- agents.log: Agent execution
- performance.log: Performance metrics

## Integration
- Updated memory.py: Full logging integration with context
  - Logs initialization, embeddings, add/get operations
  - Tracks API calls and performance
  - Provides detailed error context

- Updated trading_graph.py: Comprehensive graph logging
  - Logs initialization, propagation, reflection
  - Tracks component setup and execution
  - Performance metrics for all major operations

- Updated default_config.py: Added logging configuration
  - log_level, log_dir, log_to_console, log_to_file

## Documentation
- docs/LOGGING.md: Complete logging documentation (797 lines)
  - Quick start guide
  - Configuration examples
  - Best practices
  - API reference
  - Troubleshooting

## Benefits
- Better debugging and troubleshooting
- Production monitoring capabilities
- API cost tracking
- Performance analysis
- Audit trail for decisions
- Easier issue diagnosis

Tested and working. See docs/LOGGING.md for complete usage guide.
2025-10-20 15:47:29 +07:00
Surapong Kanoktipsatharporn 9dc69a931a feat: Update check_env_setup to load and verify .env file
- Now checks for .env file existence and location
- Loads environment variables from .env file automatically
- Provides fallback .env parser if python-dotenv not installed
- Shows which API keys are configured from .env
- Gives specific guidance based on what's found/missing
2025-10-20 15:39:17 +07:00
Surapong Kanoktipsatharporn ea6c74e46b feat: Add environment setup checker script
- Checks which API keys are configured
- Shows status for OpenAI, OpenRouter, Anthropic, Google
- Provides setup instructions for common scenarios
- Helps users debug authentication errors
2025-10-20 15:34:19 +07:00
Surapong Kanoktipsatharporn dde1632939 fix: Move component initialization back to __init__, keep only config in _configure_embeddings
The _configure_embeddings method was incorrectly trying to initialize
graph components (conditional_logic, graph_setup, etc.) which caused
an AttributeError because tool_nodes hadn't been created yet.

This fix:
- Moves component initialization back to __init__ method
- Keeps only embedding configuration logic in _configure_embeddings
- Maintains correct initialization order
2025-10-20 15:32:01 +07:00
Surapong Kanoktipsatharporn 2869ab3c5f feat: Separate embedding configuration from chat model configuration
This commit implements a comprehensive solution for separating embedding
and chat model configurations, enabling flexible provider combinations
and graceful handling of embedding failures.

## Problem Statement

Previously, the TradingAgents memory system used the same backend_url for
both chat models and embeddings. This caused critical failures when:

- Using OpenRouter for chat (doesn't support OpenAI embedding endpoints)
- Using Anthropic/Google for chat (don't provide embeddings)
- The embedding endpoint returned HTML error pages instead of JSON
- Users wanted to mix providers (e.g., OpenRouter chat + OpenAI embeddings)

Error example:
  AttributeError: 'str' object has no attribute 'data'
  # Caused by: OpenRouter returned HTML page instead of embedding JSON

## Solution

Implemented three key features:

1. **Separate Embedding Client Configuration**
   - New config parameters independent of chat LLM settings
   - embedding_provider: "openai", "ollama", or "none"
   - embedding_backend_url: Separate API endpoint
   - embedding_model: Specific model to use
   - enable_memory: Boolean flag to enable/disable memory

2. **Multiple Provider Support**
   - OpenAI: Production-grade embeddings (recommended)
   - Ollama: Local embeddings for offline/development
   - None: Disable memory system entirely

3. **Graceful Fallback**
   - System continues when embeddings fail
   - Comprehensive error logging
   - Memory operations return empty results instead of crashing
   - Agents function without historical context when memory disabled

## Changes

### Core Framework
- tradingagents/default_config.py: Added 4 new embedding config params
- tradingagents/agents/utils/memory.py: Complete refactor with error handling
- tradingagents/graph/trading_graph.py: Separated embedding initialization

### CLI/User Interface
- cli/utils.py: Added select_embedding_provider() function
- cli/main.py: Added Step 7 for embedding provider selection

### Documentation (New Files)
- docs/EMBEDDING_CONFIGURATION.md: Complete usage guide (381 lines)
- docs/EMBEDDING_MIGRATION.md: Implementation details (374 lines)
- CHANGELOG_EMBEDDING.md: Release notes (225 lines)
- FEATURE_EMBEDDING_README.md: Branch overview (418 lines)

### Testing & Verification
- tests/test_embedding_config.py: Comprehensive test suite
- verify_config.py: Simple config verification script

## Example Usage

```python
# OpenRouter for chat, OpenAI for embeddings
config = {
    "llm_provider": "openrouter",
    "backend_url": "https://openrouter.ai/api/v1",
    "deep_think_llm": "deepseek/deepseek-chat-v3-0324:free",

    "embedding_provider": "openai",
    "embedding_backend_url": "https://api.openai.com/v1",
    "embedding_model": "text-embedding-3-small",
    "enable_memory": True,
}
```

## Backward Compatibility

 100% Backward Compatible - No breaking changes!

Existing configurations work without modification. Smart defaults
applied when embedding settings are omitted.

## Testing

- All core files pass diagnostics with no errors
- Configuration verification script passes all checks
- Supports scenarios: OpenRouter+OpenAI, All Ollama, Disabled Memory
- Graceful fallback tested for invalid URLs and missing API keys

## Benefits

- Enables using OpenRouter/other providers for chat
- Reduces costs (can use local embeddings or disable memory)
- Improves reliability (graceful degradation on failures)
- Maintains full backward compatibility
- Comprehensive documentation and examples

Fixes: OpenRouter compatibility issues
Closes: Embedding/chat provider coupling
Implements: Graceful fallback for memory operations
2025-10-20 15:24:51 +07:00
Edward Sun 13b826a31d
Merge pull request #245 from TauricResearch/feat/tooloptim
Y Finance Tools Optimizations
2025-10-09 00:34:10 -07:00
Edward Sun b2ef960da7 updated readme 2025-10-09 00:32:04 -07:00
Edward Sun a5dcc7da45 update readme 2025-10-06 20:33:12 -07:00
Edward Sun 7bb2941b07 optimized yfin fetching to be much faster 2025-10-06 19:58:01 -07:00
Yijia Xiao 32be17c606
Merge pull request #235 from luohy15/data_vendor
Add Alpha Vantage API Integration and Refactor Data Provider Architecture
2025-10-05 16:01:30 -07:00
Edward Sun c07dcf026b added fallbacks for tools 2025-10-03 22:40:09 -07:00
luohy15 d23fb539e9 minor fix 2025-09-30 13:27:48 +08:00
luohy15 b01051b9f4 Switch default data vendor
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-30 12:43:27 +08:00
luohy15 8fdbbcca3d alpha vantage api key url 2025-09-29 18:22:31 +08:00
luohy15 86bc0e793f minor fix 2025-09-27 00:04:59 +08:00
luohy15 7fc9c28a94 Add environment variable configuration support
- Add .env.example file with API key placeholders
- Update README.md with .env file setup instructions
- Add dotenv loading in main.py for environment variables

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-26 23:58:51 +08:00
luohy15 7bcc2cbd8a Update configuration documentation for Alpha Vantage data vendor
Add data vendor configuration examples in README and main.py showing how to configure Alpha Vantage as the primary data provider. Update documentation to reflect the current default behavior of using Alpha Vantage for real-time market data access.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-26 23:52:26 +08:00
luohy15 6211b1132a Improve Alpha Vantage indicator column parsing with robust mapping
- Replace hardcoded column indices with column name lookup
- Add mapping for all supported indicators to their expected CSV column names
- Handle missing columns gracefully with descriptive error messages
- Strip whitespace from header parsing for reliability

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-26 23:36:36 +08:00
luohy15 8b04ec307f minor fix 2025-09-26 23:25:33 +08:00
luohy15 0ab323c2c6 Add Alpha Vantage API integration as primary data provider
- Replace FinnHub with Alpha Vantage API in README documentation
- Implement comprehensive Alpha Vantage modules:
  - Stock data (daily OHLCV with date filtering)
  - Technical indicators (SMA, EMA, MACD, RSI, Bollinger Bands, ATR)
  - Fundamental data (overview, balance sheet, cashflow, income statement)
  - News and sentiment data with insider transactions
- Update news analyst tools to use ticker-based news search
- Integrate Alpha Vantage vendor methods into interface routing
- Maintain backward compatibility with existing vendor system

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-26 22:57:50 +08:00
luohy15 a6734d71bc WIP 2025-09-26 16:17:50 +08:00
Yijia Xiao a438acdbbd
Merge pull request #89 from Mirza-Samad-Ahmed-Baig/fixes
Enhancement: agent reflection, logging improvement
2025-07-03 10:15:39 -04:00
Yijia Xiao c73e374e7c
Update main.py 2025-07-03 10:14:06 -04:00
mirza-samad-ahmed-baig f704828f89 Fix: Prevent infinite loops, enable reflection, and improve logging 2025-07-03 17:43:40 +05:00
Edward Sun fda4f664e8
Merge pull request #49 from Zhongyi-Lu/a
Exclude `.env` from Git.
2025-07-01 09:17:46 -07:00
Yijia Xiao 718df34932
Merge pull request #29 from ZeroAct/save_results
Save results
2025-06-26 00:28:30 -04:00
Max Wong 43aa9c5d09
Local Ollama (#53)
- Fix typo 'Start' 'End'
- Add llama3.1 selection
- Use 'quick_think_llm' model instead of hard-coding GPT
2025-06-26 00:27:01 -04:00
Yijia Xiao 26c5ba5a78
Revert "Docker support and Ollama support (#47)" (#57)
This reverts commit 78ea029a0b.
2025-06-26 00:07:58 -04:00
Geeta Chauhan 78ea029a0b
Docker support and Ollama support (#47)
- Added support for running CLI and Ollama server via Docker
- Introduced tests for local embeddings model and standalone Docker setup
- Enabled conditional Ollama server launch via LLM_PROVIDER
2025-06-25 23:57:05 -04:00
Huijae Lee ee3d499894
Merge branch 'TauricResearch:main' into save_results 2025-06-25 08:43:19 +09:00
Yijia Xiao 7abff0f354
Merge pull request #46 from AtharvSabde/patch-2
Updated requirements.txt based on latest commit
2025-06-23 20:40:58 -04:00
Yijia Xiao b575bd0941
Merge pull request #52 from TauricResearch/dev
Merge dev into main. Add support for Anthropic and OpenRouter.
2025-06-23 20:38:14 -04:00
Zhongyi Lu b8f712b170 Exclude `.env` from Git 2025-06-21 23:29:26 -07:00
Edward Sun 52284ce13c fixed anthropic support. Anthropic has different format of response when it has tool calls. Explicit handling added 2025-06-21 12:51:34 -07:00
Atharv Sabde 11804f88ff
Updated requirements.txt based on latest commit
PULL REQUEST: Add support for other backends, such as OpenRouter and Ollama

it had two requirments missing. added those
2025-06-20 15:58:22 +05:30
Yijia Xiao 1e86e74314
Merge pull request #40 from RealMyth21/main
Updated README.md: Swap Trader and Management order.
2025-06-19 15:10:36 -04:00
Yijia Xiao c2f897fc67
Merge pull request #43 from AtharvSabde/patch-1
fundamentals_analyst.py (spelling mistake in instruction: Makrdown -> Markdown)
2025-06-19 15:05:08 -04:00
Yijia Xiao ed32081f57
Merge pull request #44 from TauricResearch/dev
Merge dev into main branch
2025-06-19 15:00:07 -04:00
Atharv Sabde 2af7ef3d79
fundamentals_analyst.py(spelling mistake.markdown) 2025-06-19 21:48:16 +05:30
Mithil Srungarapu 383deb72aa
Updated README.md
The diagrams were switched, so I fixed it.
2025-06-18 19:08:10 -07:00
Edward Sun 7eaf4d995f update clear msg bc anthropic needs at least 1 msg in chat call 2025-06-15 23:14:47 -07:00
Edward Sun da84ef43aa main works, cli bugs 2025-06-15 22:20:59 -07:00
Edward Sun 90b23e72f5
Merge pull request #25 from maxer137/main
Add support for other backends, such as OpenRouter and Ollama
2025-06-15 16:06:20 -07:00