File size: 18,463 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
# Full reference trajectory configuration - LandingPageGenerator-H_A2A
#
# Version: an ideal trajectory derived from code design (applicable to all models)
# Principle: include only steps explicitly required by the design; do not rely on test statistics
#
# Design analysis (A2A_mix characteristic: mixing three AI frameworks):
# 1. The orchestrator calls three independent servers via the A2A protocol (orchestrator.py):
#    - Idea Expansion Server: LangGraph framework, uses bocha_websearch_tool for market research
#    - Template Selection Server: AutoGen framework, uses learn_landing_page_options to select a template
#    - Content Creation Server: CrewAI framework, uses read_file_content and write_file_with_content to generate HTML
#
# 2. Tool usage analysis (tool naming differs across frameworks):
#    - Server 1 (LangGraph): bocha_websearch_tool (no prefix/suffix)
#    - Server 2 (AutoGen): execute_tool learn_landing_page_options (execute_tool prefix)
#    - Server 3 (CrewAI): read_file_content._use, write_file_with_content._use (._use suffix)
#
# 3. Execution flow (A2A_mix architecture, mixed frameworks):
#    - The orchestrator creates the top-level SPAN: landing_page_generation-A2A_mix
#    - The orchestrator creates the crew_execution SPAN containing 3 A2A calls
#    - Each A2A call has 3 nested SPAN layers:
#      * orchestrator method layer: expand_idea / select_template / create_content
#      * HTTP call layer: a2a_call_*
#      * server execution layer: idea_expansion_server_execution / template_selection_autogen_execution / content_creation_server_execution
#    - Server 1 (LangGraph): Chain → AGENT → LLM → Chain(tools) → Tool → AGENT → LLM → Chain(format_output)
#    - Server 2 (AutoGen): AGENT(invoke_agent) → LLM → Tool(execute_tool) → LLM
#    - Server 3 (CrewAI): Chain(Crew***.kickoff) → AGENT → LLM/Tool interaction
#
# 4. SPAN hierarchy (A2A_mix multi-framework layering):
#    - landing_page_generation-A2A_mix (top-level, orchestrator.py line 451)
#      └─ crew_execution (contains 3 A2A calls, orchestrator.py line 482)
#         ├─ expand_idea (orchestrator.py line 267)
#         │  └─ a2a_call_idea_expansion (orchestrator.py line 172)
#         │     └─ idea_expansion_server_execution (LangGraph execution)
#         │        └─ Chain: LangGraph
#         │           └─ AGENT: agent (LangGraph agent node)
#         ├─ select_template (orchestrator.py line 305)
#         │  └─ a2a_call_template_selection (orchestrator.py line 172)
#         │     └─ template_selection_autogen_execution (AutoGen execution)
#         │        └─ AGENT: invoke_agent senior_react_engineer (AutoGen agent)
#         └─ create_content (orchestrator.py line 350)
#            └─ a2a_call_content_creation (orchestrator.py line 172)
#               └─ content_creation_server_execution (CrewAI execution)
#                  └─ Chain: Crew***.kickoff (CrewAI chain)
#                     └─ AGENT: Landing Page Content Generator

# Project name
project_name: "LandingPageGenerator-H_A2A"

# Trajectory extraction types
extract_types:
  - "SPAN" # Multi-layer SPAN structure
  - "Chain" # Crew kickoff chain
  - "AGENT" # Crew agent
  - "LLM" # LLM calls
  - "Tool" # MCP tool calls

# A2A_mix: enable AutoGen dynamic reference trajectory matching
enable_autogen_pattern_matching: true

# ============================================================================
# Reference Trajectory (Ground Truth) - Based on Code Design
# ============================================================================
#
# Graphical structure (ideal execution path, A2A_mix multi-framework architecture):
#
# [SPAN] landing_page_generation-A2A_mix
# └─ [SPAN] crew_execution
#    ├─ [SPAN] expand_idea
#    │  └─ [SPAN] a2a_call_idea_expansion
#    │     └─ [SPAN] idea_expansion_server_execution
#    │        └─ [Chain] LangGraph (LangGraph framework)
#    │           ├─ [AGENT] agent
#    │           │  ├─ [LLM] *
#    │           │  └─ [Chain] _should_continue
#    │           ├─ [Chain] tools (internal tool count is not fixed)
#    │           ├─ [AGENT] agent
#    │           │  ├─ [LLM] *
#    │           │  └─ [Chain] _should_continue
#    │           └─ [Chain] format_output
#    ├─ [SPAN] select_template
#    │  └─ [SPAN] a2a_call_template_selection
#    │     └─ [SPAN] template_selection_autogen_execution
#    │        └─ [AGENT] invoke_agent senior_react_engineer (AutoGen framework)
#    │           ├─ [LLM] *
#    │           ├─ [Tool] execute_tool learn_landing_page_options
#    │           └─ [LLM] *
#    └─ [SPAN] create_content
#       └─ [SPAN] a2a_call_content_creation
#          └─ [SPAN] content_creation_server_execution
#             └─ [Chain] Crew***.kickoff (CrewAI framework)
#                └─ [AGENT] Landing Page Content Generator
#                   ├─ [LLM] *
#                   ├─ [Tool] read_file_content._use
#                   ├─ [LLM] *
#                   ├─ [Tool] write_file_with_content._use
#                   └─ [LLM] *
#
# Rationale (A2A_mix):
# - orchestrator.py calls 3 independent servers via the A2A protocol over HTTP; each server uses a different framework
# - each A2A call has 3 nested SPAN layers (orchestrator method layer + HTTP call layer + server execution layer)
# - Server 1 (LangGraph): idea_expansion_langgraph.py, Chain: LangGraph, AGENT: agent
# - Server 2 (AutoGen): template_selection_autogen.py, AGENT: invoke_agent senior_react_engineer
# - Server 3 (CrewAI): content_creation_crew.py, Chain: Crew***.kickoff, AGENT: Landing Page Content Generator
# - tool naming differences: LangGraph has no prefix/suffix, AutoGen has an execute_tool prefix, CrewAI has a ._use suffix
#
# Ideal trajectory notes (A2A_mix):
# - Top-level SPAN: landing_page_generation-A2A_mix (created by the orchestrator)
# - Second-level SPAN: crew_execution (contains 3 A2A calls)
# - Each A2A call has an additional 3-layer SPAN nesting (orchestrator method → HTTP call → server execution)
# - Server 1 (LangGraph): Chain → multiple AGENT loops → Chain(tools; internal tools are not fixed) → Chain(format_output)
# - Server 2 (AutoGen): AGENT → LLM → Tool → LLM, at least 1 Tool (some models may skip Tool calls)
# - Server 3 (CrewAI): Chain → AGENT → LLM+Tool interaction, at least 1 read + 1 write
# - This trajectory represents an ideal execution path with no retries and no redundant steps
#
# Notes:
# - "LLM: *" matches any LLM model name (wildcard)
# - Agent name matching is exact: LangGraph "agent", AutoGen "invoke_agent senior_react_engineer", CrewAI "Landing Page Content Generator"
# - Tool name matching is exact: bocha_websearch_tool, execute_tool learn_landing_page_options, read_file_content._use, write_file_with_content._use
# - [Crew Created] and [Task Created] are excluded (CrewAI-only markers without business meaning)
# - Real executions may contain additional LLM and Tool calls; this is expected
# - LangGraph tool calls inside Chain: tools are not part of trajectory evaluation
# - LangGraph may loop over AGENT multiple times; AutoGen may skip Tool calls (some models return directly)
# - A2A_mix uses deeper SPAN nesting than the MCP version and mixes three different AI frameworks
# ============================================================================

reference_trajectory:
  # ===== Top-level SPAN (created by the orchestrator) =====
  - "SPAN: landing_page_generation-A2A_mix"

  # ===== Second-level SPAN (contains 3 A2A calls) =====
  - "SPAN: crew_execution"

  # ===== A2A Call 1: Idea Expansion (LangGraph framework) =====
  - "SPAN: expand_idea" # orchestrator method
  - "SPAN: a2a_call_idea_expansion" # HTTP call layer
  - "SPAN: idea_expansion_server_execution" # LangGraph server execution layer
  - "Chain: LangGraph" # LangGraph main chain
  - "AGENT: agent" # LangGraph agent node (1st)
  - "LLM: *" # decide to call tools
  - "Chain: _should_continue" # LangGraph condition check
  - "Chain: tools" # LangGraph tool chain (internal tool count is not fixed; not part of evaluation)
  - "AGENT: agent" # LangGraph agent node (2nd)
  - "LLM: *" # generate expanded idea
  - "Chain: _should_continue" # LangGraph condition check
  - "Chain: format_output" # LangGraph output formatting

  # ===== A2A Call 2: Template Selection (AutoGen framework) =====
  - "SPAN: select_template" # orchestrator method
  - "SPAN: a2a_call_template_selection" # HTTP call layer
  - "SPAN: template_selection_autogen_execution" # AutoGen server execution layer
  - "AGENT: invoke_agent senior_react_engineer" # AutoGen agent (with invoke_agent prefix)
  - "LLM: *" # decide to call tools
  - "Tool: execute_tool learn_landing_page_options" # learn available templates (execute_tool prefix)
  - "LLM: *" # select template

  # ===== A2A Call 3: Content Creation (CrewAI framework) =====
  - "SPAN: create_content" # orchestrator method
  - "SPAN: a2a_call_content_creation" # HTTP call layer
  - "SPAN: content_creation_server_execution" # CrewAI server execution layer
  - "Chain: Crew***.kickoff" # CrewAI chain (UUID wildcard)
  - "AGENT: Landing Page Content Generator" # CrewAI agent
  - "LLM: *" # decide to read template
  - "Tool: read_file_content._use" # read template file (._use suffix)
  - "LLM: *" # generate HTML content
  - "Tool: write_file_with_content._use" # write HTML file (._use suffix)
  - "LLM: *" # final confirmation

