Skip to content

feat(cortado): add multi-turn intermediate SQL execution, Set Match d… - #582

Open
erinlimbogoogle wants to merge 2 commits into
mainfrom
erin-multiturn-eval
Open

feat(cortado): add multi-turn intermediate SQL execution, Set Match d…#582
erinlimbogoogle wants to merge 2 commits into
mainfrom
erin-multiturn-eval

Conversation

@erinlimbogoogle

Copy link
Copy Markdown
Collaborator

feat(cortado): add multi-turn intermediate SQL execution, Set Match diffing, and tool telemetry

Overview & Summary

This PR resolves four critical quality and telemetry gaps in EvalBench's conversational evaluation pipeline (CortadoEvaluator / AgentScoreWork) when evaluating multi-turn sessions against external
conversational data agents (e.g., Macchiato / QueryData via GrpcProxyModel):

  1. Unpack Crash on Stream Completion: Supports flexible 4-tuple and 5-tuple returns from orchestrator.process() in eval_service.py to prevent ValueError crashes.
  2. Intermediate SQL Preservation & Live BigQuery Diffing: Eliminates turn query overwriting by executing both Golden SQL and Generated SQL per turn against BigQuery, evaluating exact row-set
    equivalence with SetMatcher, and preserving the full sequence in turn_history.
  3. Dual Rollup Scoring Metrics: Introduces set_match_all_turns (strict end-to-end trajectory accuracy), set_match_mean (average turn accuracy), and turn-indexed sub-metrics (set_match_turn_N) in
    AgentScoreWork to prevent final-turn masking.
  4. Tool Telemetry Fidelity: Propagates the proto other map across GrpcProxyModel and EvalCortadoRequest, extracting tool invocations (dataplex_search, query_data_tool, execute_sql_tool, etc.) into
    accumulated_tools.

Key Changes

1. Orchestrator Stream Unpacking (eval_service.py)

• Dynamically unpacks orchestrator.process() whether it returns a 4-tuple or 5-tuple (job_id, run_time, results_tf, scores_tf, multi_trial_scores_tf).

2. Telemetry & Proto Metadata Propagation (grpc_proxy.py, cortadoinput.py)

• GrpcProxyModel.generate() extracts inbound_response.other and merges it into eval_output.other.
• EvalCortadoRequest retains self.other = {}, unpacks proto.other in init_from_proto(), and serializes self.other in to_proto().

3. Multi-Turn SQL Execution & Set Matching (cortadoevaluator.py)

• Structured & Plan Extraction: Implemented extract_golden_sql_for_turn() with O(1) priority lookup for native turns schemas and regex fallback for legacy conversation_plan strings.
• Tool Extraction: Added extract_tools_and_skills_from_turn() to parse action logs from macchiato_debug_info and compact tool_telemetry payloads.
• Live DB Execution: Added thread-safe BigQuery client caching (_get_db()) and executed both golden and candidate SQLs on every turn.
• Granular turn_history: Records per-turn prompts, agent responses, SQL queries, database execution results, errors, Set Match scores, and tool lists.

4. Dual Rollup Scoring Pipeline (agentscorework.py)

Replaced hardcoded empty strings and "skipped" with real execution results and SQL queries.
Automatically records:
• set_match_all_turns (100.0 if all turns with SQL passed, else 0.0)
• set_match_mean (average Set Match accuracy across SQL turns)
• set_match_turn_1, set_match_turn_2, ... in scoring_results for context-length degradation analysis.

5. Unit Test Suite (cortadoorchestrator_test.py)

Added unit tests covering:
• Golden SQL extraction (structured turns + plan regex).
• Telemetry extraction from macchiato_debug_info.
• Proto other round-trip serialization.
• Multi-turn simulated user execution loop with mock BigQuery execution and Set Match scoring.
• Rollup metrics population in AgentScoreWork.

@erinlimbogoogle
erinlimbogoogle marked this pull request as ready for review August 26, 2026 22:23
pycheck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant