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
QuantNodes/__init__.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
QuantNodes - AI-native quantitative research framework
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
from importlib.metadata import PackageNotFoundError, version as _pkg_version
|
|
8
|
+
try:
|
|
9
|
+
__version__ = _pkg_version("quantnodes")
|
|
10
|
+
except PackageNotFoundError:
|
|
11
|
+
__version__ = "0.0.0+local"
|
|
12
|
+
except ImportError:
|
|
13
|
+
__version__ = "0.0.0+local"
|
|
14
|
+
|
|
15
|
+
__author__ = 'sn0wfree'
|
QuantNodes/__main__.py
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
QuantNodes Agent 系统
|
|
4
|
+
|
|
5
|
+
基于 HKUDS/nanobot 0.2.1 上游 (PyPI: ``nanobot-ai>=0.2.1,<0.3.0``) 的量化研究智能体。
|
|
6
|
+
|
|
7
|
+
v3.0.0 架构变更(Path A: 直接消费上游):
|
|
8
|
+
- 核心运行时由本地复刻 → 改为包装 ``Nanobot.from_config``(见 ``nanobot_bridge.py``)
|
|
9
|
+
- 量化专属 Dream 钩子见 ``QuantNodes.agent.core.quant_dream``
|
|
10
|
+
- 15 个量化工具父类改为 ``nanobot.agent.tools.base.Tool``(见 ``tools/base.py``)
|
|
11
|
+
- workspace 由 ``.quant_agent/`` → ``.agent/``(上游默认约定)
|
|
12
|
+
|
|
13
|
+
**v3.0.0 重要变更(Stage 5.3)**:``nanobot-ai`` 改为 **可选依赖**
|
|
14
|
+
(``pip install 'quantnodes[agent]'``)。未装时:
|
|
15
|
+
- ``NANOBOT_AVAILABLE = False``
|
|
16
|
+
- ``Agent`` 类的属性访问抛 ``NanobotNotInstalled``
|
|
17
|
+
- 量化工具库(Wiki / Factor / Backtest / Strategy)完全可用
|
|
18
|
+
- MCP server、API、CLI 等不依赖 nanobot 的部分正常启动
|
|
19
|
+
|
|
20
|
+
Usage (向后兼容 v2.x 签名):
|
|
21
|
+
from QuantNodes.agent import Agent, NANOBOT_AVAILABLE
|
|
22
|
+
|
|
23
|
+
if NANOBOT_AVAILABLE:
|
|
24
|
+
agent = Agent(workspace=".agent", config={"model": "gpt-4o"})
|
|
25
|
+
response = await agent.run("帮我生成一个动量策略")
|
|
26
|
+
else:
|
|
27
|
+
# 量化工具库仍可用
|
|
28
|
+
from QuantNodes.research.wiki import WikiFactorProxy
|
|
29
|
+
wiki = WikiFactorProxy()
|
|
30
|
+
factor = await wiki.get("momentum_20")
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
from __future__ import annotations
|
|
34
|
+
|
|
35
|
+
import warnings
|
|
36
|
+
from typing import Any
|
|
37
|
+
|
|
38
|
+
from QuantNodes.core.path_utils import ensure_dir
|
|
39
|
+
|
|
40
|
+
__version__ = "3.0.0"
|
|
41
|
+
|
|
42
|
+
# ----------------------------------------------------------------------------
|
|
43
|
+
# Optional-dependency guard
|
|
44
|
+
# ----------------------------------------------------------------------------
|
|
45
|
+
#
|
|
46
|
+
# v3.0.0 之前,``nanobot-ai`` 是强制依赖。从 Stage 5.3 起改为 ``[agent]`` extras:
|
|
47
|
+
# - ``pip install quantnodes`` → 纯量化工具库
|
|
48
|
+
# - ``pip install 'quantnodes[agent]'`` → + nanobot agent / WebUI / MCP
|
|
49
|
+
# - ``pip install 'quantnodes[all]'`` → 装齐所有 extras
|
|
50
|
+
#
|
|
51
|
+
# 顶层 import 任何 nanobot 符号必须先检查 ``NANOBOT_AVAILABLE``,否则
|
|
52
|
+
# ``from QuantNodes.agent import Agent`` 在未装 extras 时会 ImportError。
|
|
53
|
+
NANOBOT_AVAILABLE: bool = True
|
|
54
|
+
NANOBOT_IMPORT_ERROR: str | None = None
|
|
55
|
+
_NANOBOT_PROBE: Any = None
|
|
56
|
+
|
|
57
|
+
# Probe: try to import a real nanobot submodule, not just the top-level
|
|
58
|
+
# namespace. The top-level `nanobot` may exist as a namespace package
|
|
59
|
+
# (e.g. with just a `bridge/` subpackage) but the `nanobot.agent` submodule
|
|
60
|
+
# could be missing — in which case the agent runtime is not usable.
|
|
61
|
+
# We probe a known-deep symbol: ``nanobot.agent.tools.base.Tool``.
|
|
62
|
+
try:
|
|
63
|
+
from nanobot.agent.tools.base import Tool as _ProbeTool # noqa: F401
|
|
64
|
+
NANOBOT_AVAILABLE = True
|
|
65
|
+
del _ProbeTool
|
|
66
|
+
except ImportError as _e: # pragma: no cover - exercised by the import
|
|
67
|
+
NANOBOT_AVAILABLE = False
|
|
68
|
+
NANOBOT_IMPORT_ERROR = str(_e)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class NanobotNotInstalled(ImportError):
|
|
72
|
+
"""Raised when user code touches a nanobot-only symbol without [agent] extra.
|
|
73
|
+
|
|
74
|
+
The error message is tailored to be friendly: it tells the user exactly
|
|
75
|
+
which pip extra to install.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
def __init__(self, symbol: str = "Agent"):
|
|
79
|
+
msg = (
|
|
80
|
+
f"{symbol} requires the optional 'agent' extra. "
|
|
81
|
+
"Install it with: pip install 'quantnodes[agent]' (or 'quantnodes[all]')"
|
|
82
|
+
)
|
|
83
|
+
if NANOBOT_IMPORT_ERROR:
|
|
84
|
+
msg += f"\nUnderlying error: {NANOBOT_IMPORT_ERROR}"
|
|
85
|
+
super().__init__(msg)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
# ----------------------------------------------------------------------------
|
|
89
|
+
# Re-exports (lazy where nanobot is required)
|
|
90
|
+
# ----------------------------------------------------------------------------
|
|
91
|
+
if NANOBOT_AVAILABLE:
|
|
92
|
+
from .nanobot_bridge import Agent # noqa: E402
|
|
93
|
+
from .core.quant_dream import ( # noqa: E402
|
|
94
|
+
QuantDreamHook,
|
|
95
|
+
QuantDreamInsight,
|
|
96
|
+
DreamEngine,
|
|
97
|
+
)
|
|
98
|
+
from .tools import register_all_quant_tools # noqa: E402
|
|
99
|
+
else:
|
|
100
|
+
# Provide a stub for ``Agent`` so ``from QuantNodes.agent import Agent`` does
|
|
101
|
+
# not raise at import time. The stub raises ``NanobotNotInstalled`` only when
|
|
102
|
+
# the user actually tries to *instantiate* or *attribute-access* it.
|
|
103
|
+
class _NanobotUnavailableProxy:
|
|
104
|
+
"""Proxy that raises ``NanobotNotInstalled`` on any access.
|
|
105
|
+
|
|
106
|
+
Implemented via ``__getattr__`` (PEP 562) so that the import itself
|
|
107
|
+
succeeds — only attribute access triggers the error. This keeps
|
|
108
|
+
``from QuantNodes.agent import Agent`` working everywhere; the user's
|
|
109
|
+
first real call (``Agent(...)`` or ``Agent.some_attr``) gets the
|
|
110
|
+
friendly error message.
|
|
111
|
+
"""
|
|
112
|
+
|
|
113
|
+
_PROXY_SYMBOLS = {
|
|
114
|
+
"Agent",
|
|
115
|
+
"QuantDreamHook",
|
|
116
|
+
"QuantDreamInsight",
|
|
117
|
+
"DreamEngine",
|
|
118
|
+
"register_all_quant_tools",
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
def __getattr__(self, name: str) -> Any:
|
|
122
|
+
if name in self._PROXY_SYMBOLS:
|
|
123
|
+
raise NanobotNotInstalled(name)
|
|
124
|
+
raise AttributeError(
|
|
125
|
+
f"module {__name__!r} has no attribute {name!r} (nanobot-ai not installed)"
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
def __call__(self, *args: Any, **kwargs: Any) -> Any: # pragma: no cover
|
|
129
|
+
raise NanobotNotInstalled("Agent")
|
|
130
|
+
|
|
131
|
+
_proxy = _NanobotUnavailableProxy()
|
|
132
|
+
Agent = _proxy # type: ignore[assignment]
|
|
133
|
+
QuantDreamHook = _proxy # type: ignore[assignment]
|
|
134
|
+
QuantDreamInsight = _proxy # type: ignore[assignment]
|
|
135
|
+
DreamEngine = _proxy # type: ignore[assignment]
|
|
136
|
+
register_all_quant_tools = _proxy # type: ignore[assignment]
|
|
137
|
+
|
|
138
|
+
# Emit a one-time DeprecationWarning-ish info on import
|
|
139
|
+
warnings.warn(
|
|
140
|
+
"QuantNodes.agent loaded without nanobot-ai (NANOBOT_AVAILABLE=False). "
|
|
141
|
+
"Agent / WebUI / MCP features are disabled. "
|
|
142
|
+
"Install with: pip install 'quantnodes[agent]'",
|
|
143
|
+
ImportWarning,
|
|
144
|
+
stacklevel=2,
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
__all__ = [
|
|
149
|
+
"__version__",
|
|
150
|
+
"NANOBOT_AVAILABLE",
|
|
151
|
+
"NANOBOT_IMPORT_ERROR",
|
|
152
|
+
"NanobotNotInstalled",
|
|
153
|
+
"Agent",
|
|
154
|
+
"QuantDreamHook",
|
|
155
|
+
"QuantDreamInsight",
|
|
156
|
+
"DreamEngine",
|
|
157
|
+
"register_all_quant_tools",
|
|
158
|
+
]
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
Agent 定义模块
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from typing import Dict, Optional
|
|
8
|
+
from ..permission.models import PermissionRule, Action
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class AgentDefinition:
|
|
13
|
+
"""Agent 定义"""
|
|
14
|
+
id: str
|
|
15
|
+
name: str
|
|
16
|
+
description: str
|
|
17
|
+
mode: str = "primary"
|
|
18
|
+
permission_rules: list[PermissionRule] = field(default_factory=list)
|
|
19
|
+
model: Optional[str] = None
|
|
20
|
+
max_iterations: int = 20
|
|
21
|
+
temperature: float = 0.7
|
|
22
|
+
tools_allowed: Optional[set[str]] = None
|
|
23
|
+
tools_denied: set[str] = field(default_factory=set)
|
|
24
|
+
system_prompt_override: Optional[str] = None
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
QUANTNODES_AGENTS: Dict[str, AgentDefinition] = {
|
|
28
|
+
"build": AgentDefinition(
|
|
29
|
+
id="build",
|
|
30
|
+
name="Build Agent",
|
|
31
|
+
description="默认 Agent,具有完整权限,可执行代码修改和分析",
|
|
32
|
+
mode="primary",
|
|
33
|
+
permission_rules=[
|
|
34
|
+
PermissionRule("*", "*", Action.ALLOW),
|
|
35
|
+
PermissionRule("bash", "*", Action.ASK),
|
|
36
|
+
PermissionRule("external_directory", "*", Action.ASK),
|
|
37
|
+
PermissionRule("read", "*.env", Action.ASK),
|
|
38
|
+
PermissionRule("read", "*.env.*", Action.ASK),
|
|
39
|
+
],
|
|
40
|
+
),
|
|
41
|
+
|
|
42
|
+
"plan": AgentDefinition(
|
|
43
|
+
id="plan",
|
|
44
|
+
name="Plan Agent",
|
|
45
|
+
description="只读分析 Agent,禁止文件修改,用于代码探索和策略分析",
|
|
46
|
+
mode="primary",
|
|
47
|
+
permission_rules=[
|
|
48
|
+
PermissionRule("*", "*", Action.ALLOW),
|
|
49
|
+
PermissionRule("edit", "*", Action.DENY),
|
|
50
|
+
PermissionRule("bash", "*", Action.DENY),
|
|
51
|
+
PermissionRule("write", "*", Action.DENY),
|
|
52
|
+
PermissionRule("read", "*", Action.ALLOW),
|
|
53
|
+
PermissionRule("glob", "*", Action.ALLOW),
|
|
54
|
+
PermissionRule("grep", "*", Action.ALLOW),
|
|
55
|
+
PermissionRule("code_search", "*", Action.ALLOW),
|
|
56
|
+
],
|
|
57
|
+
tools_denied={"sandbox", "git_ops", "file_ops", "strategy", "backtest"},
|
|
58
|
+
),
|
|
59
|
+
|
|
60
|
+
"explore": AgentDefinition(
|
|
61
|
+
id="explore",
|
|
62
|
+
name="Explore Agent",
|
|
63
|
+
description="快速代码搜索子 Agent,只读,用于代码库探索",
|
|
64
|
+
mode="subagent",
|
|
65
|
+
permission_rules=[
|
|
66
|
+
PermissionRule("*", "*", Action.DENY),
|
|
67
|
+
PermissionRule("read", "*", Action.ALLOW),
|
|
68
|
+
PermissionRule("glob", "*", Action.ALLOW),
|
|
69
|
+
PermissionRule("grep", "*", Action.ALLOW),
|
|
70
|
+
PermissionRule("code_search", "*", Action.ALLOW),
|
|
71
|
+
PermissionRule("webfetch", "*", Action.ALLOW),
|
|
72
|
+
],
|
|
73
|
+
tools_denied={
|
|
74
|
+
"sandbox", "git_ops", "file_ops", "strategy", "backtest",
|
|
75
|
+
"pipeline", "factor", "config_backtest", "wiki",
|
|
76
|
+
},
|
|
77
|
+
),
|
|
78
|
+
|
|
79
|
+
"backtest": AgentDefinition(
|
|
80
|
+
id="backtest",
|
|
81
|
+
name="Backtest Agent",
|
|
82
|
+
description="回测专用 Agent,专注于策略回测和分析",
|
|
83
|
+
mode="subagent",
|
|
84
|
+
permission_rules=[
|
|
85
|
+
PermissionRule("*", "*", Action.ALLOW),
|
|
86
|
+
PermissionRule("bash", "*", Action.ASK),
|
|
87
|
+
],
|
|
88
|
+
tools_allowed={
|
|
89
|
+
"backtest", "config_backtest", "factor", "strategy",
|
|
90
|
+
"read", "glob", "grep", "code_search", "wiki",
|
|
91
|
+
},
|
|
92
|
+
),
|
|
93
|
+
|
|
94
|
+
# ========================================================================
|
|
95
|
+
# M5 Alpha-GPT 5-subagent 编排 (基于 .agent/agents/alpha-gpt-*.md)
|
|
96
|
+
# ========================================================================
|
|
97
|
+
|
|
98
|
+
"alpha-gpt-idea-generator": AgentDefinition(
|
|
99
|
+
id="alpha-gpt-idea-generator",
|
|
100
|
+
name="Alpha-GPT Idea Generator",
|
|
101
|
+
description=(
|
|
102
|
+
"Alpha-GPT 第 1 阶段:根据 objective 生成 N 个 alpha 因子想法。"
|
|
103
|
+
"无工具,纯文本生成。"
|
|
104
|
+
),
|
|
105
|
+
mode="subagent",
|
|
106
|
+
temperature=0.8,
|
|
107
|
+
max_iterations=3,
|
|
108
|
+
tools_denied={
|
|
109
|
+
"sandbox", "bash", "shell", "edit", "write", "file_ops",
|
|
110
|
+
"git_ops", "alpha_evaluate", "alpha_backtest",
|
|
111
|
+
"backtest", "pipeline", "factor", "config_backtest",
|
|
112
|
+
},
|
|
113
|
+
),
|
|
114
|
+
|
|
115
|
+
"alpha-gpt-formula-translator": AgentDefinition(
|
|
116
|
+
id="alpha-gpt-formula-translator",
|
|
117
|
+
name="Alpha-GPT Formula Translator",
|
|
118
|
+
description=(
|
|
119
|
+
"Alpha-GPT 第 2 阶段:把 alpha 想法翻译成 polars 公式。"
|
|
120
|
+
"无工具,纯文本生成 + 公式白名单校验。"
|
|
121
|
+
),
|
|
122
|
+
mode="subagent",
|
|
123
|
+
temperature=0.5,
|
|
124
|
+
max_iterations=3,
|
|
125
|
+
tools_denied={
|
|
126
|
+
"sandbox", "bash", "shell", "edit", "write", "file_ops",
|
|
127
|
+
"git_ops", "alpha_evaluate", "alpha_backtest",
|
|
128
|
+
"backtest", "pipeline", "factor", "config_backtest",
|
|
129
|
+
},
|
|
130
|
+
),
|
|
131
|
+
|
|
132
|
+
"alpha-gpt-evaluator": AgentDefinition(
|
|
133
|
+
id="alpha-gpt-evaluator",
|
|
134
|
+
name="Alpha-GPT Evaluator",
|
|
135
|
+
description=(
|
|
136
|
+
"Alpha-GPT 第 3 阶段:调 alpha_evaluate / alpha_backtest 工具"
|
|
137
|
+
"对公式做 IC/IR/Trading 回测评估。"
|
|
138
|
+
),
|
|
139
|
+
mode="subagent",
|
|
140
|
+
temperature=0.3,
|
|
141
|
+
max_iterations=5,
|
|
142
|
+
tools_allowed={
|
|
143
|
+
"alpha_evaluate", "alpha_backtest", "read", "glob",
|
|
144
|
+
},
|
|
145
|
+
),
|
|
146
|
+
|
|
147
|
+
"alpha-gpt-reflector": AgentDefinition(
|
|
148
|
+
id="alpha-gpt-reflector",
|
|
149
|
+
name="Alpha-GPT Reflector",
|
|
150
|
+
description=(
|
|
151
|
+
"Alpha-GPT 第 4 阶段:基于评估结果反思 keep/mutate/drop,"
|
|
152
|
+
"给下一轮 IdeaGenerator 改进建议。无工具。"
|
|
153
|
+
),
|
|
154
|
+
mode="subagent",
|
|
155
|
+
temperature=0.5,
|
|
156
|
+
max_iterations=3,
|
|
157
|
+
tools_denied={
|
|
158
|
+
"sandbox", "bash", "shell", "edit", "write", "file_ops",
|
|
159
|
+
"git_ops", "alpha_evaluate", "alpha_backtest",
|
|
160
|
+
"backtest", "pipeline", "factor", "config_backtest",
|
|
161
|
+
},
|
|
162
|
+
),
|
|
163
|
+
|
|
164
|
+
"alpha-gpt-critic": AgentDefinition(
|
|
165
|
+
id="alpha-gpt-critic",
|
|
166
|
+
name="Alpha-GPT Critic",
|
|
167
|
+
description=(
|
|
168
|
+
"Alpha-GPT 第 5 阶段:从所有历史公式中选最终 top-K,"
|
|
169
|
+
"综合 IR / 衰减 / mutual_IC 评分。无工具。"
|
|
170
|
+
),
|
|
171
|
+
mode="subagent",
|
|
172
|
+
temperature=0.2,
|
|
173
|
+
max_iterations=3,
|
|
174
|
+
tools_denied={
|
|
175
|
+
"sandbox", "bash", "shell", "edit", "write", "file_ops",
|
|
176
|
+
"git_ops", "alpha_evaluate", "alpha_backtest",
|
|
177
|
+
"backtest", "pipeline", "factor", "config_backtest",
|
|
178
|
+
},
|
|
179
|
+
),
|
|
180
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
Agent 管理器
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from typing import Dict, Optional
|
|
7
|
+
from .definition import AgentDefinition, QUANTNODES_AGENTS
|
|
8
|
+
from ..permission.service import PermissionService
|
|
9
|
+
from ..permission.defaults import create_default_ruleset
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class AgentManager:
|
|
13
|
+
"""Agent 管理器
|
|
14
|
+
|
|
15
|
+
职责:
|
|
16
|
+
1. 管理 Agent 定义
|
|
17
|
+
2. 处理 Agent 切换
|
|
18
|
+
3. 为每个 Agent 创建权限服务
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def __init__(self, project_root: str):
|
|
22
|
+
self._agents = dict(QUANTNODES_AGENTS)
|
|
23
|
+
self._current_agent: str = "build"
|
|
24
|
+
self._project_root = project_root
|
|
25
|
+
self._permission_services: Dict[str, PermissionService] = {}
|
|
26
|
+
|
|
27
|
+
def get_current_agent(self) -> AgentDefinition:
|
|
28
|
+
"""获取当前 Agent"""
|
|
29
|
+
return self._agents[self._current_agent]
|
|
30
|
+
|
|
31
|
+
def set_agent(self, agent_id: str) -> AgentDefinition:
|
|
32
|
+
"""切换 Agent
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
agent_id: Agent ID
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
新的 Agent 定义
|
|
39
|
+
|
|
40
|
+
Raises:
|
|
41
|
+
ValueError: 如果 Agent 不存在
|
|
42
|
+
"""
|
|
43
|
+
if agent_id not in self._agents:
|
|
44
|
+
raise ValueError(f"Agent not found: {agent_id}")
|
|
45
|
+
|
|
46
|
+
self._current_agent = agent_id
|
|
47
|
+
return self._agents[agent_id]
|
|
48
|
+
|
|
49
|
+
def get_permission_service(self, agent_id: Optional[str] = None) -> PermissionService:
|
|
50
|
+
"""获取 Agent 的权限服务
|
|
51
|
+
|
|
52
|
+
每个 Agent 有独立的权限服务,规则集根据 Agent 定义合并。
|
|
53
|
+
"""
|
|
54
|
+
agent_id = agent_id or self._current_agent
|
|
55
|
+
|
|
56
|
+
if agent_id not in self._permission_services:
|
|
57
|
+
default_rules = create_default_ruleset(self._project_root)
|
|
58
|
+
agent_rules = self._agents[agent_id].permission_rules
|
|
59
|
+
combined_rules = default_rules + agent_rules
|
|
60
|
+
|
|
61
|
+
self._permission_services[agent_id] = PermissionService(
|
|
62
|
+
ruleset=combined_rules,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
return self._permission_services[agent_id]
|
|
66
|
+
|
|
67
|
+
def list_agents(self) -> list[AgentDefinition]:
|
|
68
|
+
"""列出所有 Agent"""
|
|
69
|
+
return list(self._agents.values())
|
|
70
|
+
|
|
71
|
+
def register_agent(self, agent: AgentDefinition) -> None:
|
|
72
|
+
"""注册自定义 Agent"""
|
|
73
|
+
self._agents[agent.id] = agent
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
QuantNodes Agent Config - 配置文件驱动模块
|
|
4
|
+
|
|
5
|
+
基于 YAML 的策略配置加载和执行。
|
|
6
|
+
|
|
7
|
+
Modules:
|
|
8
|
+
types: 类型定义
|
|
9
|
+
loader: 配置加载器
|
|
10
|
+
executor: 配置执行器
|
|
11
|
+
|
|
12
|
+
Usage:
|
|
13
|
+
from QuantNodes.agent.config import ConfigLoader, ConfigExecutor
|
|
14
|
+
|
|
15
|
+
loader = ConfigLoader()
|
|
16
|
+
config = loader.load("strategy.yaml")
|
|
17
|
+
|
|
18
|
+
executor = ConfigExecutor()
|
|
19
|
+
result = executor.run(config, data)
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from .loader import ConfigLoader, load_config
|
|
23
|
+
from .executor import ConfigExecutor
|
|
24
|
+
from .types import StrategyConfig, FactorConfig, OperationConfig, BacktestConfig
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"ConfigLoader",
|
|
28
|
+
"ConfigExecutor",
|
|
29
|
+
"load_config",
|
|
30
|
+
"StrategyConfig",
|
|
31
|
+
"FactorConfig",
|
|
32
|
+
"OperationConfig",
|
|
33
|
+
"BacktestConfig",
|
|
34
|
+
]
|