# ============================================================================
# AutoGen dynamic reference trajectory design notes
# ============================================================================
#
# Dynamic matching for the LLM/Tool call pattern in the AutoGen phase (Template Selection):
#
# Rule: the phase must start and end with an LLM; between adjacent tools there can be 0 or 1 LLM
#
# For 1 tool (learn_landing_page_options), the possible pattern is:
#   - LLM → Tool → LLM (the only pattern)
#
# During evaluation, all possible patterns are enumerated and scored:
#   score = exact_match * 3 + in_order_match * 2 + any_order_match * 1
#
# The highest-scoring pattern is used as the final reference for that sample.
# This adapts to different model execution strategies and improves evaluation accuracy.
# ============================================================================

# Target tool list (for the single-tool use metric)
# Note: tool naming differs across frameworks (LangGraph has no prefix/suffix, AutoGen uses execute_tool prefix, CrewAI uses ._use suffix)
# Note: bocha_websearch_tool is inside Chain: tools and not in the reference trajectory, but we still track its usage
target_tools:
  - "Tool: bocha_websearch_tool" # LangGraph framework (inside Chain: tools)
  - "Tool: execute_tool learn_landing_page_options" # AutoGen framework
  - "Tool: read_file_content._use" # CrewAI framework
  - "Tool: write_file_with_content._use" # CrewAI framework

# 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 notes - specific to the A2A_mix architecture (mixing three AI frameworks)
# ============================================================================
#
# 1. Trajectory hierarchy (A2A_mix multi-framework mixing):
#    - Level 1: SPAN (landing_page_generation-A2A_mix) - orchestrator top-level
#    - Level 2: SPAN (crew_execution) - orchestrator contains 3 A2A calls
#    - Level 3: SPAN (expand_idea, select_template, create_content) - orchestrator method layer
#    - Level 4: SPAN (a2a_call_*) - HTTP call layer
#    - Level 5: SPAN (*_server_execution / *_autogen_execution) - per-server execution layer
#    - Level 6-8: framework-specific structure
#      * LangGraph: Chain(LangGraph) → AGENT(agent) → LLM → Chain → Tool → AGENT → LLM → Chain
#      * AutoGen: AGENT(invoke_agent xxx) → LLM → Tool(execute_tool xxx) → LLM
#      * CrewAI: Chain(Crew***.kickoff) → AGENT(xxx) → LLM → Tool(xxx._use) → LLM
#
# 2. Wildcard handling:
#    - Crew_<UUID>.kickoff -> Crew***.kickoff (handled by the evaluator; CrewAI only)
#    - LLM: * -> matches any model name (e.g., gpt-5-chat-latest, deepseek-reasoner, gemini-2.5-flash)
#
# 3. Exact-match requirements (differences across frameworks):
#    - SPAN names:
#      * Top-level: "landing_page_generation-A2A_mix", "crew_execution"
#      * Orchestrator method layer: "expand_idea", "select_template", "create_content"
#      * HTTP call layer: "a2a_call_idea_expansion", "a2a_call_template_selection", "a2a_call_content_creation"
#      * Server execution layer: "idea_expansion_server_execution", "template_selection_autogen_execution", "content_creation_server_execution"
#    - Chain names:
#      * LangGraph: "LangGraph", "_should_continue", "tools", "format_output"
#      * AutoGen: (no Chain nodes)
#      * CrewAI: "Crew***.kickoff" (wildcard matches the UUID part)
#    - AGENT names:
#      * LangGraph: "agent" (generic name; may appear multiple times)
#      * AutoGen: "invoke_agent senior_react_engineer" (with invoke_agent prefix)
#      * CrewAI: "Landing Page Content Generator" (exact match to role in config/agents.yaml)
#    - Tool names (naming differs across frameworks):
#      * LangGraph: "bocha_websearch_tool" (no prefix/suffix; inside Chain: tools; excluded from trajectory evaluation)
#      * AutoGen: "execute_tool learn_landing_page_options" (execute_tool prefix)
#      * CrewAI: "read_file_content._use", "write_file_with_content._use" (._use suffix)
#    - Event markers: "Crew Created", "Task Created" (CrewAI-only markers)
#    - LLM name: "LLM: *" (wildcard matches any model)
#
# 4. Metric meanings:
#    - Exact Match: trajectories must be identical (including LLM call count and all SPAN/Chain/AGENT levels)
#    - In-order Match: extra calls are allowed, but required steps must appear in order
#    - Any-order Match: contains all required steps (order ignored)
#    - Precision: fraction of predicted steps that are correct
#    - Recall: fraction of reference steps covered by the predicted trajectory
#    - Single-tool Use: checks usage of all 4 required tools (note framework-specific tool naming)
#    - unique_path_ratio: path diversity (unique full trajectories / samples)
#    - path_entropy: path entropy (Shannon entropy over path frequencies, normalized to 0-1)
#
# 5. Example command:
#    cd /Users/wzr/TOSEM-2025/RESULTS/RQ-Failure_Breakdown/LandingPageGenerator-H_A2A
#    python3 evaluate_trajectory.py --config reference_trajectory.yaml
#
# 6. Design notes (A2A_mix architecture - mixing three AI frameworks):
#    - This reference trajectory represents an ideal execution path
#    - The orchestrator calls 3 independent servers via A2A (HTTP/JSONRPC)
#    - Each A2A call has 3 nested SPAN layers (method layer + HTTP call layer + server execution layer)
#    - Server 1 (LangGraph): Chain → 2 AGENT loops + 1 tools Chain + 4 Chain nodes, at least 2 LLM calls (tool count inside Chain: tools is not fixed)
#    - Server 2 (AutoGen): 1 AGENT + 2 LLM calls + 1 Tool (execute_tool), may skip Tool calls (some models return directly)
#    - Server 3 (CrewAI): Chain + AGENT + 3 LLM calls + 1 read + 1 write
#    - Total: 2 top-level SPANs + 3 method SPANs + 3 call SPANs + 3 server SPANs + 6 Chains + 4 AGENTs + 8 LLM calls + 3 tools (AutoGen+CrewAI)
#    - Trajectory length: 31 steps (excluding Tool nodes inside Chain: tools; LangGraph has more Chain nodes)
#    - In-order Match and Recall are usually more suitable for evaluating real performance
#    - Note: LangGraph may call bocha_websearch_tool 1-3 times inside Chain: tools; excluded from trajectory evaluation
#
# 7. Differences from real trajectories (mixed-framework characteristics):
#    - LangGraph:
#      * may loop over AGENT nodes multiple times
#      * tool calls inside Chain: tools are not fixed (1-3 bocha_websearch_tool calls) and do not affect trajectory evaluation
#      * tool calls may appear in parallel (@@@ marker)
#    - AutoGen: some models may not call tools (e.g., GPT-5 returns template name directly), or use a different number of LLM calls
#    - CrewAI: may read multiple files (CSS/JS/etc.) or write multiple times (retries)
#    - Real trajectories may include more LLM calls (thinking/planning/execution/summarization)
#    - Some models may not use tools (e.g., Gemini generates content directly without bocha_websearch_tool)
#    - These differences do not necessarily indicate errors; they reflect model strategies and framework behavior
#    - Exact Match may be low; focus on In-order Match and Recall
#
# 8. A2A_mix architecture characteristics (three-framework mixing):
#    - agent-to-agent communication via HTTP/JSONRPC
#    - each A2A server runs independently and uses a different AI framework
#    - Server 1: LangGraph (StateGraph + ToolNode + conditional edges)
#    - Server 2: AutoGen (AssistantAgent + MCP tools + ToolCallFormatFixer)
#    - Server 3: CrewAI (Crew + Agent + Task + MCPServerAdapter)
#    - SPAN nesting is deeper than the MCP monolithic version (3 more nested SPAN layers)
#    - tracing code in orchestrator.py creates the multi-layer SPAN structure
#    - each server returns results to the orchestrator after execution
#    - supports distributed deployment and independent scaling
#    - demonstrates cross-framework collaboration
#
# 9. Known model behavior differences (across frameworks):
#    - LangGraph framework:
#      * GPT-5: usually 1-2 tool calls
#      * DeepSeek-V3-1/R1: may make 3 parallel tool calls
#      * Gemini: may skip tool calls and generate content directly
#    - AutoGen framework:
#      * GPT-5: may skip tool calls (returns template name directly)
#      * DeepSeek: usually calls tools
#      * Gemini: unstable behavior; may or may not call tools
#    - CrewAI framework:
#      * all models: usually at least 1 read + 1 write
#      * GPT-5: may read multiple files and make multiple LLM calls
#      * DeepSeek-R1: may write twice (retry/correction)
#    - These differences reflect different planning/execution strategies and framework implementations