File size: 23,268 Bytes
8c10cf2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
# Full reference trajectory configuration - SocialMediaManager-A2A project
#
# Version: ideal trajectory derived from the code design (applies to all models)
# Principle: include only steps explicitly required by the design, not based on test statistics
#
# Code-design analysis:
# 1. Execution flow (orchestrator.py):
#    - The Orchestrator manages the overall workflow with two retry layers:
#      (a) Orchestrator-level retries: for unexpected errors (up to 3 attempts, MAX_CREW_RETRIES=2)
#      (b) Business-logic retries: for validation failures (up to 6 attempts, max_retries=5)
#    - Ideal flow (no retries):
#      Step 1: Topic Analysis (TopicAnalyzerCrew)
#      Step 2-4: Content Generation with Feedback Loop
#        - Generate the X post (ShakespeareGeneratorCrew)
#        - Validate the X post (PostReviewCrew)
#        - If valid=True, end the loop; otherwise retry
#      Step 5: Save Results
#
# 2. Agent structure of the three Crews:
#    - TopicAnalyzerCrew (topic_analyzer/topic_analyzer_crew.py):
#      - Agent: Topic Analysis Expert
#        Tools: keyword_extractor, topic_complexity_analyzer
#    - ShakespeareGeneratorCrew (content_generator/shakespeare_generator_crew.py):
#      - Agent: Shakespearean Bard
#        Tools: keyword_extractor, character_counter_tool, emoji_detector_tool,
#              post_structure_validator, shakespearean_style_detector, tone_analyzer
#    - PostReviewCrew (post_reviewer/post_review_crew.py):
#      - Agent: X Post Verifier
#        Tools: character_counter_tool, emoji_detector_tool, post_structure_validator,
#              shakespearean_style_detector, tone_analyzer
#
# 3. SPAN hierarchy:
#    - shakespeare_x_post_orchestrator (top-level, orchestrator.py line 347)
#      └─ crew_execution (contains retry logic, orchestrator.py line 362-393)
#         ├─ topic_analysis (topic analysis, orchestrator.py line 114-141)
#         └─ content_generation_loop (content generation & review loop, orchestrator.py line 143-250)
#            includes multiple iterations:
#            - ShakespeareGeneratorCrew.kickoff (generate X post)
#            - PostReviewCrew.kickoff (validate X post)
#            - If valid=True then stop; otherwise continue
#
# 4. MCP tools (tools/mcp_server.py):
#    - Character count: character_counter_tool (validate 200-280 chars)
#    - Emoji detection: emoji_detector_tool (ensure no emoji)
#    - Structure validation: post_structure_validator (validate 1-3-1 structure, 5 lines)
#    - Style detection: shakespearean_style_detector (detect Shakespearean style elements)
#    - Tone analysis: tone_analyzer (ensure satire and humor)
#    - Keyword extraction: keyword_extractor (extract key topic concepts)
#    - Complexity analysis: topic_complexity_analyzer (estimate topic complexity)

# Project name
project_name: "SocialMediaManager-A2A"

# Trajectory node types to extract
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
# SocialMediaManager-A2A has a self-evaluation loop (but the ideal trajectory needs only 1 iteration)
repeatable_patterns: []

