Skip to content

Claude/trading council setup xezm r#186

Open
yuters777 wants to merge 19 commits intokarpathy:masterfrom
yuters777:claude/trading-council-setup-xezmR
Open

Claude/trading council setup xezm r#186
yuters777 wants to merge 19 commits intokarpathy:masterfrom
yuters777:claude/trading-council-setup-xezmR

Conversation

@yuters777
Copy link
Copy Markdown

No description provided.

claude and others added 19 commits December 2, 2025 22:59
…ic, and Google

- Add backend/llm_providers.py with provider-agnostic ModelConfig and call_model() interface
- Implement direct API integrations for OpenAI, Anthropic, and Google Gemini
- Update config.py to use ModelConfig objects instead of string identifiers
- Remove OpenRouter dependency (openrouter.py deleted)
- Update documentation (README.md, CLAUDE.md) with new API key setup instructions
- Implement shared HTTP client with connection pooling for better performance
- Add retry with exponential backoff for transient failures (429, 502, 503, timeouts)
- Replace print() statements with structured logging (logger.error/warning/debug)
- Add specific exception handling for HTTPStatusError, TimeoutException, RequestError
- Register graceful shutdown handler using FastAPI lifespan context manager
- Truncate response bodies in error logs to avoid leaking sensitive data
Backend changes:
- llm_providers.py: Add Attachment TypedDict and provider-specific formatters
  - OpenAI: image_url with data URLs, PDFs as image_url
  - Anthropic: Native image and document content blocks
  - Google: inlineData parts with mimeType
- council.py: Pass attachments through stage1_collect_responses()
- main.py: Add AttachmentModel with validation, accept attachments in endpoints

Frontend changes:
- api.js: Add fileToBase64, validateFile, formatAttachments helpers
- ChatInterface.jsx: Add file upload UI with preview and remove buttons
- ChatInterface.css: Styling for attachment preview, error messages

Supported file types:
- Images: jpg, jpeg, png, gif, webp
- Documents: pdf, txt, csv, json, md
- Max file size: 20MB per file

Note: Attachments only sent to Stage 1. Stages 2 and 3 evaluate text only.
Define MarketSnapshot input schema with all nested models (Override, GeoStress,
EmaGate, CryptoOverride, CrossAsset, Session) and TradingDecision output schema
with ModelVote, ConsensusResult, and TradingMeta. All nested fields are Optional
to accept partial snapshots. Trading config defines 3 weighted council models
(claude=0.40, gpt=0.35, gemini=0.25) with temperature=0.3.

https://claude.ai/code/session_01ReQPKyCWTuys1a7DCVBFp9
Create 6 markdown prompt templates in backend/prompts/trading/:
- system_base.md: Framework hierarchy, decision rules, JSON response format
- override_change.md: OVERRIDE_STATE_CHANGE trigger analysis
- geostress_alert.md: GEOSTRESS_ALERT trigger with stress severity assessment
- morning_briefing.md: MORNING_BRIEFING with news/movers placeholders
- conflicting_signals.md: CONFLICTING_SIGNALS with hierarchy resolution
- unusual_pattern.md: UNUSUAL_PATTERN with signal-vs-noise assessment

https://claude.ai/code/session_01ReQPKyCWTuys1a7DCVBFp9
…tep 3)

Implements backend/trading_council.py with 5 function groups:
- Prompt building: load_prompt_template, load_system_prompt, build_prompts
- 3-tier response parsing: direct JSON, markdown block, regex, fallback HOLD
- Consensus aggregation: weighted confidence, majority/unanimous/split handling
- Telegram alert formatting: emoji per trigger type, < 300 chars
- Main orchestrator: async analyze_trading() pipeline via call_models_parallel()

No direct API calls — all LLM calls go through llm_providers module.

https://claude.ai/code/session_01ReQPKyCWTuys1a7DCVBFp9
Add trading council endpoint isolated from existing conversation routes.
Imports MarketSnapshot/TradingDecision models and analyze_trading orchestrator.
Health check now returns trading_enabled status. Proper error handling with
503 (disabled) and 500 (failure) responses. All existing routes unchanged.

https://claude.ai/code/session_01ReQPKyCWTuys1a7DCVBFp9
Comprehensive pytest suite covering:
- Parsing: 5 tests for 3-tier JSON fallback (clean, markdown, regex, partial, garbage)
- Consensus: 4 tests for unanimous, majority, 3-way split, weighted confidence
- Pipeline: 3 tests verifying Stage 2 skip for OVERRIDE/GEOSTRESS triggers
- Models: 3 tests for minimal/full MarketSnapshot and TradingDecision round-trip
- Alerts: 3 tests for emoji prefixes, VIX display, and 300-char limit

All LLM calls mocked with AsyncMock. No real API calls during test execution.

https://claude.ai/code/session_01ReQPKyCWTuys1a7DCVBFp9
CLAUDE.md: Add technical section documenting new files, API endpoint,
call flow, trigger types, config, JSON parsing fallback strategy,
cost estimates, and integration architecture.

README.md: Add user-facing section with setup instructions, sample curl
command, and abbreviated response format. Placed before Tech Stack section.

No existing content modified in either file.

https://claude.ai/code/session_01ReQPKyCWTuys1a7DCVBFp9
Covers both General Council and Trading Council modes: file map, provider
layer (ModelConfig, retry logic, connection pooling, provider quirks),
full pipeline flows, all Pydantic data models, configuration settings,
API endpoints, prompt templates with trigger mappings, and dependency graph.

https://claude.ai/code/session_01RyfdUHFutBNF4a9okw6Sji
…ture-6ah29

Add comprehensive ARCHITECTURE.md documenting backend structure
- Add OpenAI-Project header to _call_openai() for project-scoped API keys
- Replace shutdown gemini-3-pro-preview with gemini-2.5-flash in trading config

https://claude.ai/code/session_01ReQPKyCWTuys1a7DCVBFp9
- Section 3: Add OpenAI-Project header note under OpenAI quirks
- Section 7: Update General Council claude model to claude-sonnet-4-6-20250415
- Section 7: Update Trading Council claude to claude-sonnet-4-6-20250415,
  gemini to gemini-2.5-pro
- Section 7: Add note that gemini-3-pro-preview was shut down March 9, 2026

https://claude.ai/code/session_01ReQPKyCWTuys1a7DCVBFp9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants