sigma-terminal 2.0.1__py3-none-any.whl → 3.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,298 @@
1
+ Metadata-Version: 2.4
2
+ Name: sigma-terminal
3
+ Version: 3.2.0
4
+ Summary: Sigma - Finance Research Agent
5
+ Project-URL: Homepage, https://github.com/desenyon/sigma
6
+ Project-URL: Documentation, https://github.com/desenyon/sigma/wiki
7
+ Project-URL: Repository, https://github.com/desenyon/sigma
8
+ Author: Sigma Team
9
+ License: Proprietary
10
+ License-File: LICENSE
11
+ Keywords: ai,analytics,backtesting,finance,investment,macos,portfolio,quantitative,research,stocks,terminal,trading
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: MacOS X
14
+ Classifier: Intended Audience :: Financial and Insurance Industry
15
+ Classifier: License :: Other/Proprietary License
16
+ Classifier: Operating System :: MacOS
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Office/Business :: Financial :: Investment
20
+ Requires-Python: >=3.11
21
+ Requires-Dist: aiohttp>=3.9.0
22
+ Requires-Dist: anthropic>=0.18.0
23
+ Requires-Dist: google-genai>=1.0.0
24
+ Requires-Dist: groq>=0.4.0
25
+ Requires-Dist: httpx>=0.26.0
26
+ Requires-Dist: kaleido>=0.2.1
27
+ Requires-Dist: numpy>=1.26.0
28
+ Requires-Dist: openai>=1.12.0
29
+ Requires-Dist: pandas>=2.2.0
30
+ Requires-Dist: pillow>=10.2.0
31
+ Requires-Dist: plotext>=5.2.8
32
+ Requires-Dist: plotly>=5.18.0
33
+ Requires-Dist: pydantic-settings>=2.1.0
34
+ Requires-Dist: pydantic>=2.6.0
35
+ Requires-Dist: pyobjc-framework-cocoa>=10.0; sys_platform == 'darwin'
36
+ Requires-Dist: python-dotenv>=1.0.0
37
+ Requires-Dist: requests>=2.31.0
38
+ Requires-Dist: rich>=13.7.0
39
+ Requires-Dist: scipy>=1.12.0
40
+ Requires-Dist: textual>=0.47.0
41
+ Requires-Dist: yfinance>=0.2.36
42
+ Provides-Extra: all
43
+ Requires-Dist: black>=24.0.0; extra == 'all'
44
+ Requires-Dist: lean>=1.0.0; extra == 'all'
45
+ Requires-Dist: mypy>=1.8.0; extra == 'all'
46
+ Requires-Dist: py2app>=0.28.0; extra == 'all'
47
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == 'all'
48
+ Requires-Dist: pytest>=8.0.0; extra == 'all'
49
+ Requires-Dist: ruff>=0.2.0; extra == 'all'
50
+ Provides-Extra: dev
51
+ Requires-Dist: black>=24.0.0; extra == 'dev'
52
+ Requires-Dist: mypy>=1.8.0; extra == 'dev'
53
+ Requires-Dist: py2app>=0.28.0; extra == 'dev'
54
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
55
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
56
+ Requires-Dist: ruff>=0.2.0; extra == 'dev'
57
+ Provides-Extra: lean
58
+ Requires-Dist: lean>=1.0.0; extra == 'lean'
59
+ Description-Content-Type: text/markdown
60
+
61
+ # Sigma
62
+
63
+ <div align="center">
64
+
65
+ ```
66
+ _____ _
67
+ / ___/(_)___ _____ ___ ____ _
68
+ \__ \/ / __ `/ __ `__ \/ __ `/
69
+ ___/ / / /_/ / / / / / / /_/ /
70
+ /____/_/\__, /_/ /_/ /_/\__,_/
71
+ /____/
72
+ ```
73
+
74
+ **Finance Research Agent**
75
+
76
+ Native macOS | Multi-Provider AI | Real-Time Data
77
+
78
+ ---
79
+
80
+ [Installation](#installation) | [Usage](#usage) | [Commands](#commands) | [Configuration
81
+ ](#configuration)
82
+
83
+ ---
84
+
85
+ ## Overview
86
+
87
+ Sigma is an AI-powered Finance Research Agent that runs natively on macOS. Ask questions in natural language, get comprehensive market analysis, charts, and backtests in seconds.
88
+
89
+ ---
90
+
91
+ ## Installation
92
+
93
+ ## Via Brew
94
+
95
+ ```bash
96
+ brew tap desenyon/sigma
97
+ brew install sigma
98
+ # or if you want app (experimental)
99
+ brew install --cask sigma
100
+ ```
101
+
102
+ ### Via pip
103
+
104
+ ```bash
105
+ pip install sigma-terminal
106
+ sigma --setup
107
+ ```
108
+
109
+ ### From source
110
+
111
+ ```bash
112
+ git clone https://github.com/desenyon/sigma.git
113
+ cd sigma
114
+ pip install -e .
115
+ sigma --setup
116
+ ```
117
+
118
+ ---
119
+
120
+ ## Usage
121
+
122
+ ### Interactive Mode
123
+
124
+ ```bash
125
+ sigma
126
+ ```
127
+
128
+ Launch the full terminal interface with:
129
+
130
+ - Natural language queries with autocomplete
131
+ - Real-time market data
132
+ - Interactive charts and analysis
133
+ - Conversation history
134
+
135
+ ### CLI Mode
136
+
137
+ ```bash
138
+ sigma ask "analyze AAPL technicals"
139
+ sigma quote AAPL MSFT GOOGL
140
+ sigma compare NVDA AMD INTC
141
+ sigma backtest TSLA --strategy macd_momentum
142
+ sigma chart SPY --period 1y
143
+ ```
144
+
145
+ ---
146
+
147
+ ## Commands
148
+
149
+ | Command | Description |
150
+ | --------------------------- | ----------------------- |
151
+ | `sigma` | Launch interactive mode |
152
+ | `sigma ask "<query>"` | Ask a question |
153
+ | `sigma quote <symbols>` | Get stock quotes |
154
+ | `sigma compare <symbols>` | Compare multiple stocks |
155
+ | `sigma backtest <symbol>` | Run a backtest |
156
+ | `sigma chart <symbol>` | Generate a chart |
157
+ | `sigma --setup` | Run setup wizard |
158
+ | `sigma --status` | Show configuration |
159
+ | `sigma --list-models` | List available models |
160
+
161
+ ### Interactive Commands
162
+
163
+ | Command | Description |
164
+ | -------------------- | ------------------------ |
165
+ | `/help` | Show available commands |
166
+ | `/clear` | Clear chat history |
167
+ | `/keys` | Configure API keys |
168
+ | `/models` | Show available models |
169
+ | `/provider <name>` | Switch AI provider |
170
+ | `/backtest` | Show backtest strategies |
171
+ | `/status` | Show configuration |
172
+ | `/export` | Export conversation |
173
+
174
+ ---
175
+
176
+ ## Features
177
+
178
+ ### AI Providers
179
+
180
+ | Provider | Models | Notes |
181
+ | ------------- | ------------------------------------- | ------------------- |
182
+ | Google Gemini | gemini-2.0-flash, 1.5-pro | Free tier available |
183
+ | OpenAI | gpt-4o, gpt-4o-mini | Best reasoning |
184
+ | Anthropic | Claude claude-sonnet-4-20250514, Opus | Deep analysis |
185
+ | Groq | Llama 3.3 70B | Ultra-fast |
186
+ | xAI | Grok 2 | Real-time knowledge |
187
+ | Ollama | Llama, Mistral, Phi | Local, private |
188
+
189
+ ### Market Data
190
+
191
+ - Real-time quotes and price data
192
+ - Historical OHLCV with adjustments
193
+ - Technical indicators (RSI, MACD, Bollinger, MAs)
194
+ - Fundamental data and financials
195
+ - Analyst recommendations
196
+ - Insider and fund activity
197
+
198
+ ### Analysis
199
+
200
+ - Performance metrics (Sharpe, Sortino, Calmar)
201
+ - Risk analysis (VaR, drawdowns, volatility)
202
+ - Sector and market overview
203
+ - Multi-asset comparison
204
+ - Regime detection
205
+ - Seasonality patterns
206
+
207
+ ### Backtesting
208
+
209
+ | Strategy | Description |
210
+ | ---------------------- | ---------------------------- |
211
+ | `sma_crossover` | SMA 20/50 crossover |
212
+ | `rsi_mean_reversion` | RSI oversold/overbought |
213
+ | `macd_momentum` | MACD signal crossover |
214
+ | `bollinger_bands` | Bollinger band bounce |
215
+ | `dual_momentum` | Absolute + relative momentum |
216
+ | `breakout` | Price breakout system |
217
+
218
+ ### Visualization
219
+
220
+ - Candlestick charts with volume
221
+ - Technical overlays
222
+ - Performance curves
223
+ - Comparison charts
224
+
225
+ ---
226
+
227
+ ## Configuration
228
+
229
+ Configuration is stored in `~/.sigma/`.
230
+
231
+ ### Environment Variables
232
+
233
+ ```bash
234
+ export GOOGLE_API_KEY="your-key"
235
+ export OPENAI_API_KEY="your-key"
236
+ export ANTHROPIC_API_KEY="your-key"
237
+ ```
238
+
239
+ ### Config File
240
+
241
+ Create `~/.sigma/config.env`:
242
+
243
+ ```
244
+ DEFAULT_PROVIDER=google
245
+ DEFAULT_MODEL=gemini-2.0-flash
246
+ GOOGLE_API_KEY=your-key
247
+ ```
248
+
249
+ ---
250
+
251
+ ## Keyboard Shortcuts
252
+
253
+ | Shortcut | Action |
254
+ | ----------- | ------------------ |
255
+ | `Ctrl+L` | Clear screen |
256
+ | `Ctrl+K` | Configure API keys |
257
+ | `Ctrl+M` | Show models |
258
+ | `Ctrl+C` | Exit |
259
+ | `Tab` | Autocomplete |
260
+ | `Up/Down` | History navigation |
261
+
262
+ ---
263
+
264
+ ## Examples
265
+
266
+ ```bash
267
+ # Get a quick stock overview
268
+ sigma ask "give me a summary of AAPL"
269
+
270
+ # Technical analysis
271
+ sigma ask "what do the technicals say about NVDA?"
272
+
273
+ # Compare stocks
274
+ sigma ask "compare AAPL MSFT GOOGL performance this year"
275
+
276
+ # Backtest a strategy
277
+ sigma ask "backtest SMA crossover on SPY for 2 years"
278
+
279
+ # Market overview
280
+ sigma ask "how are the markets doing today?"
281
+
282
+ # Sector analysis
283
+ sigma ask "which sectors are performing best?"
284
+ ```
285
+
286
+ ---
287
+
288
+ ## License
289
+
290
+ Proprietary - See [LICENSE](LICENSE)
291
+
292
+ ---
293
+
294
+ <div align="center">
295
+
296
+ **Sigma v3.2.0 - Finance Research Agent**
297
+
298
+ </div>
@@ -0,0 +1,30 @@
1
+ sigma/__init__.py,sha256=NDQ0Kx9WQOPwYgILmCtDFH_NUTaMvs5lmIMAhTvjFWg,3545
2
+ sigma/__main__.py,sha256=JR33oXObSRLsirM_8pvzTIUBr16QXS294WkQRIFI95g,114
3
+ sigma/app.py,sha256=f4ZX_8ctPEWbu5t8xk_2yB-Q_idPlvP_pi6_mHLCHlw,21228
4
+ sigma/backtest.py,sha256=7hImn0A4eO6gokWVLKERWqapN1N-T9ohc8Vof1XJo-0,13258
5
+ sigma/charts.py,sha256=-mosf43yHrXqZGss_dvhfoi6gAAppRd9YZEtHGagzm8,11815
6
+ sigma/cli.py,sha256=vf2YNM5E_wS7Kk3FvuhKv0KXhgVv4QLKqAvGdcS2bn0,15426
7
+ sigma/comparison.py,sha256=cI0VGSMiQfUjTu5BpSAYUEzo7Kf-yCo0I4kr1S87rgo,21686
8
+ sigma/config.py,sha256=cwQp2fua3cgWGmV-K_swKdlFITMVae38JDixxAhCOSI,6267
9
+ sigma/llm.py,sha256=6fFIcfVh4714fBkEXcLm7_Rfs2EPA_eOALpQ2rkhUZU,14611
10
+ sigma/monitoring.py,sha256=7iC9DaTX8dFIygwAyEgpFQFpLPQrmLg6UW1bBeB_n7M,22672
11
+ sigma/portfolio.py,sha256=ySypECWntDfa4pRVrNgxRsNDyOCEEgTOCUhrQIiMgBY,24020
12
+ sigma/reporting.py,sha256=3qzuG-uITeO2z9ENOst4QcJSY2z8FyJs_eGQVe7JGM4,19157
13
+ sigma/robustness.py,sha256=rvy-LQx9b7IZRYTI1srnL_yrVWeNAwcUFra0YSD6ZrE,23502
14
+ sigma/setup.py,sha256=-UpLYBxyldP-FnI_vupvp67d2peN_Kv5SY4stC1eJ18,12779
15
+ sigma/strategy.py,sha256=1IucLv3vcWyQgAsMhav6Q1qf-i3yk3obYEdaOkRA4Nw,28881
16
+ sigma/tools.py,sha256=L2u2uaeO_bC7RnbSLjHUBqQW11lNzTYmAAVLu7aI5v4,21609
17
+ sigma/visualization.py,sha256=w5amseNd-sO8oCUpE_jnZFQD2xW-Twx6W6kk6xSb-ZA,24749
18
+ sigma/analytics/__init__.py,sha256=NrcxlzsxMkURMiN-o3Ou6CxFKFX-VD_HDWW8SrI1aDM,22999
19
+ sigma/core/__init__.py,sha256=vpMwe22zgDRze9LuGumTNvyRS2rzaeAgNd9_4dkaFrk,136
20
+ sigma/core/engine.py,sha256=u8Z8ecvrPzaqyijHDjI4rDfdTpNjbAhxqx-5ahR8-0A,17566
21
+ sigma/core/intent.py,sha256=w3VOUIH7fQ0nSrG2Ch9l9CVfSU7dp0wqz5FCSu3e3HQ,23519
22
+ sigma/core/models.py,sha256=IkpvIK28rvGsjqV9cvC3NhbdiHaRmNzEJUevJkpLGyA,15745
23
+ sigma/data/__init__.py,sha256=nqFtjuuTGhEO7bs-eVAzesKIf0w7U_38qgkGi5O53Ek,23896
24
+ sigma/data/models.py,sha256=Zoh4s90ihPPVpUw3Nh5SqInNzf7l-jB8_I1de1OUDNQ,3694
25
+ sigma/tools/backtest.py,sha256=xYunp_dm46uGBw0pxNcWsSh4UuLmE1xuaHvWzzmcGv4,53869
26
+ sigma_terminal-3.2.0.dist-info/METADATA,sha256=fiS8qgVJRCnu1awtlOv-Mc7jLwT-DdusFxxjdztIiNc,7797
27
+ sigma_terminal-3.2.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
28
+ sigma_terminal-3.2.0.dist-info/entry_points.txt,sha256=lFpcHMWvr4jUIO-MRrBwKhxWp-AIsRJDaWMU4dOQzlw,121
29
+ sigma_terminal-3.2.0.dist-info/licenses/LICENSE,sha256=YGf6UbSNXayxJnonOYohaDbbV1yZQfQ1wyStkTuHS6w,1099
30
+ sigma_terminal-3.2.0.dist-info/RECORD,,
@@ -0,0 +1,6 @@
1
+ [console_scripts]
2
+ sigma = sigma.cli:main
3
+ sigma-setup = sigma.setup:run_setup
4
+
5
+ [gui_scripts]
6
+ sigma-app = sigma.app:launch
@@ -0,0 +1,25 @@
1
+ PROPRIETARY SOFTWARE LICENSE
2
+
3
+ Copyright (c) 2024-2026 Sigma. All Rights Reserved.
4
+
5
+ NOTICE: This software and its documentation are proprietary to Sigma
6
+ and are protected by copyright law and international treaties.
7
+
8
+ RESTRICTIONS:
9
+ 1. This software is licensed, not sold.
10
+ 2. You may not copy, modify, distribute, sell, or transfer this software.
11
+ 3. You may not reverse engineer, decompile, or disassemble this software.
12
+ 4. You may not use this software for commercial purposes without written permission.
13
+ 5. You may not remove or alter any proprietary notices or labels.
14
+
15
+ DISCLAIMER:
16
+ THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+
20
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+
25
+ For licensing inquiries, contact: legal@sigma.finance
sigma/core/agent.py DELETED
@@ -1,205 +0,0 @@
1
- """Sigma Research Agent."""
2
-
3
- import asyncio
4
- import time
5
- from datetime import datetime
6
- from typing import Any, Callable, Optional
7
-
8
- from sigma.core.config import LLMProvider, get_settings
9
- from sigma.core.llm import get_llm, BaseLLM
10
- from sigma.core.models import Message, MessageRole, ToolCall, ToolResult
11
- from sigma.tools.financial import get_all_tools, execute_tool
12
-
13
-
14
- SYSTEM_PROMPT = """You are Sigma, an elite quantitative financial research analyst and AI-powered trading strategist. You have institutional-grade expertise in markets, securities analysis, algorithmic trading, and investment research.
15
-
16
- CRITICAL CONSTRAINT: You ONLY respond to finance, investing, trading, and market-related queries.
17
- - If a user asks about non-financial topics, politely redirect them to financial topics
18
- - Example: "I specialize in financial analysis. I can help you with stock analysis, market research, portfolio optimization, or trading strategies. What financial topic would you like to explore?"
19
-
20
- Your capabilities include:
21
-
22
- MARKET DATA & ANALYSIS
23
- - Real-time stock quotes and market data
24
- - Historical price analysis and charting
25
- - Sector performance and market indices
26
- - Options chain analysis
27
-
28
- TECHNICAL ANALYSIS
29
- - Price charts (line, candle, area)
30
- - Moving averages (SMA, EMA)
31
- - RSI, MACD, Bollinger Bands
32
- - Support/resistance levels
33
- - Technical signals and patterns
34
-
35
- FUNDAMENTAL ANALYSIS
36
- - Financial statements (income, balance sheet, cash flow)
37
- - Valuation metrics (P/E, P/B, PEG, EV/EBITDA)
38
- - Earnings and revenue analysis
39
- - Profitability ratios (ROE, ROA, margins)
40
-
41
- PREDICTIONS & FORECASTING
42
- - Price predictions using multiple models
43
- - Sentiment analysis
44
- - Risk assessment
45
- - Monte Carlo simulations
46
-
47
- INSTITUTIONAL FEATURES
48
- - Analyst recommendations and price targets
49
- - Insider trading activity
50
- - Institutional holdings
51
- - Short interest data
52
-
53
- ALGORITHMIC TRADING
54
- - Generate LEAN engine backtests
55
- - Strategy templates (SMA crossover, RSI mean reversion, MACD momentum, etc.)
56
- - Custom strategy builder
57
- - Backtest parameter optimization
58
-
59
- When answering:
60
- 1. ALWAYS use tools to get real, current data - never make up numbers
61
- 2. Provide specific metrics and data points
62
- 3. Present analysis in clear, structured formats
63
- 4. Include risk factors and caveats
64
- 5. Give actionable insights with reasoning
65
- 6. Use charts when visualizing would help
66
- 7. Compare to benchmarks and peers when relevant
67
-
68
- For comprehensive analysis, use multiple tools:
69
- 1. get_stock_quote → Current price and key metrics
70
- 2. get_company_info → Business context and fundamentals
71
- 3. get_analyst_recommendations → Wall Street sentiment
72
- 4. technical_analysis → Price action and signals
73
- 5. get_financial_statements → Deep fundamental analysis
74
- 6. sentiment_analysis → Multi-factor sentiment
75
- 7. price_forecast → Forward-looking projections
76
-
77
- For charts and visualization:
78
- - generate_price_chart → Beautiful terminal price charts
79
- - generate_comparison_chart → Compare multiple stocks
80
- - generate_rsi_chart → Price with RSI indicator
81
- - generate_sector_chart → Sector performance overview
82
-
83
- For backtesting and strategy:
84
- - list_backtest_strategies → Available strategies
85
- - generate_backtest → Create LEAN algorithm
86
- - generate_custom_backtest → Custom strategy builder
87
-
88
- Your analysis should match the quality of Goldman Sachs, Morgan Stanley, and Citadel research."""
89
-
90
-
91
- class SigmaAgent:
92
- """Financial research agent."""
93
-
94
- def __init__(
95
- self,
96
- provider: Optional[LLMProvider] = None,
97
- model: Optional[str] = None,
98
- ):
99
- self.settings = get_settings()
100
- self.provider = provider or self.settings.default_provider
101
- self.llm: BaseLLM = get_llm(self.provider, model)
102
- self.messages: list[Message] = []
103
- self.tools = get_all_tools()
104
- self.tool_results: list[ToolResult] = []
105
- self._reset()
106
-
107
- def _reset(self):
108
- """Reset conversation."""
109
- self.messages = [
110
- Message(role=MessageRole.SYSTEM, content=SYSTEM_PROMPT)
111
- ]
112
- self.tool_results = []
113
-
114
- async def run(
115
- self,
116
- query: str,
117
- on_tool_start: Optional[Callable[[str, dict], None]] = None,
118
- on_tool_end: Optional[Callable[[str, Any, float], None]] = None,
119
- on_thinking: Optional[Callable[[str], None]] = None,
120
- on_response: Optional[Callable[[str], None]] = None,
121
- ) -> str:
122
- """Run the agent on a query."""
123
- self.messages.append(Message(role=MessageRole.USER, content=query))
124
- self.tool_results = []
125
-
126
- iteration = 0
127
- start_time = time.time()
128
-
129
- while iteration < self.settings.max_iterations:
130
- iteration += 1
131
-
132
- # Get LLM response
133
- try:
134
- content, tool_calls = await self.llm.generate(
135
- messages=self.messages,
136
- tools=self.tools,
137
- )
138
- except Exception as e:
139
- return f"Error: {str(e)}"
140
-
141
- # If no tool calls, we're done
142
- if not tool_calls:
143
- if content:
144
- self.messages.append(Message(role=MessageRole.ASSISTANT, content=content))
145
- if on_response:
146
- on_response(content)
147
- return content
148
- continue
149
-
150
- # Record assistant message with tool calls
151
- self.messages.append(Message(
152
- role=MessageRole.ASSISTANT,
153
- content=content,
154
- tool_calls=tool_calls,
155
- ))
156
-
157
- if on_thinking and content:
158
- on_thinking(content)
159
-
160
- # Execute tools
161
- for tc in tool_calls:
162
- tool_start = time.time()
163
-
164
- if on_tool_start:
165
- on_tool_start(tc.name, tc.arguments)
166
-
167
- result = await execute_tool(tc.name, tc.arguments)
168
-
169
- duration_ms = (time.time() - tool_start) * 1000
170
-
171
- tool_result = ToolResult(
172
- tool_name=tc.name,
173
- tool_call_id=tc.id,
174
- success="error" not in str(result).lower(),
175
- result=result,
176
- duration_ms=duration_ms,
177
- )
178
- self.tool_results.append(tool_result)
179
-
180
- if on_tool_end:
181
- on_tool_end(tc.name, result, duration_ms)
182
-
183
- # Add tool result message
184
- self.messages.append(Message(
185
- role=MessageRole.TOOL,
186
- content=str(result),
187
- tool_call_id=tc.id,
188
- name=tc.name,
189
- ))
190
-
191
- return "Max iterations reached. Please try a simpler query."
192
-
193
- def get_stats(self) -> dict[str, Any]:
194
- """Get execution statistics."""
195
- total_time = sum(r.duration_ms for r in self.tool_results)
196
- return {
197
- "tools_called": len(self.tool_results),
198
- "total_time_ms": total_time,
199
- "successful": sum(1 for r in self.tool_results if r.success),
200
- "failed": sum(1 for r in self.tool_results if not r.success),
201
- }
202
-
203
- def clear(self):
204
- """Clear conversation history."""
205
- self._reset()
sigma/core/config.py DELETED
@@ -1,119 +0,0 @@
1
- """Configuration for Sigma."""
2
-
3
- from enum import Enum
4
- from pathlib import Path
5
- from typing import Optional
6
-
7
- from pydantic import Field, SecretStr
8
- from pydantic_settings import BaseSettings, SettingsConfigDict
9
-
10
-
11
- class LLMProvider(str, Enum):
12
- """LLM providers."""
13
- OPENAI = "openai"
14
- ANTHROPIC = "anthropic"
15
- GOOGLE = "google"
16
- OLLAMA = "ollama"
17
- XAI = "xai"
18
- GROQ = "groq"
19
-
20
-
21
- class Settings(BaseSettings):
22
- """Application settings."""
23
-
24
- model_config = SettingsConfigDict(
25
- env_file=".env",
26
- env_file_encoding="utf-8",
27
- extra="ignore",
28
- )
29
-
30
- # App
31
- app_name: str = "Sigma"
32
- debug: bool = False
33
-
34
- # LLM
35
- default_provider: LLMProvider = LLMProvider.GOOGLE
36
-
37
- # API Keys
38
- openai_api_key: Optional[SecretStr] = Field(default=None, alias="OPENAI_API_KEY")
39
- anthropic_api_key: Optional[SecretStr] = Field(default=None, alias="ANTHROPIC_API_KEY")
40
- google_api_key: Optional[SecretStr] = Field(default=None, alias="GOOGLE_API_KEY")
41
- xai_api_key: Optional[SecretStr] = Field(default=None, alias="XAI_API_KEY")
42
- groq_api_key: Optional[SecretStr] = Field(default=None, alias="GROQ_API_KEY")
43
-
44
- # Models
45
- openai_model: str = "gpt-4o"
46
- anthropic_model: str = "claude-sonnet-4-20250514"
47
- google_model: str = "gemini-2.0-flash"
48
- ollama_model: str = "llama3.2"
49
- xai_model: str = "grok-beta"
50
- groq_model: str = "llama-3.3-70b-versatile"
51
-
52
- # Ollama
53
- ollama_base_url: str = "http://127.0.0.1:11434"
54
-
55
- # Search
56
- exa_api_key: Optional[SecretStr] = Field(default=None, alias="EXASEARCH_API_KEY")
57
- tavily_api_key: Optional[SecretStr] = Field(default=None, alias="TAVILY_API_KEY")
58
- serper_api_key: Optional[SecretStr] = Field(default=None, alias="SERPER_API_KEY")
59
-
60
- # Financial
61
- financial_datasets_api_key: Optional[SecretStr] = Field(default=None, alias="FINANCIAL_DATASETS_API_KEY")
62
- fmp_api_key: Optional[SecretStr] = Field(default=None, alias="FMP_API_KEY")
63
- polygon_api_key: Optional[SecretStr] = Field(default=None, alias="POLYGON_API_KEY")
64
- alpha_vantage_api_key: Optional[SecretStr] = Field(default=None, alias="ALPHA_VANTAGE_API_KEY")
65
-
66
- # Agent
67
- max_iterations: int = 25
68
- max_tokens: int = 8192
69
- temperature: float = 0.1
70
-
71
- # Storage
72
- cache_dir: Path = Path.home() / ".sigma" / "cache"
73
- db_path: Path = Path.home() / ".sigma" / "sigma.db"
74
-
75
- def get_api_key(self, provider: LLMProvider) -> Optional[str]:
76
- """Get API key for provider."""
77
- keys = {
78
- LLMProvider.OPENAI: self.openai_api_key,
79
- LLMProvider.ANTHROPIC: self.anthropic_api_key,
80
- LLMProvider.GOOGLE: self.google_api_key,
81
- LLMProvider.XAI: self.xai_api_key,
82
- LLMProvider.GROQ: self.groq_api_key,
83
- }
84
- key = keys.get(provider)
85
- return key.get_secret_value() if key else None
86
-
87
- def get_model(self, provider: Optional[LLMProvider] = None) -> str:
88
- """Get model for provider."""
89
- provider = provider or self.default_provider
90
- models = {
91
- LLMProvider.OPENAI: self.openai_model,
92
- LLMProvider.ANTHROPIC: self.anthropic_model,
93
- LLMProvider.GOOGLE: self.google_model,
94
- LLMProvider.OLLAMA: self.ollama_model,
95
- LLMProvider.XAI: self.xai_model,
96
- LLMProvider.GROQ: self.groq_model,
97
- }
98
- return models.get(provider, self.google_model)
99
-
100
- def get_available_providers(self) -> list[LLMProvider]:
101
- """Get providers with API keys."""
102
- available = []
103
- for p in LLMProvider:
104
- if p == LLMProvider.OLLAMA:
105
- available.append(p)
106
- elif self.get_api_key(p):
107
- available.append(p)
108
- return available
109
-
110
-
111
- _settings: Optional[Settings] = None
112
-
113
-
114
- def get_settings() -> Settings:
115
- """Get settings singleton."""
116
- global _settings
117
- if _settings is None:
118
- _settings = Settings()
119
- return _settings