AINativeBench / data /processed /RQ1 /SQLAssistant-MCP /reference_trajectory.yaml
王子睿
restructure + add files
8c10cf2
Raw
History Blame
13.3 kB
# Complete Reference Trajectory Configuration - SQLAssistant-MCP Project
#
# Version: Ideal trajectory based on code design (applicable to all models)
# Principle: Only include steps explicitly required by code design, not based on test statistics
#
# Code Design Analysis:
# 1. Execution Flow (orchestrator.py):
# - Orchestrator manages entire workflow with two-level retry logic:
# (a) Orchestrator-level retry: For exception errors (max 3 attempts, MAX_CREW_RETRIES=2)
# (b) Business logic retry: For compliance check failures (max 3 attempts, max_business_retries=2)
# - Ideal flow (no retry):
# Step 1-2: Generate and review SQL (SQLGenerationCrew)
# Step 3: Compliance check (ComplianceCheckerCrew)
# Step 4: Execute SQL query (only if compliance passes)
# Step 5: Interpret results (ResultInterpreterCrew, only if compliance passes)
#
# 2. Three Crew Agent Structure:
# - SQLGenerationCrew (sql_generation/sql_generation_crew.py):
# - Agent 1: Expert SQL Query Generator
# Tools: get_database_schema, get_table_sample, get_column_stats, list_tables
# - Agent 2: Senior SQL Code Reviewer
# Tools: validate_sql_syntax, get_database_schema, check_table_exists
# - ComplianceCheckerCrew (compliance_checker/compliance_checker_crew.py):
# - Agent: Data Security and Compliance Auditor
# Tools: get_database_schema, check_table_exists
# - ResultInterpreterCrew (result_interpreter/result_interpreter_crew.py):
# - Agent: Business Intelligence Analyst
# Tools: run_sql_query, count_rows
#
# 3. SPAN Hierarchy:
# - sql_assistant_workflow (top level, orchestrator.py line 226)
# - crew_execution (contains retry logic, orchestrator.py line 243)
# - generate_sql (SQL generation, orchestrator.py line 266)
# - check_compliance (compliance check, orchestrator.py line 316)
# - interpret_results (result interpretation, orchestrator.py line 380, only if compliance passes)
#
# 4. MCP Tools (tools/mcp_server.py):
# - Database exploration: get_database_schema, get_table_sample, get_column_stats, list_tables
# - SQL validation: validate_sql_syntax, check_table_exists
# - Query execution: run_sql_query, count_rows
# Project name
project_name: "SQLAssistant-MCP"
# Trajectory extraction type configuration
extract_types:
- "SPAN" # Multi-level SPAN structure
- "Chain" # Each Crew's kickoff chain
- "Agent" # Each Crew's Agent
- "LLM" # LLM calls
- "Tool" # MCP tool calls
# Repeatable pattern configuration
# SQLAssistant-MCP has no repeatable patterns (unlike book writing with multiple chapters)
repeatable_patterns: []
# ============================================================================
# Reference Trajectory (Ground Truth) - Based on Code Design
# ============================================================================
#
# Graphical Structure (ideal execution path, no retry, no error, each Agent uses
# at least the key tools required in config/tasks; other tools are optional):
#
# [SPAN] sql_assistant_workflow
# +-- [SPAN] crew_execution
# +-- [SPAN] generate_sql
# | +-- [Chain] Crew***.kickoff
# | +-- [Agent] Expert SQL Query Generator
# | | +-- [LLM] *
# | | +-- [Tool] get_database_schema
# | | +-- [LLM] *
# | +-- [Agent] Senior SQL Code Reviewer
# | +-- [LLM] *
# | +-- [Tool] validate_sql_syntax
# | +-- [LLM] *
# | +-- [Tool] get_database_schema
# | +-- [LLM] *
# +-- [SPAN] check_compliance
# | +-- [Chain] Crew***.kickoff
# | +-- [Agent] Data Security and Compliance Auditor
# | +-- [LLM] *
# | +-- [Tool] get_database_schema
# | +-- [LLM] *
# +-- [SPAN] interpret_results
# +-- [Chain] Crew***.kickoff
# +-- [Agent] Business Intelligence Analyst
# +-- [LLM] *
# +-- [Tool] run_sql_query (execute query)
# +-- [LLM] *
#
# Design Basis:
# - orchestrator.py: Sequential execution of 5 steps (generate, review, compliance, execute, interpret)
# - SQLGenerationCrew contains 2 Agents, sequential execution (Generator -> Reviewer)
# - ComplianceCheckerCrew contains 1 Agent
# - ResultInterpreterCrew contains 1 Agent, uses run_sql_query to execute query
# - All Agent roles defined in each crew's config/agents.yaml
# - Tools obtained from MCP server via MCPServerAdapter
#
# Ideal Trajectory Notes:
# - Top-level SPAN: sql_assistant_workflow
# - Second-level SPAN: crew_execution (contains two-level retry logic)
# - 3 sub-SPANs execute sequentially: generate_sql -> check_compliance -> interpret_results
# - generate_sql stage: Generator explores schema, Reviewer validates syntax
# - check_compliance stage: Auditor checks security and compliance, must pass (PASS verdict)
# - interpret_results stage: BI Analyst uses run_sql_query to execute and interpret results
# - This trajectory represents ideal execution path with no retry, no error
#
# Notes:
# - "LLM: *" means any LLM model (wildcard match)
# - AGENT names exactly match role field in agents.yaml
# - Tool names exactly match MCP server provided tool names
# - Tool calls may vary based on Agent decisions (e.g., Generator may use get_database_schema or list_tables)
# - Reviewer may skip tool calls (if SQL is already correct)
# - Auditor may skip tool calls (if no additional verification needed)
# ============================================================================
reference_trajectory:
# ===== Top-level SPAN =====
- "SPAN: sql_assistant_workflow"
# ===== Second-level SPAN (contains two-level retry logic) =====
- "SPAN: crew_execution"
# ===== Stage 1: Generate SQL (SQLGenerationCrew) =====
- "SPAN: generate_sql"
- "Chain: Crew***.kickoff"
# Agent 1: SQL Generator (uses key tools required in config/tasks)
- "Agent: Expert SQL Query Generator"
- "LLM: *" # Decide overall generation strategy
- "Tool: get_database_schema" # Per tasks.yaml, first view complete schema
- "LLM: *" # Generate candidate SQL query based on schema
# Other tools (list_tables / get_table_sample / get_column_stats) are optional exploration tools
# Agent 2: SQL Reviewer (uses key tools required in config/tasks)
- "Agent: Senior SQL Code Reviewer"
- "LLM: *" # Read and understand generated SQL
- "Tool: validate_sql_syntax" # Per tasks.yaml and backstory, must check syntax
- "LLM: *" # Analyze syntax check results
- "Tool: get_database_schema" # Per tasks.yaml, verify tables and columns exist
- "LLM: *" # Correct SQL based on schema check results
# ===== Stage 2: Check Compliance (ComplianceCheckerCrew) =====
- "SPAN: check_compliance"
- "Chain: Crew***.kickoff"
- "Agent: Data Security and Compliance Auditor"
- "LLM: *" # Initial SQL reading and risk identification
- "Tool: get_database_schema" # Required: view schema to assess table/field sensitivity
- "LLM: *" # Combine SQL text and schema to give PASS/FAIL verdict
# ===== Stage 3: Interpret Results (ResultInterpreterCrew) =====
# Note: This stage only executes if compliance passes
- "SPAN: interpret_results"
- "Chain: Crew***.kickoff"
- "Agent: Business Intelligence Analyst"
- "LLM: *" # Understand business question and reviewed SQL
- "Tool: run_sql_query" # Per tasks.yaml and backstory, must use run_sql_query to get real data
- "LLM: *" # Generate business interpretation based on real results (count_rows etc. are optional)
# Target tools list (for single-tool use metric)
# Lists all tools filtered for each Agent in configuration
target_tools:
# SQL Generation stage - Generator
- "Tool: get_database_schema"
- "Tool: get_table_sample"
- "Tool: get_column_stats"
- "Tool: list_tables"
# SQL Generation stage - Reviewer
- "Tool: validate_sql_syntax"
- "Tool: check_table_exists"
# Compliance stage
# (shares get_database_schema and check_table_exists with Reviewer, not repeated)
# Result Interpretation stage
- "Tool: run_sql_query"
- "Tool: count_rows"
# Models to evaluate
models:
- "GPT-5"
- "GPT-4o-mini"
- "DeepSeek-V3-1"
- "DeepSeek-R1"
- "Gemini-2.5-flash"
- "Gemini-2.5-flash-nothinking"
- "Qwen3-235b"
# ============================================================================
# Usage Instructions
# ============================================================================
#
# 1. Trajectory Hierarchy:
# - Level 1: SPAN (sql_assistant_workflow)
# - Level 2: SPAN (crew_execution)
# - Level 3: SPAN (generate_sql, check_compliance, interpret_results)
# - Level 4: Chain (Crew***.kickoff, wildcard handles UUID)
# - Level 5: AGENT (exact match agent role)
# - Level 6: LLM (wildcard matches any model)
# - Level 6: Tool (exact match tool name)
#
# 2. Wildcard Handling:
# - Crew_<UUID>.kickoff -> Crew***.kickoff (auto-handled by evaluate_trajectory.py)
# - LLM: * -> matches any model name (e.g., gpt-5-chat-latest, deepseek-reasoner)
# - AGENT names must match completely (including full role name)
#
# 3. Exact Match Requirements:
# - SPAN names: "sql_assistant_workflow", "crew_execution", "generate_sql",
# "check_compliance", "interpret_results"
# - Chain names: "Crew***.kickoff" (wildcard match)
# - Agent names: "Agent: Expert SQL Query Generator",
# "Agent: Senior SQL Code Reviewer",
# "Agent: Data Security and Compliance Auditor",
# "Agent: Business Intelligence Analyst"
# (exact match role field in each agents.yaml)
# - LLM names: "LLM: *" (wildcard matches any model)
# - Tool names: exact match MCP tool names (get_database_schema, list_tables,
# get_table_sample, get_column_stats, validate_sql_syntax,
# check_table_exists, run_sql_query, count_rows)
#
# 4. Evaluation Metric Meanings:
# - Exact Match: Requires identical trajectory (including LLM and tool call counts)
# - In-order Match: Allows extra calls, but core steps must appear in order
# - Any-order Match: Only requires all necessary steps present (ignores order)
# - Precision: Proportion of correct steps in predicted trajectory
# - Recall: Proportion of reference steps covered
# - Single-tool Use: Detects core tool usage
# - unique_path_ratio: Path diversity (unique complete trajectories / sample count)
# - path_entropy: Path entropy (Shannon entropy based on trajectory frequency, normalized to 0-1)
#
# 5. Run Command:
# cd SQLAssistant-MCP
# python3 evaluate_trajectory-Filter_Tools.py --config reference_trajectory.yaml
#
# 6. Design Notes:
# - This reference trajectory represents ideal execution path (no retry, no error)
# - 3 main stages execute sequentially: SQL Generation -> Compliance Check -> Result Interpretation
# - Stage 1 (SQL Generation): Generator uses tools to explore schema + Reviewer validates syntax
# - Stage 2 (Compliance Check): Auditor checks security, must pass
# - Stage 3 (Result Interpretation): BI Analyst uses run_sql_query to execute and interpret
# - In-order Match and Recall metrics are more suitable for evaluating actual performance
# - Reference trajectory only defines core required steps, allows extra tool calls and LLM reasoning
#
# 7. Differences from Actual Trajectories:
# - Actual trajectories may contain business logic retries (compliance check failure triggers SQL regeneration)
# - Actual trajectories may contain orchestrator-level retries (exception errors trigger workflow retry)
# - Generator may use multiple tools to explore database (get_database_schema, list_tables, etc.)
# - Reviewer may call validate_sql_syntax multiple times for syntax validation
# - Auditor may use get_database_schema to verify table and column existence
# - BI Analyst may use count_rows to verify result count
# - Reasoning models (e.g., DeepSeek-R1) may include many extra LLM thinking calls
# - Some models may skip certain tool calls and generate results directly
# - These differences don't represent errors, but different model execution strategies
#
# 8. MCP Version Features:
# - All tools provided via MCP server using SSE protocol
# - Tools obtained from server via MCPServerAdapter
# - Contains multi-level SPAN structure (orchestrator + crew_execution + 3 stage SPANs)
# - 3 specialized Crews collaborate to complete SQL query task
# - Each Crew has clear responsibilities and available tool sets
# - SQLGenerationCrew: 2 Agents, generate and review SQL
# - ComplianceCheckerCrew: 1 Agent, check security and compliance
# - ResultInterpreterCrew: 1 Agent, execute query and generate business insights
# - Tool categories: exploration tools (get_database_schema, list_tables, get_table_sample, etc.),
# validation tools (validate_sql_syntax, check_table_exists),
# execution tools (run_sql_query, count_rows)
#
# 9. Business Logic Notes:
# - Compliance check is critical: only if compliance passes will query execute
# - If compliance fails, SQL is regenerated (max 3 attempts)
# - If all attempts fail, workflow ends without executing query
# - interpret_results stage only appears after compliance passes
# - Therefore, some failed trajectories may lack interpret_results stage