Spaces:
Paused
Paused
File size: 12,011 Bytes
7e930a6 eea12dd 7e930a6 49c2560 7e930a6 49c2560 7e930a6 49c2560 7e930a6 eea12dd 7e930a6 aa162f5 7e930a6 a4ea1a8 7e930a6 a4ea1a8 eea12dd 7e930a6 eea12dd a4ea1a8 7e930a6 a4ea1a8 7e930a6 a4ea1a8 7e930a6 49c2560 7e930a6 eea12dd 7e930a6 eea12dd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | """
graph_config.py - Centralized Graph Configuration
==================================================
All configurable parameters for the graph orchestration system.
Modify these values to change graph behavior.
Author: AI Lab Team
Last Updated: 2025-10-10
Version: 3.1 - Added legacy compatibility constants
"""
import os
from typing import Dict, Any, List
# ============================================================================
# TIER SYSTEM CONFIGURATION
# ============================================================================
# Tier definitions with clear value propositions
TIER_LITE = "lite"
TIER_STANDARD = "standard"
TIER_FULL = "full"
TIER_CONFIGS = {
TIER_LITE: {
"name": "Lite",
"description": "Fast, basic responses for simple queries",
"max_cost": 0.50,
"max_execution_time": 60, # seconds
"qa_rework_cycles": 1,
"includes_planning": False,
"includes_experiments": False,
"includes_monitoring": False,
"use_cases": ["Quick questions", "Simple summaries", "Basic info"]
},
TIER_STANDARD: {
"name": "Standard",
"description": "Balanced quality and speed for most tasks",
"max_cost": 5.00,
"max_execution_time": 180, # seconds
"qa_rework_cycles": 2,
"includes_planning": True,
"includes_experiments": True,
"includes_monitoring": False,
"use_cases": ["Code generation", "Research", "Document creation"]
},
TIER_FULL: {
"name": "Full",
"description": "Premium quality with comprehensive refinement",
"max_cost": None, # Unlimited
"max_execution_time": 900, # seconds
"qa_rework_cycles": 10,
"includes_planning": True,
"includes_experiments": True,
"includes_monitoring": True,
"use_cases": ["Complex projects", "Production code", "Detailed research"]
}
}
# Default tier
DEFAULT_TIER = TIER_STANDARD
# ============================================================================
# EXECUTION CONTROL
# ============================================================================
# Maximum execution path length (safety limit)
MAX_EXECUTION_PATH_LENGTH = 150
# Node timeout settings
NODE_TIMEOUT_SECONDS = 60
ALLOW_TIMEOUT_RECOVERY = True
# Cost estimation
GPT4O_INPUT_COST_PER_1K_TOKENS = 0.005
GPT4O_OUTPUT_COST_PER_1K_TOKENS = 0.015
AVG_TOKENS_PER_CALL = 2000
# Budget multipliers (legacy compatibility)
BUDGET_BUFFER_MULTIPLIER = 1.20
MAX_COST_MULTIPLIER = 1.20
# ============================================================================
# LANGUAGE & CODING CONFIGURATION
# ============================================================================
DEFAULT_LANGUAGE = "python"
SUPPORTED_LANGUAGES = [
"python", "javascript", "typescript", "java",
"go", "rust", "cpp", "csharp", "php", "ruby"
]
LANGUAGE_PREFERENCE_KEYWORDS = {
"python": ["python", "py", "prefer python", "use python"],
"javascript": ["javascript", "js", "node", "prefer javascript"],
"typescript": ["typescript", "ts", "prefer typescript"],
"java": ["java", "prefer java"],
"go": ["golang", "go", "prefer go"],
"rust": ["rust", "prefer rust"]
}
NO_CODE_KEYWORDS = [
'what is', 'what are', 'document', 'curriculum', 'explain', 'describe',
'summarize', 'list', 'tell me about', 'report',
'definition of', 'meaning of', 'overview of'
]
CODE_KEYWORDS = [
'script', 'function', 'api', 'backend', 'frontend',
'algorithm', 'program', 'code', 'implement',
'build', 'create app', 'develop', 'software'
]
# ============================================================================
# RESEARCH MODE CONFIGURATION
# ============================================================================
RESEARCH_KEYWORDS = [
'research', 'analyze', 'study', 'investigate', 'explore',
'survey', 'review', 'compare', 'evaluate', 'assess',
'trends', 'best practices', 'state of', 'landscape',
'comprehensive', 'detailed analysis', 'in-depth'
]
REPORT_KEYWORDS = [
'report', 'summary', 'findings', 'document',
'write up', 'present', 'deliverable', 'brief', 'whitepaper'
]
REQUIRE_CITATIONS_FOR_RESEARCH = True
MIN_SOURCES_PER_RESEARCH = 5
MAX_SOURCES_PER_RESEARCH = 25
CITATION_FORMAT = "APA"
WEB_SEARCH_ENABLED = True
WEB_SEARCH_API = "brave"
WEB_SEARCH_MAX_RESULTS = 25
WEB_SEARCH_TIMEOUT = 30 # seconds
# ============================================================================
# ARTIFACT TYPE CONFIGURATION
# ============================================================================
KNOWN_ARTIFACT_TYPES = {
"notebook", "script", "repo", "word",
"excel", "pdf", "image", "data"
}
ARTIFACT_TYPE_KEYWORDS = {
'notebook': ['notebook', 'jupyter', 'ipynb', 'visualization', 'chart', 'graph'],
'script': ['script', 'function', 'utility', 'tool'],
'repo': ['app', 'backend', 'frontend', 'api', 'repository', 'project'],
'word': ['document', 'report', 'research', 'analysis', 'doc', 'docx'],
'excel': ['spreadsheet', 'excel', 'xlsx', 'csv', 'data table'],
'pdf': ['pdf', 'printable']
}
DEFAULT_CODE_ARTIFACT = "script"
DEFAULT_RESEARCH_ARTIFACT = "word"
# ============================================================================
# FILE & ARTIFACT MANAGEMENT
# ============================================================================
OUT_DIR = os.environ.get("OUT_DIR", "outputs")
OUTPUTS_DIR = "outputs"
USER_ARTIFACTS_DIR = "outputs/user_artifacts"
EXPORTS_DIR = os.path.join(OUT_DIR, "exports")
FEEDBACK_STORAGE_DIR = "outputs/feedback"
ARTIFACT_REGISTRY_FILE = "outputs/artifact_registry.json"
ENSURE_ALL_ARTIFACTS_EXPORTED = True
ARTIFACT_RETENTION_DAYS = 30
MAX_ARTIFACT_SIZE_MB = 100
UUID_LENGTH = 8
FILENAME_SEPARATOR = "_"
TIMESTAMP_FORMAT = "%Y%m%d_%H%M%S"
# ============================================================================
# CONVERSATION CONTEXT MANAGEMENT
# ============================================================================
MAX_CONVERSATION_HISTORY = 25
CONTEXT_TOKEN_LIMIT = 40000
INCLUDE_ARTIFACTS_IN_CONTEXT = True
AUTO_SUMMARIZE_LONG_CONVERSATIONS = True
SUMMARIZE_AFTER_EXCHANGES = 5
FOLLOW_UP_KEYWORDS = [
'also', 'additionally', 'now', 'then', 'next',
'can you', 'please', 'what about', 'how about',
'add', 'include', 'expand', 'modify', 'change',
'update', 'improve', 'enhance', 'refine'
]
REFERENCE_PRONOUNS = ['it', 'that', 'this', 'they', 'them', 'those', 'these']
SHOW_CONTEXT_INDICATOR = True
CONTEXT_INDICATOR_NEW = "📊 **New conversation**"
CONTEXT_INDICATOR_FOLLOW_UP = "🔄 Follow-up detected"
CONTEXT_INDICATOR_FORMAT = "💬 **Context: {count} exchange(s)**"
# ============================================================================
# EXECUTION MODES
# ============================================================================
EXECUTION_MODES = {
"research": {
"description": "Factual research with citations",
"needs_code": False,
"requires_citations": True,
"uses_web_search": True,
"output_formats": ["document", "response"]
},
"coding": {
"description": "Code generation and implementation",
"needs_code": True,
"requires_citations": False,
"uses_web_search": False,
"output_formats": ["script", "notebook", "repo"]
},
"hybrid": {
"description": "Research with code examples",
"needs_code": True,
"requires_citations": True,
"uses_web_search": True,
"output_formats": ["document", "notebook"]
},
"simple_response": {
"description": "Quick text response",
"needs_code": False,
"requires_citations": False,
"uses_web_search": False,
"output_formats": ["text"]
}
}
# ============================================================================
# NODE STATUS MESSAGES
# ============================================================================
NODE_STATUS = {
"memory": "Retrieving context...",
"intent": "Clarifying objective...",
"pm": "Planning execution...",
"pragmatist": "Assessing feasibility...",
"experimenter": "Generating artifacts...",
"research": "Conducting research...",
"synthesis": "Synthesizing response...",
"qa": "Reviewing quality...",
"observer": "Monitoring performance...",
"archive": "Saving to memory..."
}
COMPLETION_SUCCESS = "✅ Task completed successfully"
COMPLETION_WITH_WARNING = "⚠️ Task completed with limitations"
COMPLETION_FAILED = "❌ Task could not be completed"
# ============================================================================
# ERROR HANDLING
# ============================================================================
ERROR_NO_LLM = "LLM not available"
ERROR_TIMEOUT = "Operation timed out"
ERROR_BUDGET_EXCEEDED = "Budget limit exceeded"
ERROR_PARSE_FAILED = "Failed to parse LLM response"
ERROR_ARTIFACT_CREATION = "Failed to create artifact"
MAX_RETRIES = 3
RETRY_DELAY_SECONDS = 2
EXPONENTIAL_BACKOFF = True
# ============================================================================
# LOGGING CONFIGURATION
# ============================================================================
TIER_LOG_LEVELS = {
TIER_LITE: "WARNING",
TIER_STANDARD: "INFO",
TIER_FULL: "DEBUG"
}
LOG_SEPARATOR = "=" * 60
LOG_SEPARATOR_SHORT = "-" * 40
LOG_PERFORMANCE_METRICS = True
LOG_TOKEN_USAGE = True
LOG_COST_TRACKING = True
# ============================================================================
# HELPER FUNCTIONS
# ============================================================================
def get_tier_config(tier: str) -> Dict[str, Any]:
"""Get configuration for specified tier."""
return TIER_CONFIGS.get(tier, TIER_CONFIGS[DEFAULT_TIER])
def calculate_cost_per_call(tokens: int = None) -> float:
tokens = tokens or AVG_TOKENS_PER_CALL
avg_cost_per_1k = (GPT4O_INPUT_COST_PER_1K_TOKENS + GPT4O_OUTPUT_COST_PER_1K_TOKENS) / 2.0
return (tokens / 1000.0) * avg_cost_per_1k
def is_tier_unlimited(tier: str) -> bool:
config = get_tier_config(tier)
return config["max_cost"] is None
def get_max_rework_cycles(tier: str) -> int:
config = get_tier_config(tier)
return config["qa_rework_cycles"]
def should_include_monitoring(tier: str) -> bool:
config = get_tier_config(tier)
return config["includes_monitoring"]
def validate_tier(tier: str) -> str:
tier_lower = tier.lower() if tier else DEFAULT_TIER
if tier_lower not in TIER_CONFIGS:
return DEFAULT_TIER
return tier_lower
# ============================================================================
# LEGACY COMPATIBILITY CONSTANTS (to prevent AttributeError)
# ============================================================================
# Maintain backward compatibility with older modules (e.g., app_gradio.py)
INITIAL_MAX_REWORK_CYCLES = get_max_rework_cycles(DEFAULT_TIER)
# Explicitly re-export legacy cost multipliers for older modules
LEGACY_BUDGET_BUFFER_MULTIPLIER = BUDGET_BUFFER_MULTIPLIER
LEGACY_MAX_COST_MULTIPLIER = MAX_COST_MULTIPLIER
# ============================================================================
# EXPORTS
# ============================================================================
__all__ = [
'TIER_LITE', 'TIER_STANDARD', 'TIER_FULL', 'TIER_CONFIGS', 'DEFAULT_TIER',
'MAX_EXECUTION_PATH_LENGTH', 'NODE_TIMEOUT_SECONDS',
'DEFAULT_LANGUAGE', 'SUPPORTED_LANGUAGES', 'NO_CODE_KEYWORDS', 'CODE_KEYWORDS',
'RESEARCH_KEYWORDS', 'REQUIRE_CITATIONS_FOR_RESEARCH', 'WEB_SEARCH_ENABLED',
'KNOWN_ARTIFACT_TYPES', 'USER_ARTIFACTS_DIR', 'MAX_CONVERSATION_HISTORY',
'FOLLOW_UP_KEYWORDS', 'get_tier_config', 'calculate_cost_per_call',
'is_tier_unlimited', 'get_max_rework_cycles', 'should_include_monitoring',
'validate_tier', 'INITIAL_MAX_REWORK_CYCLES',
'LEGACY_BUDGET_BUFFER_MULTIPLIER', 'LEGACY_MAX_COST_MULTIPLIER'
]
|