463 lines
17 KiB
Python
463 lines
17 KiB
Python
"""Default runtime profiles for protected AI functions."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
|
|
AI_FUNCTION_RUNTIME_PROFILE_INTEGRATION_TYPE = "ai_function_runtime_profiles"
|
|
|
|
DEFAULT_AI_FUNCTION_RUNTIME_PROFILES: dict[str, dict[str, Any]] = {
|
|
"pmflow_launch_draft_v1": {
|
|
"function_name": "pmflow_launch_draft_v1",
|
|
"label": "项目启动草案生成",
|
|
"scene_key": "project_launch",
|
|
"prompt_key": "PROMPT_PMFLOW_LAUNCH_DRAFT",
|
|
"required_slot": "structured",
|
|
"response_contract": "structured",
|
|
"max_tokens": 10000,
|
|
"max_tokens_min": 3000,
|
|
"max_tokens_max": 10000,
|
|
"recommended_min_tokens": 6500,
|
|
"repair_max_tokens": 3600,
|
|
"temperature": 0.0,
|
|
"foreground_wait_seconds": 10,
|
|
"provider_timeout_seconds": 90,
|
|
"job_timeout_seconds": 180,
|
|
"max_retries": 1,
|
|
"large_input_policy": "preprocess_then_generate",
|
|
"response_mode": "fast",
|
|
"response_format": "json_object",
|
|
"retry_policy": {
|
|
"on_length": "model_repair_then_fail",
|
|
"on_json_invalid": "model_repair_then_fail",
|
|
"max_attempts": 2,
|
|
},
|
|
"health_policy": {
|
|
"window_hours": 24,
|
|
"consecutive_failure_threshold": 3,
|
|
"smoke_required_for_publish": True,
|
|
},
|
|
"cost_policy": {
|
|
"budget_class": "medium",
|
|
"estimated_cost_ceiling_cny": 0.02,
|
|
"show_cost_warning_above_tokens": 8000,
|
|
},
|
|
},
|
|
"pmflow_change_review_extraction_v1": {
|
|
"function_name": "pmflow_change_review_extraction_v1",
|
|
"label": "项目主链变更抽取",
|
|
"scene_key": "change_review",
|
|
"prompt_key": "PROMPT_PMFLOW_CHANGE_REVIEW_EXTRACTION",
|
|
"required_slot": "structured",
|
|
"response_contract": "structured",
|
|
"max_tokens": 10000,
|
|
"max_tokens_min": 1800,
|
|
"max_tokens_max": 10000,
|
|
"recommended_min_tokens": 4200,
|
|
"repair_max_tokens": 2400,
|
|
"temperature": 0.0,
|
|
"foreground_wait_seconds": 8,
|
|
"provider_timeout_seconds": 90,
|
|
"job_timeout_seconds": 180,
|
|
"max_retries": 1,
|
|
"large_input_policy": "preprocess_then_generate",
|
|
"response_mode": "fast",
|
|
"response_format": "json_object",
|
|
"retry_policy": {
|
|
"on_length": "model_repair_then_fail",
|
|
"on_json_invalid": "model_repair_then_fail",
|
|
"max_attempts": 2,
|
|
},
|
|
"health_policy": {
|
|
"window_hours": 24,
|
|
"consecutive_failure_threshold": 3,
|
|
"smoke_required_for_publish": True,
|
|
},
|
|
"cost_policy": {
|
|
"budget_class": "medium",
|
|
"estimated_cost_ceiling_cny": 0.015,
|
|
"show_cost_warning_above_tokens": 6500,
|
|
},
|
|
},
|
|
"customer_answer_composer": {
|
|
"function_name": "customer_answer_composer",
|
|
"label": "客户答案表达生成",
|
|
"scene_key": "pmflow_ai_answer_presentation",
|
|
"prompt_key": "PROMPT_CUSTOMER_ANSWER_COMPOSER",
|
|
"required_slot": "low",
|
|
"response_contract": "text",
|
|
"max_tokens": 10000,
|
|
"max_tokens_min": 700,
|
|
"max_tokens_max": 10000,
|
|
"recommended_min_tokens": 1400,
|
|
"repair_max_tokens": 1000,
|
|
"temperature": 0.2,
|
|
"foreground_wait_seconds": 8,
|
|
"provider_timeout_seconds": 120,
|
|
"job_timeout_seconds": 240,
|
|
"max_retries": 1,
|
|
"large_input_policy": "direct_generate",
|
|
"response_mode": "fast",
|
|
"response_format": "text",
|
|
"retry_policy": {
|
|
"on_length": "retry_with_larger_budget_then_fallback",
|
|
"max_attempts": 2,
|
|
},
|
|
"health_policy": {
|
|
"window_hours": 24,
|
|
"consecutive_failure_threshold": 3,
|
|
"smoke_required_for_publish": False,
|
|
},
|
|
"cost_policy": {
|
|
"budget_class": "medium",
|
|
"estimated_cost_ceiling_cny": 0.02,
|
|
"show_cost_warning_above_tokens": 8000,
|
|
},
|
|
},
|
|
"space_ai_interaction_option_planner": {
|
|
"function_name": "space_ai_interaction_option_planner",
|
|
"label": "Space AI 追问选项规划",
|
|
"scene_key": "pmflow_ai_answer_presentation",
|
|
"prompt_key": "PROMPT_SPACE_AI_INTERACTION_OPTION_PLANNER",
|
|
"required_slot": "low",
|
|
"response_contract": "json",
|
|
"max_tokens": 4000,
|
|
"max_tokens_min": 700,
|
|
"max_tokens_max": 6000,
|
|
"recommended_min_tokens": 1600,
|
|
"repair_max_tokens": 800,
|
|
"temperature": 0.1,
|
|
"foreground_wait_seconds": 5,
|
|
"provider_timeout_seconds": 60,
|
|
"job_timeout_seconds": 120,
|
|
"max_retries": 1,
|
|
"large_input_policy": "direct_generate",
|
|
"response_mode": "fast",
|
|
"response_format": "json_object",
|
|
"retry_policy": {
|
|
"on_json_invalid": "fallback_to_generic_options",
|
|
"max_attempts": 1,
|
|
},
|
|
"health_policy": {
|
|
"window_hours": 24,
|
|
"consecutive_failure_threshold": 3,
|
|
"smoke_required_for_publish": False,
|
|
},
|
|
"cost_policy": {
|
|
"budget_class": "low",
|
|
"estimated_cost_ceiling_cny": 0.01,
|
|
"show_cost_warning_above_tokens": 5000,
|
|
},
|
|
},
|
|
"customer_answer_verifier": {
|
|
"function_name": "customer_answer_verifier",
|
|
"label": "客户答案安全质检",
|
|
"scene_key": "pmflow_ai_answer_presentation",
|
|
"prompt_key": "PROMPT_CUSTOMER_ANSWER_VERIFIER",
|
|
"required_slot": "low",
|
|
"response_contract": "json",
|
|
"max_tokens": 10000,
|
|
"max_tokens_min": 300,
|
|
"max_tokens_max": 10000,
|
|
"recommended_min_tokens": 300,
|
|
"repair_max_tokens": 300,
|
|
"temperature": 0.0,
|
|
"foreground_wait_seconds": 5,
|
|
"provider_timeout_seconds": 60,
|
|
"job_timeout_seconds": 120,
|
|
"max_retries": 1,
|
|
"large_input_policy": "direct_generate",
|
|
"response_mode": "fast",
|
|
"response_format": "json_object",
|
|
"retry_policy": {
|
|
"on_json_invalid": "deterministic_guard_fallback",
|
|
"max_attempts": 1,
|
|
},
|
|
"health_policy": {
|
|
"window_hours": 24,
|
|
"consecutive_failure_threshold": 3,
|
|
"smoke_required_for_publish": False,
|
|
},
|
|
"cost_policy": {
|
|
"budget_class": "low",
|
|
"estimated_cost_ceiling_cny": 0.01,
|
|
"show_cost_warning_above_tokens": 8000,
|
|
},
|
|
},
|
|
"pmflow_ai_operating_mission": {
|
|
"function_name": "pmflow_ai_operating_mission",
|
|
"label": "Space AI Operating Mission 生成",
|
|
"scene_key": "space_pmflow_ai_operating_runtime",
|
|
"prompt_key": "PROMPT_PMFLOW_AI_OPERATING_MISSION",
|
|
"required_slot": "low",
|
|
"response_contract": "json",
|
|
"max_tokens": 1600,
|
|
"max_tokens_min": 600,
|
|
"max_tokens_max": 4000,
|
|
"recommended_min_tokens": 1600,
|
|
"repair_max_tokens": 600,
|
|
"temperature": 0.0,
|
|
"foreground_wait_seconds": 6,
|
|
"provider_timeout_seconds": 60,
|
|
"job_timeout_seconds": 90,
|
|
"max_retries": 0,
|
|
"large_input_policy": "direct_generate",
|
|
"response_mode": "fast",
|
|
"response_format": "json_object",
|
|
"retry_policy": {
|
|
"on_timeout": "deterministic_mission_fallback",
|
|
"on_json_invalid": "deterministic_mission_fallback",
|
|
"max_attempts": 1,
|
|
},
|
|
"health_policy": {
|
|
"window_hours": 24,
|
|
"consecutive_failure_threshold": 3,
|
|
"smoke_required_for_publish": False,
|
|
},
|
|
"cost_policy": {
|
|
"budget_class": "low",
|
|
"estimated_cost_ceiling_cny": 0.01,
|
|
"show_cost_warning_above_tokens": 5000,
|
|
},
|
|
},
|
|
"pmflow_ai_agent_goal_frame": {
|
|
"function_name": "pmflow_ai_agent_goal_frame",
|
|
"label": "Space AI Agent 目标框架",
|
|
"scene_key": "space_pmflow_ai_agent_runtime",
|
|
"prompt_key": "PROMPT_PMFLOW_AI_AGENT_GOAL_FRAME",
|
|
"required_slot": "low",
|
|
"response_contract": "json",
|
|
"max_tokens": 1600,
|
|
"max_tokens_min": 600,
|
|
"max_tokens_max": 6000,
|
|
"recommended_min_tokens": 1200,
|
|
"repair_max_tokens": 600,
|
|
"temperature": 0.0,
|
|
"foreground_wait_seconds": 45,
|
|
"provider_timeout_seconds": 45,
|
|
"job_timeout_seconds": 55,
|
|
"max_retries": 0,
|
|
"large_input_policy": "direct_generate",
|
|
"response_mode": "fast",
|
|
"response_format": "json_object",
|
|
"retry_policy": {"on_timeout": "deterministic_agent_node_fallback", "max_attempts": 1},
|
|
"health_policy": {"window_hours": 24, "consecutive_failure_threshold": 3, "smoke_required_for_publish": False},
|
|
"cost_policy": {"budget_class": "low", "estimated_cost_ceiling_cny": 0.01, "show_cost_warning_above_tokens": 5000},
|
|
},
|
|
"pmflow_ai_agent_step_planner": {
|
|
"function_name": "pmflow_ai_agent_step_planner",
|
|
"label": "Space AI Agent 步骤规划",
|
|
"scene_key": "space_pmflow_ai_agent_runtime",
|
|
"prompt_key": "PROMPT_PMFLOW_AI_AGENT_STEP_PLANNER",
|
|
"required_slot": "low",
|
|
"response_contract": "json",
|
|
"max_tokens": 1600,
|
|
"max_tokens_min": 600,
|
|
"max_tokens_max": 6000,
|
|
"recommended_min_tokens": 1200,
|
|
"repair_max_tokens": 600,
|
|
"temperature": 0.0,
|
|
"foreground_wait_seconds": 45,
|
|
"provider_timeout_seconds": 45,
|
|
"job_timeout_seconds": 55,
|
|
"max_retries": 0,
|
|
"large_input_policy": "direct_generate",
|
|
"response_mode": "fast",
|
|
"response_format": "json_object",
|
|
"retry_policy": {"on_timeout": "deterministic_agent_node_fallback", "max_attempts": 1},
|
|
"health_policy": {"window_hours": 24, "consecutive_failure_threshold": 3, "smoke_required_for_publish": False},
|
|
"cost_policy": {"budget_class": "low", "estimated_cost_ceiling_cny": 0.01, "show_cost_warning_above_tokens": 5000},
|
|
},
|
|
"pmflow_ai_agent_evidence_normalizer": {
|
|
"function_name": "pmflow_ai_agent_evidence_normalizer",
|
|
"label": "Space AI Agent 证据归一",
|
|
"scene_key": "space_pmflow_ai_agent_runtime",
|
|
"prompt_key": "PROMPT_PMFLOW_AI_AGENT_EVIDENCE_NORMALIZER",
|
|
"required_slot": "low",
|
|
"response_contract": "json",
|
|
"max_tokens": 2800,
|
|
"max_tokens_min": 900,
|
|
"max_tokens_max": 8000,
|
|
"recommended_min_tokens": 2200,
|
|
"repair_max_tokens": 900,
|
|
"temperature": 0.0,
|
|
"foreground_wait_seconds": 75,
|
|
"provider_timeout_seconds": 75,
|
|
"job_timeout_seconds": 90,
|
|
"max_retries": 0,
|
|
"large_input_policy": "direct_generate",
|
|
"response_mode": "fast",
|
|
"response_format": "json_object",
|
|
"runtime_mode": "active",
|
|
"quality_gate_mode": "strict",
|
|
"retry_policy": {"on_timeout": "bounded_evidence_fallback", "max_attempts": 1},
|
|
"health_policy": {"window_hours": 24, "consecutive_failure_threshold": 3, "smoke_required_for_publish": False},
|
|
"cost_policy": {"budget_class": "low", "estimated_cost_ceiling_cny": 0.015, "show_cost_warning_above_tokens": 7000},
|
|
},
|
|
"pmflow_ai_agent_state_critic": {
|
|
"function_name": "pmflow_ai_agent_state_critic",
|
|
"label": "Space AI Agent 状态审查",
|
|
"scene_key": "space_pmflow_ai_agent_runtime",
|
|
"prompt_key": "PROMPT_PMFLOW_AI_AGENT_STATE_CRITIC",
|
|
"required_slot": "low",
|
|
"response_contract": "json",
|
|
"max_tokens": 1600,
|
|
"max_tokens_min": 600,
|
|
"max_tokens_max": 6000,
|
|
"recommended_min_tokens": 1200,
|
|
"repair_max_tokens": 600,
|
|
"temperature": 0.0,
|
|
"foreground_wait_seconds": 30,
|
|
"provider_timeout_seconds": 30,
|
|
"job_timeout_seconds": 40,
|
|
"max_retries": 0,
|
|
"large_input_policy": "direct_generate",
|
|
"response_mode": "fast",
|
|
"response_format": "json_object",
|
|
"retry_policy": {"on_timeout": "deterministic_agent_node_fallback", "max_attempts": 1},
|
|
"health_policy": {"window_hours": 24, "consecutive_failure_threshold": 3, "smoke_required_for_publish": False},
|
|
"cost_policy": {"budget_class": "low", "estimated_cost_ceiling_cny": 0.01, "show_cost_warning_above_tokens": 5000},
|
|
},
|
|
"pmflow_ai_agent_answer_composer": {
|
|
"function_name": "pmflow_ai_agent_answer_composer",
|
|
"label": "Space AI Agent 终局答案生成",
|
|
"scene_key": "space_pmflow_ai_agent_runtime",
|
|
"prompt_key": "PROMPT_PMFLOW_AI_AGENT_ANSWER_COMPOSER",
|
|
"required_slot": "low",
|
|
"response_contract": "text",
|
|
"max_tokens": 2600,
|
|
"max_tokens_min": 900,
|
|
"max_tokens_max": 8000,
|
|
"recommended_min_tokens": 2200,
|
|
"repair_max_tokens": 900,
|
|
"temperature": 0.2,
|
|
"foreground_wait_seconds": 60,
|
|
"provider_timeout_seconds": 60,
|
|
"job_timeout_seconds": 75,
|
|
"max_retries": 0,
|
|
"large_input_policy": "direct_generate",
|
|
"response_mode": "fast",
|
|
"response_format": "text",
|
|
"runtime_mode": "active",
|
|
"quality_gate_mode": "off",
|
|
"retry_policy": {"on_timeout": "terminal_state_fallback", "max_attempts": 1},
|
|
"health_policy": {"window_hours": 24, "consecutive_failure_threshold": 3, "smoke_required_for_publish": False},
|
|
"cost_policy": {"budget_class": "low", "estimated_cost_ceiling_cny": 0.015, "show_cost_warning_above_tokens": 7000},
|
|
},
|
|
"pmflow_ai_agent_answer_reviser": {
|
|
"function_name": "pmflow_ai_agent_answer_reviser",
|
|
"label": "Space AI Agent 答案修订",
|
|
"scene_key": "space_pmflow_ai_agent_runtime",
|
|
"prompt_key": "PROMPT_PMFLOW_AI_AGENT_ANSWER_REVISER",
|
|
"required_slot": "low",
|
|
"response_contract": "text",
|
|
"max_tokens": 2600,
|
|
"max_tokens_min": 900,
|
|
"max_tokens_max": 8000,
|
|
"recommended_min_tokens": 2000,
|
|
"repair_max_tokens": 900,
|
|
"temperature": 0.15,
|
|
"foreground_wait_seconds": 45,
|
|
"provider_timeout_seconds": 45,
|
|
"job_timeout_seconds": 55,
|
|
"max_retries": 0,
|
|
"large_input_policy": "direct_generate",
|
|
"response_mode": "fast",
|
|
"response_format": "text",
|
|
"runtime_mode": "active",
|
|
"quality_gate_mode": "off",
|
|
"retry_policy": {"on_timeout": "terminal_state_fallback", "max_attempts": 1},
|
|
"health_policy": {"window_hours": 24, "consecutive_failure_threshold": 3, "smoke_required_for_publish": False},
|
|
"cost_policy": {"budget_class": "low", "estimated_cost_ceiling_cny": 0.015, "show_cost_warning_above_tokens": 7000},
|
|
},
|
|
"external_query_dashscope_responses": {
|
|
"function_name": "external_query_dashscope_responses",
|
|
"label": "DashScope Responses 外部搜索",
|
|
"scene_key": "external_query",
|
|
"prompt_key": "",
|
|
"required_slot": "external_query",
|
|
"response_contract": "external_evidence",
|
|
"max_tokens": 1000,
|
|
"max_tokens_min": 1,
|
|
"max_tokens_max": 4000,
|
|
"recommended_min_tokens": 1,
|
|
"repair_max_tokens": 180,
|
|
"temperature": 0.0,
|
|
"foreground_wait_seconds": 8,
|
|
"provider_timeout_seconds": 120,
|
|
"job_timeout_seconds": 180,
|
|
"max_retries": 0,
|
|
"large_input_policy": "direct_generate",
|
|
"response_mode": "tool",
|
|
"response_format": "external_evidence",
|
|
"retry_policy": {
|
|
"on_timeout": "try_next_external_adapter",
|
|
"max_attempts": 1,
|
|
},
|
|
"health_policy": {
|
|
"window_hours": 24,
|
|
"consecutive_failure_threshold": 3,
|
|
"smoke_required_for_publish": False,
|
|
},
|
|
"cost_policy": {
|
|
"budget_class": "external_query",
|
|
"estimated_cost_ceiling_cny": 0.05,
|
|
"show_cost_warning_above_tokens": 30000,
|
|
},
|
|
},
|
|
}
|
|
|
|
_AGENT_RUNTIME_FULL_BUDGET_PROFILE_NAMES = (
|
|
"pmflow_ai_agent_goal_frame",
|
|
"pmflow_ai_agent_step_planner",
|
|
"pmflow_ai_agent_evidence_normalizer",
|
|
"pmflow_ai_agent_state_critic",
|
|
"pmflow_ai_agent_answer_composer",
|
|
"pmflow_ai_agent_answer_reviser",
|
|
"external_query_dashscope_responses",
|
|
)
|
|
|
|
for _profile_name in _AGENT_RUNTIME_FULL_BUDGET_PROFILE_NAMES:
|
|
_profile = DEFAULT_AI_FUNCTION_RUNTIME_PROFILES.get(_profile_name)
|
|
if not isinstance(_profile, dict):
|
|
continue
|
|
_profile.update(
|
|
{
|
|
"max_tokens": 10000,
|
|
"max_tokens_max": 10000,
|
|
"recommended_min_tokens": 10000,
|
|
"repair_max_tokens": 10000,
|
|
"foreground_wait_seconds": 180,
|
|
"provider_timeout_seconds": 180,
|
|
"job_timeout_seconds": 180,
|
|
}
|
|
)
|
|
|
|
|
|
def default_runtime_profile_bundle() -> dict[str, Any]:
|
|
return {
|
|
"version": "profile-default-v1",
|
|
"active_version": "profile-default-v1",
|
|
"draft_version": "draft",
|
|
"active": {
|
|
"profiles": DEFAULT_AI_FUNCTION_RUNTIME_PROFILES,
|
|
"published_at": None,
|
|
"published_by": None,
|
|
},
|
|
"draft": {
|
|
"profiles": DEFAULT_AI_FUNCTION_RUNTIME_PROFILES,
|
|
"updated_at": None,
|
|
"updated_by": None,
|
|
"last_smoke": {},
|
|
},
|
|
"history": [],
|
|
}
|
|
|
|
|
|
__all__ = [
|
|
"AI_FUNCTION_RUNTIME_PROFILE_INTEGRATION_TYPE",
|
|
"DEFAULT_AI_FUNCTION_RUNTIME_PROFILES",
|
|
"default_runtime_profile_bundle",
|
|
]
|