# ============================================================================
# Reference trajectory (Ground Truth) - derived from code design
# ============================================================================
#
# Graph view (ideal execution path: no retries, no errors, first generation passes validation):
#
# [SPAN] shakespeare_x_post_orchestrator
# └─ [SPAN] crew_execution
#    ├─ [SPAN] analyze_topic
#    │  └─ [SPAN] a2a_call_topic_analyzer
#    │     └─ [SPAN] topic_analyzer_server_execution
#    │        └─ [Chain] Crew***.kickoff
#    │           └─ [AGENT] Topic Analysis Expert
#    │              ├─ [LLM] * (understand the topic)
#    │              ├─ [Tool] keyword_extractor (extract keywords)
#    │              ├─ [LLM] * (analyze keywords)
#    │              ├─ [Tool] topic_complexity_analyzer (analyze complexity)
#    │              └─ [LLM] * (produce the topic analysis report)
#    └─ [SPAN] content_generation_loop
#       ├─ [SPAN] a2a_call_content_generator
#       │  └─ [SPAN] content_generator_server_execution
#       │     └─ [Chain] Crew***.kickoff (ShakespeareGeneratorCrew - 1st generation)
#       │        └─ [AGENT] Shakespearean Bard
#       │           ├─ [LLM] * (plan generation strategy)
#       │           ├─ [Tool] keyword_extractor (understand topic keywords)
#       │           ├─ [LLM] * (draft the initial X post)
#       │           ├─ [Tool] character_counter_tool (check character count)
#       │           ├─ [LLM] * (adjust character count)
#       │           ├─ [Tool] emoji_detector_tool (check emoji)
#       │           ├─ [LLM] * (confirm no emoji)
#       │           ├─ [Tool] post_structure_validator (validate 1-3-1 structure)
#       │           ├─ [LLM] * (adjust structure)
#       │           ├─ [Tool] shakespearean_style_detector (check style)
#       │           ├─ [LLM] * (strengthen style)
#       │           ├─ [Tool] tone_analyzer (check tone)
#       │           └─ [LLM] * (final polish and output)
#       └─ [SPAN] a2a_call_post_reviewer
#          └─ [SPAN] post_reviewer_server_execution
#             └─ [Chain] Crew***.kickoff (PostReviewCrew - 1st validation)
#                └─ [AGENT] X Post Verifier
#                   ├─ [LLM] * (read and perform an initial assessment)
#                   ├─ [Tool] character_counter_tool (validate character count)
#                   ├─ [LLM] * (record character-count check)
#                   ├─ [Tool] emoji_detector_tool (validate no emoji)
#                   ├─ [LLM] * (record emoji check)
#                   ├─ [Tool] post_structure_validator (validate 1-3-1 structure)
#                   ├─ [LLM] * (record structure check)
#                   ├─ [Tool] shakespearean_style_detector (validate style)
#                   ├─ [LLM] * (record style check)
#                   ├─ [Tool] tone_analyzer (validate tone)
#                   └─ [LLM] * (overall decision; output valid=True)
#
# Design rationale:
# - orchestrator.py executes analyze_topic → content_generation_loop in order (via A2A communication)
# - TopicAnalyzerCrew has 1 Agent using 2 tools to analyze the topic
# - ShakespeareGeneratorCrew has 1 Agent using multiple tools for generation and self-validation
# - PostReviewCrew has 1 Agent using multiple tools for comprehensive validation
# - Ideal case: first generation passes validation (valid=True), no retries
# - Agent roles are defined in each crew's config/agents.yaml
# - Tasks are defined in each crew's config/tasks.yaml and explicitly require specific tools
# - A2A architecture: the orchestrator calls three independent agent servers via Agent2Agent
# - Each agent server runs its Crew via the CrewAI framework
#
# Ideal-trajectory notes:
# - Top-level SPAN: shakespeare_x_post_orchestrator
# - Second-level SPAN: crew_execution (contains two-layer retry logic)
# - Two child SPANs run in order: analyze_topic → content_generation_loop
# - analyze_topic stage: call the topic_analyzer server via A2A; Topic Analyst uses
#   keyword_extractor and topic_complexity_analyzer
# - content_generation_loop stage includes a self-evaluation loop:
#   - Iteration 1 (ideal case):
#     * ShakespeareGeneratorCrew generates the X post and self-validates using multiple tools
#     * PostReviewCrew validates the X post using all validation tools, returning valid=True
#   - No iterations 2-N needed (because the first one passes)
# - This trajectory represents an ideal execution path with no retries and no errors
#
# Notes:
# - "LLM: *" means any LLM model (wildcard match)
# - Agent names must exactly match the role fields in agents.yaml
# - Tool names must exactly match the tool names provided by each agent server
# - Both Generator and Verifier use multiple tools (as required by tasks.yaml)
# - Tool-call order may differ slightly depending on agent decisions
# - Some LLM calls may be merged or split, but core tool calls must exist
# ============================================================================

