quantnodes 3.0.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.
- QuantNodes/__init__.py +15 -0
- QuantNodes/__main__.py +14 -0
- QuantNodes/agent/__init__.py +158 -0
- QuantNodes/agent/agents/__init__.py +13 -0
- QuantNodes/agent/agents/definition.py +180 -0
- QuantNodes/agent/agents/manager.py +73 -0
- QuantNodes/agent/config/__init__.py +34 -0
- QuantNodes/agent/config/executor.py +958 -0
- QuantNodes/agent/config/loader.py +427 -0
- QuantNodes/agent/config/templates/bollinger_bands.yaml +84 -0
- QuantNodes/agent/config/templates/dual_ma.yaml +72 -0
- QuantNodes/agent/config/templates/empty.yaml +56 -0
- QuantNodes/agent/config/templates/mean_reversion.yaml +47 -0
- QuantNodes/agent/config/templates/mean_reversion_zscore.yaml +90 -0
- QuantNodes/agent/config/templates/momentum.yaml +81 -0
- QuantNodes/agent/config/templates/momentum_breakout.yaml +84 -0
- QuantNodes/agent/config/templates/rsi_strategy.yaml +72 -0
- QuantNodes/agent/config/templates/volume_price.yaml +86 -0
- QuantNodes/agent/config/types.py +156 -0
- QuantNodes/agent/config_mapper.py +293 -0
- QuantNodes/agent/core/__init__.py +19 -0
- QuantNodes/agent/core/dream.py +47 -0
- QuantNodes/agent/core/quant_dream.py +274 -0
- QuantNodes/agent/cron_jobs.py +314 -0
- QuantNodes/agent/nanobot_bridge.py +242 -0
- QuantNodes/agent/permission/__init__.py +30 -0
- QuantNodes/agent/permission/defaults.py +36 -0
- QuantNodes/agent/permission/evaluate.py +41 -0
- QuantNodes/agent/permission/models.py +59 -0
- QuantNodes/agent/permission/service.py +133 -0
- QuantNodes/agent/providers/__init__.py +11 -0
- QuantNodes/agent/providers/base.py +102 -0
- QuantNodes/agent/providers/quantnodes.py +610 -0
- QuantNodes/agent/providers/rate_limiter.py +326 -0
- QuantNodes/agent/providers/registry.py +163 -0
- QuantNodes/agent/skills/__init__.py +20 -0
- QuantNodes/agent/skills/base.py +118 -0
- QuantNodes/agent/skills/bridge.py +73 -0
- QuantNodes/agent/skills/factor/__init__.py +14 -0
- QuantNodes/agent/skills/factor/correlation.py +99 -0
- QuantNodes/agent/skills/factor/group_backtest.py +114 -0
- QuantNodes/agent/skills/factor/ic_analysis.py +106 -0
- QuantNodes/agent/skills/loader.py +107 -0
- QuantNodes/agent/skills/registry.py +105 -0
- QuantNodes/agent/skills/strategy/__init__.py +16 -0
- QuantNodes/agent/skills/strategy/bollinger.py +86 -0
- QuantNodes/agent/skills/strategy/dual_ma.py +82 -0
- QuantNodes/agent/skills/strategy/momentum.py +74 -0
- QuantNodes/agent/skills/strategy/rsi_reversal.py +99 -0
- QuantNodes/agent/skills_quant/__init__.py +14 -0
- QuantNodes/agent/skills_quant/backtest-analyze/SKILL.md +42 -0
- QuantNodes/agent/skills_quant/config-driven/SKILL.md +72 -0
- QuantNodes/agent/skills_quant/factor-research/SKILL.md +40 -0
- QuantNodes/agent/skills_quant/quant-dream/SKILL.md +55 -0
- QuantNodes/agent/skills_quant/risk-management/SKILL.md +45 -0
- QuantNodes/agent/skills_quant/strategy-design/SKILL.md +43 -0
- QuantNodes/agent/templates/__init__.py +4 -0
- QuantNodes/agent/tools/__init__.py +173 -0
- QuantNodes/agent/tools/_workspace.py +51 -0
- QuantNodes/agent/tools/alpha_backtest.py +328 -0
- QuantNodes/agent/tools/alpha_evaluate.py +493 -0
- QuantNodes/agent/tools/backtest.py +226 -0
- QuantNodes/agent/tools/base.py +133 -0
- QuantNodes/agent/tools/code_search.py +207 -0
- QuantNodes/agent/tools/config_backtest.py +401 -0
- QuantNodes/agent/tools/context.py +97 -0
- QuantNodes/agent/tools/dream_skill.py +77 -0
- QuantNodes/agent/tools/echo.py +38 -0
- QuantNodes/agent/tools/factor.py +231 -0
- QuantNodes/agent/tools/file_ops.py +201 -0
- QuantNodes/agent/tools/git_ops.py +190 -0
- QuantNodes/agent/tools/operator_lookup.py +218 -0
- QuantNodes/agent/tools/output_truncation.py +77 -0
- QuantNodes/agent/tools/path_check.py +43 -0
- QuantNodes/agent/tools/pipeline.py +62 -0
- QuantNodes/agent/tools/registry.py +150 -0
- QuantNodes/agent/tools/sandbox.py +62 -0
- QuantNodes/agent/tools/shell_safety.py +63 -0
- QuantNodes/agent/tools/strategy.py +106 -0
- QuantNodes/agent/tools/task.py +171 -0
- QuantNodes/agent/tools/web_fetch.py +142 -0
- QuantNodes/agent/tools/web_search.py +114 -0
- QuantNodes/agent/tools/wiki.py +370 -0
- QuantNodes/agent/utils/__init__.py +11 -0
- QuantNodes/agent/utils/helpers.py +43 -0
- QuantNodes/agent/utils/prompt_templates.py +30 -0
- QuantNodes/agent/workflows/__init__.py +20 -0
- QuantNodes/agent/workflows/implementations/__init__.py +8 -0
- QuantNodes/agent/workflows/implementations/alpha_gpt.py +508 -0
- QuantNodes/agent/workflows/implementations/mcts.py +442 -0
- QuantNodes/agent/workflows/parsers.py +44 -0
- QuantNodes/agent/workflows/registry.py +119 -0
- QuantNodes/agent/workflows/step_agent.py +219 -0
- QuantNodes/agent/workflows/tool.py +198 -0
- QuantNodes/ai/__init__.py +93 -0
- QuantNodes/ai/llm/__init__.py +75 -0
- QuantNodes/ai/llm/base.py +233 -0
- QuantNodes/ai/llm/decorators.py +281 -0
- QuantNodes/ai/llm/gateway.py +571 -0
- QuantNodes/ai/llm/null.py +76 -0
- QuantNodes/ai/llm/openai.py +435 -0
- QuantNodes/ai/optimizer.py +405 -0
- QuantNodes/ai/prompts/__init__.py +229 -0
- QuantNodes/ai/sandbox.py +371 -0
- QuantNodes/ai/sandbox_pandas_bridge.py +150 -0
- QuantNodes/ai/strategy_gen.py +396 -0
- QuantNodes/backtest/__init__.py +64 -0
- QuantNodes/backtest/backtest_node.py +188 -0
- QuantNodes/backtest/broker_node.py +378 -0
- QuantNodes/backtest/config_runner.py +397 -0
- QuantNodes/backtest/config_strategy.py +64 -0
- QuantNodes/backtest/risk_node.py +360 -0
- QuantNodes/backtest/strategy_node.py +268 -0
- QuantNodes/cache_node/__init__.py +19 -0
- QuantNodes/cache_node/base.py +244 -0
- QuantNodes/cache_node/cache_store.py +99 -0
- QuantNodes/cache_node/metadata.py +100 -0
- QuantNodes/cli/__init__.py +109 -0
- QuantNodes/cli/_helpers.py +511 -0
- QuantNodes/cli/command.py +110 -0
- QuantNodes/cli/commands/__init__.py +69 -0
- QuantNodes/cli/commands/agent.py +158 -0
- QuantNodes/cli/commands/alpha.py +951 -0
- QuantNodes/cli/commands/chat.py +38 -0
- QuantNodes/cli/commands/evolve.py +120 -0
- QuantNodes/cli/commands/factor.py +569 -0
- QuantNodes/cli/commands/init.py +190 -0
- QuantNodes/cli/commands/run.py +259 -0
- QuantNodes/cli/commands/serve.py +398 -0
- QuantNodes/cli/commands/version.py +120 -0
- QuantNodes/cli/enhanced.py +146 -0
- QuantNodes/conf_node/__init__.py +37 -0
- QuantNodes/conf_node/base.py +120 -0
- QuantNodes/conf_node/env_config.py +132 -0
- QuantNodes/conf_node/ini_config.py +70 -0
- QuantNodes/conf_node/json_config.py +69 -0
- QuantNodes/conf_node/yaml_config.py +78 -0
- QuantNodes/constants.py +17 -0
- QuantNodes/core/__init__.py +196 -0
- QuantNodes/core/_lookback_helpers.py +49 -0
- QuantNodes/core/ast_parser.py +198 -0
- QuantNodes/core/base.py +61 -0
- QuantNodes/core/cache_manager.py +344 -0
- QuantNodes/core/cache_utils.py +150 -0
- QuantNodes/core/cond_builder.py +53 -0
- QuantNodes/core/config.py +170 -0
- QuantNodes/core/constants.py +48 -0
- QuantNodes/core/control.py +412 -0
- QuantNodes/core/data_preprocessing.py +453 -0
- QuantNodes/core/data_source.py +46 -0
- QuantNodes/core/events.py +178 -0
- QuantNodes/core/evolution/__init__.py +22 -0
- QuantNodes/core/evolution/loop.py +583 -0
- QuantNodes/core/evolution/operators.py +289 -0
- QuantNodes/core/evolution/settings.py +44 -0
- QuantNodes/core/expression.py +841 -0
- QuantNodes/core/feedback/__init__.py +38 -0
- QuantNodes/core/feedback/channels.py +182 -0
- QuantNodes/core/feedback/collector.py +91 -0
- QuantNodes/core/feedback/dataclass.py +239 -0
- QuantNodes/core/feedback/llm_judge.py +138 -0
- QuantNodes/core/knowledge/__init__.py +69 -0
- QuantNodes/core/knowledge/knowledge_base.py +217 -0
- QuantNodes/core/knowledge/lineage_compress.py +196 -0
- QuantNodes/core/knowledge/lineage_expand.py +123 -0
- QuantNodes/core/knowledge/metrics/__init__.py +43 -0
- QuantNodes/core/knowledge/metrics/evaluator.py +176 -0
- QuantNodes/core/knowledge/metrics/metrics.py +220 -0
- QuantNodes/core/knowledge/rag_prompt.py +196 -0
- QuantNodes/core/knowledge/retriever.py +209 -0
- QuantNodes/core/lambda_node.py +81 -0
- QuantNodes/core/monitoring/__init__.py +22 -0
- QuantNodes/core/monitoring/collector.py +292 -0
- QuantNodes/core/monitoring/dashboard.py +365 -0
- QuantNodes/core/node.py +375 -0
- QuantNodes/core/pandas_utils.py +504 -0
- QuantNodes/core/parallel/__init__.py +15 -0
- QuantNodes/core/parallel/worker.py +140 -0
- QuantNodes/core/parallel/worker_process.py +265 -0
- QuantNodes/core/path_utils.py +73 -0
- QuantNodes/core/pipeline.py +328 -0
- QuantNodes/core/plugin.py +135 -0
- QuantNodes/core/quality_gate/__init__.py +32 -0
- QuantNodes/core/quality_gate/complexity.py +94 -0
- QuantNodes/core/quality_gate/consistency.py +26 -0
- QuantNodes/core/quality_gate/node.py +97 -0
- QuantNodes/core/quality_gate/redundancy.py +51 -0
- QuantNodes/core/quality_gate/settings.py +43 -0
- QuantNodes/core/quality_gate/zoo.py +98 -0
- QuantNodes/core/serializable.py +116 -0
- QuantNodes/core/serialization.py +673 -0
- QuantNodes/core/tools.py +333 -0
- QuantNodes/core/trajectory/__init__.py +25 -0
- QuantNodes/core/trajectory/entry.py +116 -0
- QuantNodes/core/trajectory/lineage.py +67 -0
- QuantNodes/core/trajectory/pool.py +211 -0
- QuantNodes/core/trajectory/selector.py +140 -0
- QuantNodes/core/visualization/__init__.py +33 -0
- QuantNodes/core/visualization/builder.py +233 -0
- QuantNodes/core/visualization/gate_breakdown.py +140 -0
- QuantNodes/core/visualization/lineage_dag.py +203 -0
- QuantNodes/core/visualization/metric_distribution.py +125 -0
- QuantNodes/core/visualization/report.py +68 -0
- QuantNodes/database_node/__init__.py +69 -0
- QuantNodes/database_node/base.py +135 -0
- QuantNodes/database_node/clickhouse_node.py +272 -0
- QuantNodes/database_node/csv_node.py +83 -0
- QuantNodes/database_node/duckdb_node.py +86 -0
- QuantNodes/database_node/factory.py +83 -0
- QuantNodes/database_node/mysql_node.py +100 -0
- QuantNodes/database_node/parquet_node.py +75 -0
- QuantNodes/database_node/sqlite_node.py +67 -0
- QuantNodes/factor_node/__init__.py +50 -0
- QuantNodes/factor_node/factor.py +563 -0
- QuantNodes/factor_node/factor_db.py +421 -0
- QuantNodes/factor_node/factor_functions/__init__.py +252 -0
- QuantNodes/factor_node/factor_functions/_helpers.py +358 -0
- QuantNodes/factor_node/factor_functions/_helpers_debug.py +317 -0
- QuantNodes/factor_node/factor_functions/composite_ops.py +136 -0
- QuantNodes/factor_node/factor_functions/math_ops.py +433 -0
- QuantNodes/factor_node/factor_functions/section_ops.py +290 -0
- QuantNodes/factor_node/factor_functions/talib_ops.py +1293 -0
- QuantNodes/factor_node/factor_functions/time_ops.py +535 -0
- QuantNodes/factor_node/factor_operation.py +1115 -0
- QuantNodes/factor_node/factor_table.py +1073 -0
- QuantNodes/factor_node/quant_nodes_object.py +60 -0
- QuantNodes/mcp_server/__init__.py +27 -0
- QuantNodes/mcp_server/__main__.py +4 -0
- QuantNodes/mcp_server/server.py +272 -0
- QuantNodes/methods/__init__.py +28 -0
- QuantNodes/methods/pipeline.py +100 -0
- QuantNodes/methods/sandbox.py +102 -0
- QuantNodes/monitor/__init__.py +27 -0
- QuantNodes/monitor/agent_tools/__init__.py +5 -0
- QuantNodes/monitor/agent_tools/monitor_tool.py +98 -0
- QuantNodes/monitor/agent_tools/schedule_tool.py +98 -0
- QuantNodes/monitor/agent_tools/version_tool.py +133 -0
- QuantNodes/monitor/monitor/__init__.py +6 -0
- QuantNodes/monitor/monitor/alerter.py +60 -0
- QuantNodes/monitor/monitor/collector.py +164 -0
- QuantNodes/monitor/monitor/dashboard.py +115 -0
- QuantNodes/monitor/monitor/drift.py +190 -0
- QuantNodes/monitor/scheduler/__init__.py +4 -0
- QuantNodes/monitor/scheduler/runner.py +133 -0
- QuantNodes/monitor/scheduler/scheduler.py +184 -0
- QuantNodes/monitor/storage/__init__.py +16 -0
- QuantNodes/monitor/storage/models.py +70 -0
- QuantNodes/monitor/storage/repository.py +407 -0
- QuantNodes/monitor/version/__init__.py +4 -0
- QuantNodes/monitor/version/diff.py +81 -0
- QuantNodes/monitor/version/version_manager.py +182 -0
- QuantNodes/operator_node/__init__.py +28 -0
- QuantNodes/operator_node/base.py +97 -0
- QuantNodes/operator_node/query_node.py +129 -0
- QuantNodes/operator_node/sql_builder.py +125 -0
- QuantNodes/operator_node/sql_utils.py +172 -0
- QuantNodes/operator_node/transform.py +130 -0
- QuantNodes/operators/__init__.py +90 -0
- QuantNodes/operators/_engine.py +108 -0
- QuantNodes/operators/composite.py +161 -0
- QuantNodes/operators/composite_dag.py +667 -0
- QuantNodes/operators/composite_dag_ops.py +343 -0
- QuantNodes/operators/composite_dag_pandas_ops.py +382 -0
- QuantNodes/operators/custom.py +408 -0
- QuantNodes/operators/facade.py +164 -0
- QuantNodes/operators/math.py +163 -0
- QuantNodes/operators/proxy.py +29 -0
- QuantNodes/operators/registry.py +144 -0
- QuantNodes/operators/section.py +99 -0
- QuantNodes/operators/talib.py +757 -0
- QuantNodes/operators/templates.py +95 -0
- QuantNodes/operators/time_series.py +136 -0
- QuantNodes/prompts/__init__.py +20 -0
- QuantNodes/prompts/backtest/__init__.py +12 -0
- QuantNodes/prompts/backtest/factor_based.py +86 -0
- QuantNodes/prompts/backtest/standard.py +73 -0
- QuantNodes/prompts/factor/__init__.py +14 -0
- QuantNodes/prompts/factor/correlation.py +77 -0
- QuantNodes/prompts/factor/group_backtest.py +86 -0
- QuantNodes/prompts/factor/ic_analysis.py +91 -0
- QuantNodes/prompts/strategy/__init__.py +18 -0
- QuantNodes/prompts/strategy/market_neutral.py +96 -0
- QuantNodes/prompts/strategy/mean_reversion.py +107 -0
- QuantNodes/prompts/strategy/momentum.py +160 -0
- QuantNodes/prompts/strategy/pairs_trading.py +107 -0
- QuantNodes/prompts/strategy/trend_following.py +96 -0
- QuantNodes/research/README.md +106 -0
- QuantNodes/research/__init__.py +154 -0
- QuantNodes/research/_legacy_3c/__init__.py +61 -0
- QuantNodes/research/_legacy_3c/auto_researcher.py +289 -0
- QuantNodes/research/_legacy_3c/factor_evaluator.py +560 -0
- QuantNodes/research/_legacy_3c/factor_miner.py +318 -0
- QuantNodes/research/_legacy_3c/mcts_search.py +324 -0
- QuantNodes/research/factor_test/__init__.py +25 -0
- QuantNodes/research/factor_test/config.py +184 -0
- QuantNodes/research/factor_test/config_builder.py +276 -0
- QuantNodes/research/factor_test/e2e/data_prep.py +163 -0
- QuantNodes/research/factor_test/e2e/run_evolution_e2e.py +309 -0
- QuantNodes/research/factor_test/evolution_adapter.py +231 -0
- QuantNodes/research/factor_test/feedback_wrapper.py +102 -0
- QuantNodes/research/factor_test/ifind_db/__init__.py +7 -0
- QuantNodes/research/factor_test/ifind_db/fetcher.py +224 -0
- QuantNodes/research/factor_test/ifind_db/ifind_database.py +689 -0
- QuantNodes/research/factor_test/nodes/__init__.py +1 -0
- QuantNodes/research/factor_test/nodes/_base.py +91 -0
- QuantNodes/research/factor_test/nodes/adjust_date_node.py +48 -0
- QuantNodes/research/factor_test/nodes/configs.py +240 -0
- QuantNodes/research/factor_test/nodes/factor_neutralize_node.py +87 -0
- QuantNodes/research/factor_test/nodes/factor_preprocess_node.py +222 -0
- QuantNodes/research/factor_test/nodes/factor_score_node.py +141 -0
- QuantNodes/research/factor_test/nodes/factor_test_report_node.py +153 -0
- QuantNodes/research/factor_test/nodes/group_analyzer_node.py +317 -0
- QuantNodes/research/factor_test/nodes/ic_analyzer_node.py +112 -0
- QuantNodes/research/factor_test/nodes/load_data_node.py +100 -0
- QuantNodes/research/factor_test/nodes/long_short_node.py +93 -0
- QuantNodes/research/factor_test/nodes/neutralizers.py +222 -0
- QuantNodes/research/factor_test/nodes/preprocess_strategies.py +277 -0
- QuantNodes/research/factor_test/nodes/risk_correlation_node.py +112 -0
- QuantNodes/research/factor_test/nodes/sample_pool_filter_node.py +110 -0
- QuantNodes/research/factor_test/nodes/tradability_filter_node.py +92 -0
- QuantNodes/research/factor_test/pipeline_runner.py +305 -0
- QuantNodes/research/factor_test/pipeline_spec.py +216 -0
- QuantNodes/research/factor_test/utils/__init__.py +26 -0
- QuantNodes/research/factor_test/utils/constants.py +86 -0
- QuantNodes/research/factor_test/utils/data_loader.py +141 -0
- QuantNodes/research/factor_test/utils/date_utils.py +232 -0
- QuantNodes/research/factor_test/utils/file_loaders.py +150 -0
- QuantNodes/research/factor_test/utils/labels.py +37 -0
- QuantNodes/research/factor_test/utils/metrics_extractor.py +55 -0
- QuantNodes/research/factor_test/utils/performance_metrics.py +175 -0
- QuantNodes/research/factor_test/utils/safe_load.py +106 -0
- QuantNodes/research/quant_alpha/CHANGELOG.md +80 -0
- QuantNodes/research/quant_alpha/README.md +142 -0
- QuantNodes/research/quant_alpha/__init__.py +45 -0
- QuantNodes/research/quant_alpha/adapters/__init__.py +99 -0
- QuantNodes/research/quant_alpha/adapters/calculator.py +503 -0
- QuantNodes/research/quant_alpha/adapters/expression.py +387 -0
- QuantNodes/research/quant_alpha/alpha101_design/__init__.py +50 -0
- QuantNodes/research/quant_alpha/alpha101_design/few_shot_examples.py +243 -0
- QuantNodes/research/quant_alpha/alpha101_design/philosophy.py +474 -0
- QuantNodes/research/quant_alpha/alpha158_design/__init__.py +63 -0
- QuantNodes/research/quant_alpha/alpha158_design/few_shot_examples.py +219 -0
- QuantNodes/research/quant_alpha/alpha158_design/philosophy.py +240 -0
- QuantNodes/research/quant_alpha/evaluation/__init__.py +47 -0
- QuantNodes/research/quant_alpha/evaluation/baselines/__init__.py +8 -0
- QuantNodes/research/quant_alpha/evaluation/baselines/g1_handcrafted.py +135 -0
- QuantNodes/research/quant_alpha/evaluation/baselines/g2_llm_only.py +269 -0
- QuantNodes/research/quant_alpha/evaluation/baselines/g3_alpha_gpt.py +152 -0
- QuantNodes/research/quant_alpha/evaluation/clickhouse_data_loader.py +227 -0
- QuantNodes/research/quant_alpha/evaluation/contracts.py +376 -0
- QuantNodes/research/quant_alpha/evaluation/evaluators/__init__.py +6 -0
- QuantNodes/research/quant_alpha/evaluation/evaluators/polars_evaluator.py +545 -0
- QuantNodes/research/quant_alpha/evaluation/mock_data_loader.py +226 -0
- QuantNodes/research/quant_alpha/evaluation/runner.py +243 -0
- QuantNodes/research/quant_alpha/llm/__init__.py +38 -0
- QuantNodes/research/quant_alpha/llm/parser.py +681 -0
- QuantNodes/research/quant_alpha/logic_driven_pipeline.py +411 -0
- QuantNodes/research/quant_alpha/logic_mining/__init__.py +74 -0
- QuantNodes/research/quant_alpha/logic_mining/compiler.py +457 -0
- QuantNodes/research/quant_alpha/logic_mining/generator.py +366 -0
- QuantNodes/research/quant_alpha/logic_mining/models.py +252 -0
- QuantNodes/research/quant_alpha/logic_mining/parser.py +287 -0
- QuantNodes/research/quant_alpha/logic_mining/pipelines.py +297 -0
- QuantNodes/research/quant_alpha/logic_mining/sources.py +149 -0
- QuantNodes/research/quant_alpha/mcts/__init__.py +66 -0
- QuantNodes/research/quant_alpha/mcts/cache.py +262 -0
- QuantNodes/research/quant_alpha/mcts/extension_ops.py +320 -0
- QuantNodes/research/quant_alpha/mcts/feedback.py +825 -0
- QuantNodes/research/quant_alpha/mcts/op_prior.py +180 -0
- QuantNodes/research/quant_alpha/mcts/search.py +540 -0
- QuantNodes/research/quant_alpha/mcts/tree.py +201 -0
- QuantNodes/research/quant_alpha/operator_vocab/__init__.py +50 -0
- QuantNodes/research/quant_alpha/operator_vocab/config.py +54 -0
- QuantNodes/research/quant_alpha/operator_vocab/metadata.py +263 -0
- QuantNodes/research/quant_alpha/operator_vocab/vocabulary.py +481 -0
- QuantNodes/research/quant_alpha/pipeline.py +1027 -0
- QuantNodes/research/quant_alpha/types/__init__.py +27 -0
- QuantNodes/research/quant_alpha/types/constants.py +28 -0
- QuantNodes/research/quant_alpha/types/state.py +205 -0
- QuantNodes/research/quant_alpha/workflow/__init__.py +32 -0
- QuantNodes/research/quant_alpha/workflow/alpha_gpt.py +911 -0
- QuantNodes/research/quant_alpha/workflow/alpha_logics.py +416 -0
- QuantNodes/research/quant_alpha/workflow/state.py +27 -0
- QuantNodes/research/report_reproducer.py +485 -0
- QuantNodes/research/wiki.py +1155 -0
- QuantNodes/symbolic/__init__.py +51 -0
- QuantNodes/symbolic/compiler.py +113 -0
- QuantNodes/symbolic/dialect.py +260 -0
- QuantNodes/symbolic/executor.py +147 -0
- QuantNodes/symbolic/expression.py +234 -0
- QuantNodes/symbolic/functions.py +433 -0
- QuantNodes/symbolic/optimizer.py +165 -0
- QuantNodes/ui_node/__init__.py +30 -0
- QuantNodes/ui_node/base.py +222 -0
- quantnodes-3.0.0.dist-info/METADATA +463 -0
- quantnodes-3.0.0.dist-info/RECORD +399 -0
- quantnodes-3.0.0.dist-info/WHEEL +5 -0
- quantnodes-3.0.0.dist-info/entry_points.txt +24 -0
- quantnodes-3.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""AlphaGptWorkflow — 用 StepAgent 框架重写。
|
|
3
|
+
|
|
4
|
+
5 个 StepAgentSpec + 注册到 WorkflowRegistry。
|
|
5
|
+
复用原有 state.py 的 dataclass 和 parser.py 的验证器。
|
|
6
|
+
不修改原 research/quant_alpha/workflow/alpha_gpt.py。
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import logging
|
|
12
|
+
from typing import Any, Dict, List, Optional
|
|
13
|
+
|
|
14
|
+
import numpy as np
|
|
15
|
+
|
|
16
|
+
from ..step_agent import StepAgentSpec, _run_async
|
|
17
|
+
from ..parsers import (
|
|
18
|
+
parse_json_3layer,
|
|
19
|
+
validate_idea_generator,
|
|
20
|
+
validate_formula_translator,
|
|
21
|
+
validate_reflector,
|
|
22
|
+
validate_critic,
|
|
23
|
+
validate_formula_operators,
|
|
24
|
+
ALLOWED_OPERATORS,
|
|
25
|
+
)
|
|
26
|
+
from ..registry import WorkflowSpec, REGISTRY
|
|
27
|
+
|
|
28
|
+
from QuantNodes.research.quant_alpha.types import (
|
|
29
|
+
AlphaGptState,
|
|
30
|
+
IdeaRecord,
|
|
31
|
+
FormulaRecord,
|
|
32
|
+
EvaluationRecord,
|
|
33
|
+
ReflectionRecord,
|
|
34
|
+
FinalFormulaRecord,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
logger = logging.getLogger(__name__)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# ==============================================================================
|
|
41
|
+
# Prompt builders(支持 _prev_error / _prev_raw 重试注入)
|
|
42
|
+
# ==============================================================================
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _build_idea_prompt(
|
|
46
|
+
state: Any = None,
|
|
47
|
+
round_idx: int = 1,
|
|
48
|
+
pool_size: int = 10,
|
|
49
|
+
a_share_focus: bool = True,
|
|
50
|
+
objective: str = "",
|
|
51
|
+
_prev_error: Optional[str] = None,
|
|
52
|
+
_prev_raw: Optional[str] = None,
|
|
53
|
+
**kwargs: Any,
|
|
54
|
+
) -> str:
|
|
55
|
+
prev_reflection = None
|
|
56
|
+
if state and state.all_reflections:
|
|
57
|
+
prev_reflection = state.all_reflections[-1].to_dict()
|
|
58
|
+
|
|
59
|
+
prompt = (
|
|
60
|
+
f"Read .agent/agents/alpha-gpt-idea-generator.md. "
|
|
61
|
+
f"Generate {pool_size} alpha ideas for objective={objective!r}. "
|
|
62
|
+
f"round={round_idx}, a_share_focus={a_share_focus}. "
|
|
63
|
+
f"previous_reflection={prev_reflection}. "
|
|
64
|
+
f"Output STRICT JSON only."
|
|
65
|
+
)
|
|
66
|
+
if _prev_error:
|
|
67
|
+
prompt += (
|
|
68
|
+
f"\n\n[SYSTEM: Your previous response was not valid JSON. "
|
|
69
|
+
f"Error: {_prev_error}\n"
|
|
70
|
+
f"Your full previous response:\n{_prev_raw}\n"
|
|
71
|
+
f"Please output ONLY a JSON object with no additional text.]"
|
|
72
|
+
)
|
|
73
|
+
return prompt
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _build_formula_prompt(
|
|
77
|
+
prev_output: Optional[list] = None,
|
|
78
|
+
round_idx: int = 1,
|
|
79
|
+
a_share_focus: bool = True,
|
|
80
|
+
available_operators: Optional[List[str]] = None,
|
|
81
|
+
data_columns: Optional[List[str]] = None,
|
|
82
|
+
_prev_error: Optional[str] = None,
|
|
83
|
+
_prev_raw: Optional[str] = None,
|
|
84
|
+
**kwargs: Any,
|
|
85
|
+
) -> str:
|
|
86
|
+
ideas_payload = [i.to_dict() for i in prev_output] if prev_output else []
|
|
87
|
+
ops = available_operators or sorted(ALLOWED_OPERATORS)
|
|
88
|
+
columns = data_columns or ["close", "open", "high", "low", "vol", "vwap"]
|
|
89
|
+
|
|
90
|
+
prompt = (
|
|
91
|
+
f"Read .agent/agents/alpha-gpt-formula-translator.md. "
|
|
92
|
+
f"Translate these ideas to polars formulas. round={round_idx}. "
|
|
93
|
+
f"ideas={ideas_payload}. available_operators={ops}. "
|
|
94
|
+
f"data_columns={columns}. a_share_focus={a_share_focus}. "
|
|
95
|
+
f"Output STRICT JSON only."
|
|
96
|
+
)
|
|
97
|
+
if _prev_error:
|
|
98
|
+
prompt += (
|
|
99
|
+
f"\n\n[SYSTEM: Your previous response was not valid JSON. "
|
|
100
|
+
f"Error: {_prev_error}\n"
|
|
101
|
+
f"Your full previous response:\n{_prev_raw}\n"
|
|
102
|
+
f"Please output ONLY a JSON object with no additional text.]"
|
|
103
|
+
)
|
|
104
|
+
return prompt
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _build_reflector_prompt(
|
|
108
|
+
prev_output: Optional[list] = None,
|
|
109
|
+
round_idx: int = 1,
|
|
110
|
+
_prev_error: Optional[str] = None,
|
|
111
|
+
_prev_raw: Optional[str] = None,
|
|
112
|
+
**kwargs: Any,
|
|
113
|
+
) -> str:
|
|
114
|
+
evaluations = [e.to_dict() for e in prev_output] if prev_output else []
|
|
115
|
+
|
|
116
|
+
prompt = (
|
|
117
|
+
f"Read .agent/agents/alpha-gpt-reflector.md. "
|
|
118
|
+
f"Reflect on round {round_idx} evaluations. "
|
|
119
|
+
f"evaluations={evaluations}. "
|
|
120
|
+
f"Output STRICT JSON only."
|
|
121
|
+
)
|
|
122
|
+
if _prev_error:
|
|
123
|
+
prompt += (
|
|
124
|
+
f"\n\n[SYSTEM: Your previous response was not valid JSON. "
|
|
125
|
+
f"Error: {_prev_error}\n"
|
|
126
|
+
f"Your full previous response:\n{_prev_raw}\n"
|
|
127
|
+
f"Please output ONLY a JSON object with no additional text.]"
|
|
128
|
+
)
|
|
129
|
+
return prompt
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _build_critic_prompt(
|
|
133
|
+
state: Any = None,
|
|
134
|
+
top_k: int = 10,
|
|
135
|
+
min_ir_threshold: float = 0.5,
|
|
136
|
+
max_mutual_ic_threshold: float = 0.7,
|
|
137
|
+
_prev_error: Optional[str] = None,
|
|
138
|
+
_prev_raw: Optional[str] = None,
|
|
139
|
+
**kwargs: Any,
|
|
140
|
+
) -> str:
|
|
141
|
+
all_evaluations = [e.to_dict() for e in (state.all_evaluations if state else [])]
|
|
142
|
+
all_reflections = [r.to_dict() for r in (state.all_reflections if state else [])]
|
|
143
|
+
|
|
144
|
+
prompt = (
|
|
145
|
+
f"Read .agent/agents/alpha-gpt-critic.md. "
|
|
146
|
+
f"Select final top-{top_k} from all rounds. "
|
|
147
|
+
f"min_ir_threshold={min_ir_threshold}. "
|
|
148
|
+
f"max_mutual_ic_threshold={max_mutual_ic_threshold}. "
|
|
149
|
+
f"all_evaluations={all_evaluations}. all_reflections={all_reflections}. "
|
|
150
|
+
f"Output STRICT JSON only."
|
|
151
|
+
)
|
|
152
|
+
if _prev_error:
|
|
153
|
+
prompt += (
|
|
154
|
+
f"\n\n[SYSTEM: Your previous response was not valid JSON. "
|
|
155
|
+
f"Error: {_prev_error}\n"
|
|
156
|
+
f"Your full previous response:\n{_prev_raw}\n"
|
|
157
|
+
f"Please output ONLY a JSON object with no additional text.]"
|
|
158
|
+
)
|
|
159
|
+
return prompt
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
# ==============================================================================
|
|
163
|
+
# Record factories
|
|
164
|
+
# ==============================================================================
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _idea_factory(d: dict, round_idx: int = 1, **kwargs: Any) -> IdeaRecord:
|
|
168
|
+
return IdeaRecord.from_dict(d, round_idx)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _formula_factory(
|
|
172
|
+
d: dict,
|
|
173
|
+
round_idx: int = 1,
|
|
174
|
+
formula_counter: Optional[list] = None,
|
|
175
|
+
**kwargs: Any,
|
|
176
|
+
) -> Optional[FormulaRecord]:
|
|
177
|
+
formula_str = d.get("formula", "")
|
|
178
|
+
err = validate_formula_operators(formula_str)
|
|
179
|
+
if err:
|
|
180
|
+
logger.debug("formula op-validation failed: %s (%s)", formula_str, err)
|
|
181
|
+
return None
|
|
182
|
+
|
|
183
|
+
if formula_counter is not None:
|
|
184
|
+
idx = formula_counter[0]
|
|
185
|
+
formula_counter[0] += 1
|
|
186
|
+
else:
|
|
187
|
+
idx = 1
|
|
188
|
+
|
|
189
|
+
return FormulaRecord(
|
|
190
|
+
formula_id=f"FORMULA-{round_idx}-{idx}",
|
|
191
|
+
idea_id=d.get("idea_id", ""),
|
|
192
|
+
formula=formula_str,
|
|
193
|
+
round_discovered=round_idx,
|
|
194
|
+
complexity=d.get("complexity", 0),
|
|
195
|
+
a_share_compatible=d.get("a_share_compatible", True),
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _evaluation_factory(
|
|
200
|
+
d: dict,
|
|
201
|
+
prev_output: Optional[list] = None,
|
|
202
|
+
**kwargs: Any,
|
|
203
|
+
) -> EvaluationRecord:
|
|
204
|
+
formula_idx = d.get("formula_id", "")
|
|
205
|
+
formula_str = d.get("formula", "")
|
|
206
|
+
|
|
207
|
+
if d.get("status") == "success":
|
|
208
|
+
metrics = d.get("metrics", {})
|
|
209
|
+
return EvaluationRecord(
|
|
210
|
+
formula_id=formula_idx,
|
|
211
|
+
formula=formula_str,
|
|
212
|
+
status="success",
|
|
213
|
+
ic_mean=metrics.get("ic_mean", 0.0),
|
|
214
|
+
ic_std=metrics.get("ic_std", 0.0),
|
|
215
|
+
ir=metrics.get("ir", 0.0),
|
|
216
|
+
ic_decay=metrics.get("ic_decay", {}),
|
|
217
|
+
)
|
|
218
|
+
return EvaluationRecord(
|
|
219
|
+
formula_id=formula_idx,
|
|
220
|
+
formula=formula_str,
|
|
221
|
+
status=d.get("status", "failed"),
|
|
222
|
+
error_msg=d.get("error_msg"),
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _reflection_factory(d: dict, round_idx: int = 1, **kwargs: Any) -> ReflectionRecord:
|
|
227
|
+
return ReflectionRecord(
|
|
228
|
+
round_idx=round_idx,
|
|
229
|
+
verdicts=d.get("formula_feedback", []),
|
|
230
|
+
suggestions=d.get("next_round_suggestions", {}),
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def _critic_factory(d: dict, **kwargs: Any) -> dict:
|
|
235
|
+
"""Critic 输出是 dict (不是 list),直接返回。"""
|
|
236
|
+
return d
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
# ==============================================================================
|
|
240
|
+
# Evaluator tool_executor
|
|
241
|
+
# ==============================================================================
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def _run_evaluator(
|
|
245
|
+
prev_output: Optional[list] = None,
|
|
246
|
+
data: Any = None,
|
|
247
|
+
data_path: Optional[str] = None,
|
|
248
|
+
forward_returns: Optional[list] = None,
|
|
249
|
+
date_column: str = "date",
|
|
250
|
+
code_column: str = "code",
|
|
251
|
+
**kwargs: Any,
|
|
252
|
+
) -> List[EvaluationRecord]:
|
|
253
|
+
"""直接调用 AlphaEvaluateTool,跳过 LLM。"""
|
|
254
|
+
formulas = prev_output or []
|
|
255
|
+
if not formulas:
|
|
256
|
+
return []
|
|
257
|
+
|
|
258
|
+
try:
|
|
259
|
+
from QuantNodes.agent.tools.alpha_evaluate import AlphaEvaluateTool
|
|
260
|
+
|
|
261
|
+
tool = AlphaEvaluateTool()
|
|
262
|
+
formulas_str = [f.formula for f in formulas]
|
|
263
|
+
result = _run_async(
|
|
264
|
+
tool.execute(
|
|
265
|
+
formulas=formulas_str,
|
|
266
|
+
data=data,
|
|
267
|
+
data_path=data_path,
|
|
268
|
+
forward_returns=list(forward_returns or (1, 5, 20)),
|
|
269
|
+
date_column=date_column,
|
|
270
|
+
code_column=code_column,
|
|
271
|
+
)
|
|
272
|
+
)
|
|
273
|
+
except Exception as exc:
|
|
274
|
+
logger.exception("alpha_evaluate tool failed: %s", exc)
|
|
275
|
+
return []
|
|
276
|
+
|
|
277
|
+
evals_data = result.get("evaluations", [])
|
|
278
|
+
out: List[EvaluationRecord] = []
|
|
279
|
+
for fd, ed in zip(formulas, evals_data):
|
|
280
|
+
if ed.get("status") == "success":
|
|
281
|
+
metrics = ed.get("metrics", {})
|
|
282
|
+
out.append(
|
|
283
|
+
EvaluationRecord(
|
|
284
|
+
formula_id=fd.formula_id,
|
|
285
|
+
formula=fd.formula,
|
|
286
|
+
status="success",
|
|
287
|
+
ic_mean=metrics.get("ic_mean", 0.0),
|
|
288
|
+
ic_std=metrics.get("ic_std", 0.0),
|
|
289
|
+
ir=metrics.get("ir", 0.0),
|
|
290
|
+
ic_decay=metrics.get("ic_decay", {}),
|
|
291
|
+
)
|
|
292
|
+
)
|
|
293
|
+
else:
|
|
294
|
+
out.append(
|
|
295
|
+
EvaluationRecord(
|
|
296
|
+
formula_id=fd.formula_id,
|
|
297
|
+
formula=fd.formula,
|
|
298
|
+
status=ed.get("status", "failed"),
|
|
299
|
+
error_msg=ed.get("error_msg"),
|
|
300
|
+
)
|
|
301
|
+
)
|
|
302
|
+
return out
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
# ==============================================================================
|
|
306
|
+
# Result builder
|
|
307
|
+
# ==============================================================================
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def _build_result(state: AlphaGptState, config: dict) -> dict:
|
|
311
|
+
"""构建最终结果 dict。"""
|
|
312
|
+
top_k = config.get("top_k", 10)
|
|
313
|
+
|
|
314
|
+
# 从 critic_output 或 fallback 选 top-K
|
|
315
|
+
critic_pool = (state.critic_output or {}).get("final_pool") or []
|
|
316
|
+
if critic_pool:
|
|
317
|
+
pool_data = critic_pool[:top_k]
|
|
318
|
+
final_pool = [FinalFormulaRecord.from_dict(p, i + 1) for i, p in enumerate(pool_data)]
|
|
319
|
+
else:
|
|
320
|
+
# Fallback: 按 IR 排序
|
|
321
|
+
successful = [e for e in state.all_evaluations if e.status == "success"]
|
|
322
|
+
successful.sort(key=lambda e: e.ir, reverse=True)
|
|
323
|
+
top = successful[:top_k]
|
|
324
|
+
final_pool = [
|
|
325
|
+
FinalFormulaRecord(
|
|
326
|
+
rank=i + 1,
|
|
327
|
+
formula_id=e.formula_id,
|
|
328
|
+
formula=e.formula,
|
|
329
|
+
ic_mean=e.ic_mean,
|
|
330
|
+
ir=e.ir,
|
|
331
|
+
round_discovered=int(e.formula_id.split("-")[1]) if "-" in e.formula_id else 0,
|
|
332
|
+
selection_reason=f"IR={e.ir:.3f} (auto-selected by fallback)",
|
|
333
|
+
risk_notes=[],
|
|
334
|
+
)
|
|
335
|
+
for i, e in enumerate(top)
|
|
336
|
+
]
|
|
337
|
+
|
|
338
|
+
# Summary
|
|
339
|
+
successful = [e for e in state.all_evaluations if e.status == "success"]
|
|
340
|
+
irs = [e.ir for e in successful]
|
|
341
|
+
cat_dist: Dict[str, int] = {}
|
|
342
|
+
for f in final_pool:
|
|
343
|
+
cat = f.category or "unknown"
|
|
344
|
+
cat_dist[cat] = cat_dist.get(cat, 0) + 1
|
|
345
|
+
|
|
346
|
+
summary = {
|
|
347
|
+
"total_evaluated": len(state.all_evaluations),
|
|
348
|
+
"successful": len(successful),
|
|
349
|
+
"failed": len(state.all_evaluations) - len(successful),
|
|
350
|
+
"selected": len(final_pool),
|
|
351
|
+
"avg_ir": float(np.mean(irs)) if irs else 0.0,
|
|
352
|
+
"best_ir": float(np.max(irs)) if irs else 0.0,
|
|
353
|
+
"category_distribution": cat_dist,
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return {
|
|
357
|
+
"objective": state.objective,
|
|
358
|
+
"iterations_completed": state.iterations_total,
|
|
359
|
+
"total_formulas": len(state.all_formulas),
|
|
360
|
+
"final_pool": [f.to_dict() for f in final_pool],
|
|
361
|
+
"summary": summary,
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
# ==============================================================================
|
|
366
|
+
# Mock LLM
|
|
367
|
+
# ==============================================================================
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def _mock_response(
|
|
371
|
+
agent_id: str,
|
|
372
|
+
prompt: str,
|
|
373
|
+
state: Any = None,
|
|
374
|
+
config: Any = None,
|
|
375
|
+
) -> str:
|
|
376
|
+
"""Mock LLM 返回,让 workflow 无 API key 也能端到端跑通。"""
|
|
377
|
+
import json
|
|
378
|
+
|
|
379
|
+
pool_size = config.get("pool_size", 10) if isinstance(config, dict) else 10
|
|
380
|
+
round_idx = getattr(state, "round_idx_hint", 1) if state else 1
|
|
381
|
+
|
|
382
|
+
if "idea-generator" in agent_id:
|
|
383
|
+
categories = ["reversal", "momentum", "volatility", "value", "quality", "liquidity"]
|
|
384
|
+
ideas = [
|
|
385
|
+
{
|
|
386
|
+
"id": f"IDEA-{round_idx}-{i+1}",
|
|
387
|
+
"name": f"mock-idea-{i+1}",
|
|
388
|
+
"category": categories[i % len(categories)],
|
|
389
|
+
"description": f"Mock idea {i+1}",
|
|
390
|
+
"expected_direction": "long",
|
|
391
|
+
"suggested_lookback": 20,
|
|
392
|
+
"a_share_compatible": True,
|
|
393
|
+
"orthogonal_to": [],
|
|
394
|
+
"complexity_hint": "simple",
|
|
395
|
+
}
|
|
396
|
+
for i in range(pool_size)
|
|
397
|
+
]
|
|
398
|
+
return json.dumps({"round": round_idx, "ideas": ideas}, ensure_ascii=False)
|
|
399
|
+
|
|
400
|
+
if "formula-translator" in agent_id:
|
|
401
|
+
formulas = [
|
|
402
|
+
{
|
|
403
|
+
"id": f"FORMULA-{round_idx}-{i+1}",
|
|
404
|
+
"idea_id": f"IDEA-{round_idx}-{i+1}",
|
|
405
|
+
"formula": "sub(close, ts_mean(close, 10))",
|
|
406
|
+
"complexity": 3,
|
|
407
|
+
"a_share_compatible": True,
|
|
408
|
+
"explanation": "Mock formula",
|
|
409
|
+
}
|
|
410
|
+
for i in range(pool_size)
|
|
411
|
+
]
|
|
412
|
+
return json.dumps({"round": round_idx, "formulas": formulas}, ensure_ascii=False)
|
|
413
|
+
|
|
414
|
+
if "reflector" in agent_id:
|
|
415
|
+
return json.dumps({
|
|
416
|
+
"round": round_idx,
|
|
417
|
+
"formula_feedback": [],
|
|
418
|
+
"next_round_suggestions": {},
|
|
419
|
+
}, ensure_ascii=False)
|
|
420
|
+
|
|
421
|
+
if "critic" in agent_id:
|
|
422
|
+
return json.dumps({"final_pool": []}, ensure_ascii=False)
|
|
423
|
+
|
|
424
|
+
return json.dumps({})
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
# ==============================================================================
|
|
428
|
+
# StepAgentSpec 定义
|
|
429
|
+
# ==============================================================================
|
|
430
|
+
|
|
431
|
+
IDEA_GEN_SPEC = StepAgentSpec(
|
|
432
|
+
agent_id="alpha-gpt-idea-generator",
|
|
433
|
+
prompt_builder=_build_idea_prompt,
|
|
434
|
+
output_parser=lambda raw: parse_json_3layer(raw, validate_idea_generator),
|
|
435
|
+
output_key="ideas",
|
|
436
|
+
state_output="all_ideas",
|
|
437
|
+
record_factory=_idea_factory,
|
|
438
|
+
)
|
|
439
|
+
|
|
440
|
+
FORMULA_TRANS_SPEC = StepAgentSpec(
|
|
441
|
+
agent_id="alpha-gpt-formula-translator",
|
|
442
|
+
prompt_builder=_build_formula_prompt,
|
|
443
|
+
output_parser=lambda raw: parse_json_3layer(raw, validate_formula_translator),
|
|
444
|
+
output_key="formulas",
|
|
445
|
+
state_output="all_formulas",
|
|
446
|
+
record_factory=_formula_factory,
|
|
447
|
+
)
|
|
448
|
+
|
|
449
|
+
EVALUATOR_SPEC = StepAgentSpec(
|
|
450
|
+
agent_id="alpha-gpt-evaluator",
|
|
451
|
+
prompt_builder=None,
|
|
452
|
+
output_parser=None,
|
|
453
|
+
output_key="evaluations",
|
|
454
|
+
state_output="all_evaluations",
|
|
455
|
+
tool_executor=_run_evaluator,
|
|
456
|
+
record_factory=None,
|
|
457
|
+
)
|
|
458
|
+
|
|
459
|
+
REFLECTOR_SPEC = StepAgentSpec(
|
|
460
|
+
agent_id="alpha-gpt-reflector",
|
|
461
|
+
prompt_builder=_build_reflector_prompt,
|
|
462
|
+
output_parser=lambda raw: parse_json_3layer(raw, validate_reflector),
|
|
463
|
+
output_key="formula_feedback",
|
|
464
|
+
state_output="all_reflections",
|
|
465
|
+
record_factory=_reflection_factory,
|
|
466
|
+
skip_on_last=True,
|
|
467
|
+
)
|
|
468
|
+
|
|
469
|
+
CRITIC_SPEC = StepAgentSpec(
|
|
470
|
+
agent_id="alpha-gpt-critic",
|
|
471
|
+
prompt_builder=_build_critic_prompt,
|
|
472
|
+
output_parser=lambda raw: parse_json_3layer(raw, validate_critic),
|
|
473
|
+
output_key="final_pool",
|
|
474
|
+
state_output="critic_output",
|
|
475
|
+
record_factory=_critic_factory,
|
|
476
|
+
)
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
# ==============================================================================
|
|
480
|
+
# WorkflowSpec 注册
|
|
481
|
+
# ==============================================================================
|
|
482
|
+
|
|
483
|
+
ALPHA_GPT_SPEC = WorkflowSpec(
|
|
484
|
+
name="alpha-gpt",
|
|
485
|
+
description=(
|
|
486
|
+
"5-round alpha discovery pipeline: "
|
|
487
|
+
"idea generation → formula translation → IC evaluation → reflection → critic selection. "
|
|
488
|
+
"Config: {objective: str, iterations: int=5, pool_size: int=10, top_k: int=10, "
|
|
489
|
+
"data_path: str, a_share_focus: bool=true, forward_returns: [int]=[1,5,20]}"
|
|
490
|
+
),
|
|
491
|
+
steps=[IDEA_GEN_SPEC, FORMULA_TRANS_SPEC, EVALUATOR_SPEC, REFLECTOR_SPEC],
|
|
492
|
+
iterations=5,
|
|
493
|
+
final_steps=[CRITIC_SPEC],
|
|
494
|
+
state_factory=lambda: AlphaGptState(objective=""),
|
|
495
|
+
result_builder=_build_result,
|
|
496
|
+
)
|
|
497
|
+
|
|
498
|
+
REGISTRY.register(ALPHA_GPT_SPEC)
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
__all__ = [
|
|
502
|
+
"ALPHA_GPT_SPEC",
|
|
503
|
+
"IDEA_GEN_SPEC",
|
|
504
|
+
"FORMULA_TRANS_SPEC",
|
|
505
|
+
"EVALUATOR_SPEC",
|
|
506
|
+
"REFLECTOR_SPEC",
|
|
507
|
+
"CRITIC_SPEC",
|
|
508
|
+
]
|