agentson
e3b1ecc572
feat: context aggregation scheduler (issue #87 )
...
CI / test (pull_request) Has been cancelled
- Add ContextScheduler with run_if_due() for periodic rollups
- Weekly (Sunday), monthly (last day), quarterly, annual, legacy schedules
- Daily cleanup of expired contexts via ContextStore
- Dedup guard: each task runs at most once per day
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-10 04:26:51 +09:00
agentson
78021d4695
feat: EOD aggregation with market filter (issue #86 )
...
CI / test (pull_request) Has been cancelled
- Add market parameter to aggregate_daily_from_trades() for per-market L6 aggregation
- Store market-scoped keys (total_pnl_KR, win_rate_US, etc.) in L6/L5/L4 layers
- Hook aggregate_daily_from_trades() into market close detection in run()
- Update tests for market-scoped context keys
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-10 04:23:49 +09:00
agentson
f03cc6039b
fix: derive all aggregation timeframes from trade timestamp ( #112 )
...
CI / test (pull_request) Has been cancelled
run_all_aggregations() previously used datetime.now(UTC) for weekly
through annual layers while using the trade date only for daily,
causing data misalignment on backfill. Now all layers consistently
use the latest trade timestamp. Also adds "Z" suffix handling for
fromisoformat() compatibility and strengthens test assertions to
verify L4-L2 layer values end-to-end.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-02-10 00:40:28 +09:00
agentson
61f5aaf4a3
fix: resolve linting issues in token efficiency implementation
...
CI / test (pull_request) Has been cancelled
- Fix ambiguous variable names (l → layer)
- Remove unused imports and variables
- Organize import statements
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2026-02-04 18:35:55 +09:00
agentson
4f61d5af8e
feat: implement token efficiency optimization for issue #24
...
Implement comprehensive token efficiency system to reduce LLM costs:
- Add prompt_optimizer.py: Token counting, compression, abbreviations
- Add context_selector.py: Smart L1-L7 context layer selection
- Add summarizer.py: Historical data aggregation and summarization
- Add cache.py: TTL-based response caching with hit rate tracking
- Enhance gemini_client.py: Integrate optimization, caching, metrics
Key features:
- Compressed prompts with abbreviations (40-50% reduction)
- Smart context selection (L7 for normal, L6-L5 for strategic)
- Response caching for HOLD decisions and high-confidence calls
- Token usage tracking and metrics (avg tokens, cache hit rate)
- Comprehensive test coverage (34 tests, 84-93% coverage)
Metrics tracked:
- Total tokens used
- Avg tokens per decision
- Cache hit rate
- Cost per decision
All tests passing (191 total, 76% overall coverage).
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2026-02-04 18:09:51 +09:00
agentson
917b68eb81
feat: implement L1-L7 context tree for multi-layered memory management
...
CI / test (pull_request) Has been cancelled
Implements Pillar 2 (Multi-layered Context Management) with a 7-tier
hierarchical memory system from real-time market data to generational
trading wisdom.
## New Modules
- `src/context/layer.py`: ContextLayer enum and metadata config
- `src/context/store.py`: ContextStore for CRUD operations
- `src/context/aggregator.py`: Bottom-up aggregation (L7→L6→...→L1)
## Database Changes
- Added `contexts` table for hierarchical data storage
- Added `context_metadata` table for layer configuration
- Indexed by layer, timeframe, and updated_at for fast queries
## Context Layers
- L1 (Legacy): Cumulative wisdom (kept forever)
- L2 (Annual): Yearly metrics (10 years retention)
- L3 (Quarterly): Strategy pivots (3 years)
- L4 (Monthly): Portfolio rebalancing (2 years)
- L5 (Weekly): Stock selection (1 year)
- L6 (Daily): Trade logs (90 days)
- L7 (Real-time): Live market data (7 days)
## Tests
- 18 new tests in `tests/test_context.py`
- 100% coverage on context modules
- All 72 tests passing (54 existing + 18 new)
## Documentation
- Added `docs/context-tree.md` with comprehensive guide
- Updated `CLAUDE.md` architecture section
- Includes usage examples and best practices
Closes #15
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2026-02-04 14:12:29 +09:00