reference_trajectory:
  # ===== Top-level SPAN =====
  - "SPAN: shakespeare_x_post_orchestrator"

  # ===== Second-level SPAN (contains two-layer retry logic) =====
  - "SPAN: crew_execution"

  # ===== Stage 1: Analyze Topic (TopicAnalyzerCrew) =====
  - "SPAN: analyze_topic"
  - "SPAN: a2a_call_topic_analyzer"
  - "SPAN: topic_analyzer_server_execution"
  - "Chain: Crew***.kickoff"
  - "Agent: Topic Analysis Expert"
  - "LLM: *" # Initial understanding of the topic; plan analysis strategy
  - "Tool: keyword_extractor" # Required by tasks.yaml (no order requirement)
  - "LLM: *" # Analyze keyword extraction results
  - "Tool: topic_complexity_analyzer" # Required by tasks.yaml (no order requirement)
  - "LLM: *" # Synthesize analysis; produce topic insights

  # ===== Stage 2: Content Generation Loop (Self-Evaluation Loop) =====
  - "SPAN: content_generation_loop"

  # === Iteration 1: Content generation (ShakespeareGeneratorCrew) ===
  - "SPAN: a2a_call_content_generator"
  - "SPAN: content_generator_server_execution"
  - "Chain: Crew***.kickoff"
  - "Agent: Shakespearean Bard"
  - "LLM: *" # Understand the topic and topic_insights; plan generation strategy
  - "Tool: keyword_extractor" # MUST be first: tasks.yaml STEP 1 requires "First, use the keyword_extractor tool"
  - "LLM: *" # Draft the initial X post based on keywords
  # The following tools are used for validation as required by tasks.yaml (no order requirement):
  - "Tool: character_counter_tool" # Validate character count (200-280)
  - "LLM: *" # Adjust based on character-count check
  - "Tool: emoji_detector_tool" # Ensure no emoji
  - "LLM: *" # Confirm emoji check passes
  - "Tool: post_structure_validator" # Validate 1-3-1 structure (5 lines)
  - "LLM: *" # Adjust based on structure check
  - "Tool: shakespearean_style_detector" # Check Shakespearean style
  - "LLM: *" # Strengthen style elements
  - "Tool: tone_analyzer" # Validate satirical and humorous tone
  - "LLM: *" # Final polish and output X post

  # === Iteration 1: Content validation (PostReviewCrew) ===
  - "SPAN: a2a_call_post_reviewer"
  - "SPAN: post_reviewer_server_execution"
  - "Chain: Crew***.kickoff"
  - "Agent: X Post Verifier"
  - "LLM: *" # Read the X post and plan the validation strategy
  # The following 5 tools are all required by tasks.yaml (no order requirement):
  - "Tool: character_counter_tool" # Validate character count (200-280)
  - "LLM: *" # Analyze character-count check results
  - "Tool: emoji_detector_tool" # Validate no emoji
  - "LLM: *" # Analyze emoji check results
  - "Tool: post_structure_validator" # Validate 1-3-1 structure (5 lines)
  - "LLM: *" # Analyze structure check results
  - "Tool: shakespearean_style_detector" # Validate Shakespearean style
  - "LLM: *" # Analyze style check results
  - "Tool: tone_analyzer" # Validate satirical and humorous tone
  - "LLM: *" # Combine checks; output valid=True, feedback=""

# Target tool list (used for the single-tool use metric)
# Lists all tools filtered for each Agent in this config
target_tools:
  # Topic Analysis stage
  - "Tool: keyword_extractor"
  - "Tool: topic_complexity_analyzer"
  # Content Generation stage
  - "Tool: character_counter_tool"
  - "Tool: emoji_detector_tool"
  - "Tool: post_structure_validator"
  - "Tool: shakespearean_style_detector"
  - "Tool: tone_analyzer"
  # Post Review stage (shares tools with Generation; not duplicated here)

# ============================================================================
# Dynamic tool permutation configuration
# ============================================================================
# Define permutable tool groups for certain stages to generate reference trajectories
# with different tool orders. During evaluation, all permutations are tried and the
# best-matching one is selected as the reference.
#
# Notes:
# - Topic Analyst's two tools can be in any order (tasks.yaml does not specify order)
# - Shakespearean Bard's keyword_extractor must be first (explicitly required by tasks.yaml),
#   but the subsequent 5 validation tools can be in any order
# - X Post Verifier's 5 validation tools can be in any order (tasks.yaml does not specify order)
permutable_tool_groups:
  # Topic Analysis stage tools can be in any order
  topic_analysis_tools:
    - "Tool: keyword_extractor"
    - "Tool: topic_complexity_analyzer"

  # Shakespearean Bard validation tools can be in any order
  # Note: this excludes the first keyword_extractor (it must remain the first tool)
  shakespearean_bard_validation_tools:
    - "Tool: character_counter_tool"
    - "Tool: emoji_detector_tool"
    - "Tool: post_structure_validator"
    - "Tool: shakespearean_style_detector"
    - "Tool: tone_analyzer"

  # X Post Verifier validation tools can be in any order
  x_post_verifier_tools:
    - "Tool: character_counter_tool"
    - "Tool: emoji_detector_tool"
    - "Tool: post_structure_validator"
    - "Tool: shakespearean_style_detector"
    - "Tool: tone_analyzer"

# 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
# ============================================================================
#
# 1. Trajectory hierarchy:
#    - Level 1: SPAN (shakespeare_x_post_orchestrator)
#    - Level 2: SPAN (crew_execution)
#    - Level 3: SPAN (analyze_topic, content_generation_loop)
#    - Level 4: SPAN (a2a_call_topic_analyzer, a2a_call_content_generator, a2a_call_post_reviewer)
#    - Level 5: SPAN (topic_analyzer_server_execution, content_generator_server_execution, post_reviewer_server_execution)
#    - Level 6: Chain (Crew***.kickoff; UUID wildcard handling)
#    - Level 7: AGENT (exact match for agent role)
#    - Level 8: LLM (wildcard match for any model)
#    - Level 8: Tool (exact match for tool name)
#
# 2. Wildcard handling:
#    - Crew_<UUID>.kickoff -> Crew***.kickoff (handled automatically by evaluate_trajectory.py)
#    - LLM: * -> matches any model name (e.g., gpt-4o-mini, deepseek-reasoner, gemini-2.5-flash, etc.)
#    - Agent names must match in full (including the full role name)
#
# 3. Exact-match requirements:
#    - SPAN names: "shakespeare_x_post_orchestrator", "crew_execution",
#      "analyze_topic", "content_generation_loop",
#      "a2a_call_topic_analyzer", "a2a_call_content_generator", "a2a_call_post_reviewer",
#      "topic_analyzer_server_execution", "content_generator_server_execution", "post_reviewer_server_execution"
#    - Chain name: "Crew***.kickoff" (wildcard match)
#    - Agent names: "Agent: Topic Analysis Expert",
#      "Agent: Shakespearean Bard",
#      "Agent: X Post Verifier"
#      (exact match for the role field in agents.yaml)
#    - LLM name: "LLM: *" (wildcard match for any model)
#    - Tool names: exact match for tool names (keyword_extractor, topic_complexity_analyzer,
#      character_counter_tool, emoji_detector_tool, post_structure_validator,
#      shakespearean_style_detector, tone_analyzer)
#
# 4. Metric definitions:
#    - Exact Match: trajectories must be identical (including LLM-call counts and tool-call counts)
#    - In-order Match: extra calls allowed, but core steps must appear in order
#    - Any-order Match: all required steps must be present (order ignored)
#    - Precision: fraction of predicted steps that are correct
#    - Recall: fraction of reference steps covered by the prediction
#    - Single-tool Use: checks whether core tools are used
#    - unique_path_ratio: path diversity (number of unique full trajectories / number of samples)
#    - path_entropy: path entropy (Shannon entropy over trajectory frequencies, normalized to 0-1)
#
# 5. Run command:
#    cd /Users/wzr/TOSEM-2025/RESULTS/RQ-Failure_Breakdown/SocialMediaManager-A2A
#    python3 evaluate_trajectory.py --config reference_trajectory.yaml
#
# 6. Design notes:
#    - This reference trajectory represents an ideal execution path (no retries, no errors)
#    - Two main stages execute in order: Analyze Topic → Content Generation Loop
#    - Stage 1 (Analyze Topic): Topic Analyst uses 2 tools to analyze the topic
#    - Stage 2 (Content Generation Loop): includes a self-evaluation loop
#      * Shakespearean Bard generates the X post and self-validates with multiple tools
#      * X Post Verifier performs comprehensive validation using all validation tools
#      * Ideal case: first iteration returns valid=True with no retries
#    - In-order Match and Recall are often more suitable for evaluating real-world behavior
#    - The reference trajectory only defines core required steps; extra tool calls and LLM reasoning are allowed
#
# 7. Differences from actual trajectories:
#    - Actual trajectories may include business-logic retries (validation failure triggers regeneration)
#    - Actual trajectories may include orchestrator-level retries (exceptions trigger a full workflow retry)
#    - The Generator may use a different tool order (but should still use tools required by tasks.yaml)
#    - The Verifier may use a different tool order (but must use all 5 validation tools)
#    - Reasoning models (e.g., DeepSeek-R1) may include many additional LLM calls
#    - Some models (e.g., Gemini) may skip tool calls and generate results directly (not compliant)
#    - These differences are not always errors, but skipping required tools or failing validation is abnormal
#
# 8. A2A version characteristics:
#    - Uses an Agent2Agent (A2A) architecture; the orchestrator calls 3 independent agent servers via A2A
#    - Each agent server runs a CrewAI Crew with its own toolset
#    - Includes a multi-level SPAN structure (orchestrator + crew_execution + 2 stage SPANs + A2A comm SPAN + server_execution SPAN)
#    - Three specialized Crews collaborate to generate a Shakespeare-style X post
#    - Each Crew has clear responsibilities and an explicit toolset
#    - TopicAnalyzerCrew: 1 Agent analyzing the topic and extracting insights (via the topic_analyzer server)
#    - ShakespeareGeneratorCrew: 1 Agent generating and self-validating the X post (via the content_generator server)
#    - PostReviewCrew: 1 Agent comprehensively validating X post quality (via the post_reviewer server)
#    - Tool categories: analysis tools (keyword_extractor, topic_complexity_analyzer),
#      validation tools (character_counter_tool, emoji_detector_tool, post_structure_validator,
#      shakespearean_style_detector, tone_analyzer)
#
# 9. Business-logic notes:
#    - The self-evaluation loop is critical: generation must be followed by validation
#    - If validation fails (valid=False), regeneration happens with feedback (up to 6 attempts)
#    - If all attempts fail, the workflow ends and the failing X post is saved
#    - The ideal trajectory assumes the first generation passes validation (best case)
#    - The Generator should self-validate using all tools explicitly required by tools.yaml
#    - The Verifier must use all 5 validation tools for thorough validation
#    - Some actual trajectories may include multiple generate-validate loops (normal business-logic retries)
#
# 10. Tool usage requirements (based on tasks.yaml analysis):
#     - Topic Analyst (analyze_topic task):
#       * Explicit requirement: "Start by using the available analytical tools"
#       * Must use: keyword_extractor, topic_complexity_analyzer
#       * Ordering: none (tasks.yaml does not specify order)
#     - Shakespearean Bard (write_x_post task):
#       * Explicit requirement: "STEP 1 - REQUIRED: First, use the keyword_extractor tool"
#       * Explicit requirement: "IMPORTANT: Before finalizing, use the available tools to verify quality"
#       * Must use: keyword_extractor (must be the first tool)
#       * Should use: character_counter_tool, emoji_detector_tool, post_structure_validator,
#                   shakespearean_style_detector, tone_analyzer (quality validation)
#       * Ordering: keyword_extractor must be first; other validation tools have no order requirement
#     - X Post Verifier (verify_x_post task):
#       * Explicit requirement: "CRITICAL: You MUST use the following tools to perform thorough validation"
#       * Must use: character_counter_tool, emoji_detector_tool, post_structure_validator,
#                   shakespearean_style_detector, tone_analyzer (all 5)
#       * Requirement: "Base your validation decision on these tool results, not assumptions"
#       * Ordering: none (tasks.yaml does not specify order)
#
# 11. Tool-call ordering notes:
#     - **Scenarios with ordering requirements**:
#       * Shakespearean Bard's keyword_extractor must be the first tool
#         (tasks.yaml line 7-8: "STEP 1 - REQUIRED: First, use the keyword_extractor tool")
#     - **Scenarios without ordering requirements**:
#       * Topic Analyst's two tools (keyword_extractor, topic_complexity_analyzer) can be in any order
#       * Shakespearean Bard's 5 validation tools can be in any order (as long as after keyword_extractor)
#       * X Post Verifier's 5 validation tools can be in any order
#     - **Order in the reference trajectory**:
#       * The listed order reflects a common observed pattern
#       * Evaluation should allow flexibility in tool order (except Bard keyword_extractor must be first)
#       * The evaluation script should enforce the constraint that keyword_extractor must be first for the Bard
#
# 12. Dynamic tool permutation optimization:
#     - **Design idea**: tool calls within each AGENT may appear in different orders
#     - **Mechanism**:
#       * permutable_tool_groups defines the tool groups that can be permuted
#       * the evaluation script generates all possible tool-order combinations (cartesian product)
#       * for each sample, it selects the permutation with the highest combined score from
#         exact_match, in_order_match, and any_order_match
#     - **Number of combinations**:
#       * topic_analysis_tools: 2! = 2 permutations
#       * shakespearean_bard_validation_tools: 5! = 120 permutations
#       * x_post_verifier_tools: 5! = 120 permutations
#       * total: 2 × 120 × 120 = 28,800 reference trajectories
#     - **Evaluation strategy**:
#       * dynamically select the best reference trajectory per test sample
#       * combined score = exact_match×3 + in_order_match×2 + any_order_match×1
#       * more fair across different models' tool-calling strategies
#     - **Notes**:
#       * the Bard's first keyword_extractor is not permuted (must remain first)
#       * permutations are only within the same AGENT and do not cross AGENT boundaries
#       * tool permutations do not change where/when LLM calls appear or how many there are