| # Full reference trajectory configuration - BookWriter-H_A2A project | |
| # | |
| # Version: ideal trajectory derived from code design (applies to all models) | |
| # Principle: include only steps explicitly required by the code design; do not rely on test statistics | |
| # | |
| # Code design analysis (A2A_mix characteristic: mixing three AI frameworks): | |
| # 1. The orchestrator calls three independent servers via the A2A protocol (orchestrator.py): | |
| # - Outline Generator Server: AutoGen framework, 2 agents (researcher + outliner) | |
| # - Chapter Writer Server: CrewAI framework, 2 agents (researcher + writer) | |
| # - Book Reviewer Server: LangGraph framework, StateGraph + ToolNode | |
| # | |
| # 2. Tool usage analysis (tool naming differences across frameworks): | |
| # - Server 1 (AutoGen): execute_tool bocha_websearch_tool, execute_tool extract_keywords (execute_tool prefix) | |
| # - Server 2 (CrewAI): bocha_websearch_tool._use, extract_keywords._use, count_words._use, analyze_chapter_quality._use, validate_markdown_structure._use (._use suffix) | |
| # - Server 3 (LangGraph): count_book_words, analyze_book_quality, validate_book_markdown, extract_book_keywords (no prefix/suffix) | |
| # | |
| # 3. Execution flow (A2A_mix architecture, three frameworks combined): | |
| # - The orchestrator creates the top-level SPAN: book_writing_orchestrator | |
| # - The orchestrator creates the crew_execution SPAN containing 3 stages | |
| # - Each stage has 3 levels of nested SPANs: | |
| # * orchestrator method layer: generate_outline / write_chapters / review_book | |
| # * HTTP call layer: a2a_call_outline_generator / a2a_call_chapter_writer_* / a2a_call_book_reviewer | |
| # * server execution layer: outline_generator_autogen_execution / chapter_writer_server_execution / book_reviewer_server_execution | |
| # - Server 1 (AutoGen): AGENT(invoke_agent researcher) → LLM → Tool(execute_tool) → LLM → AGENT(invoke_agent outliner) → LLM | |
| # - Server 2 (CrewAI): Chain(Crew***.kickoff) → AGENT(researcher) → LLM+Tool → AGENT(writer) → LLM+Tool | |
| # - Server 3 (LangGraph): Chain(LangGraph) → AGENT(agent) → LLM → Chain(tools) → Tool → AGENT(agent) → LLM → Chain(format_output) | |
| # | |
| # 4. SPAN hierarchy (A2A_mix-specific multi-framework nesting): | |
| # - book_writing_orchestrator (top-level, orchestrator.py line 691) | |
| # └─ crew_execution (contains 3 stages, orchestrator.py line 724) | |
| # ├─ generate_outline (orchestrator.py line 285) | |
| # │ └─ a2a_call_outline_generator (orchestrator.py line 184) | |
| # │ └─ outline_generator_autogen_execution (AutoGen execution) | |
| # │ └─ AGENT: invoke_agent researcher / invoke_agent outliner | |
| # ├─ write_chapters (orchestrator.py line 416) | |
| # │ └─ a2a_call_chapter_writer_* (per chapter, orchestrator.py line 184) | |
| # │ └─ chapter_writer_server_execution (CrewAI execution) | |
| # │ └─ Chain: Crew***.kickoff | |
| # │ └─ AGENT: Specialized Chapter Research Agent / Professional Chapter Content Writer | |
| # └─ review_book (orchestrator.py line 472) | |
| # └─ a2a_call_book_reviewer (orchestrator.py line 184) | |
| # └─ book_reviewer_server_execution (LangGraph execution) | |
| # └─ Chain: LangGraph | |
| # └─ AGENT: agent | |
| # Project name | |
| project_name: "BookWriter-H_A2A" | |
| # Trajectory extraction types | |
| extract_types: | |
| - "SPAN" # Multi-level SPAN structure (including the A2A call layer) | |
| - "Chain" # LangGraph chains and CrewAI crew kickoff chains | |
| - "AGENT" # Agents from all frameworks | |
| - "LLM" # LLM calls | |
| - "Tool" # Tool calls (note naming differences across frameworks) | |
| # Repeatable pattern configuration (used to handle varying chapter counts) | |
| # Format: {"start": start step index (0-based), "end": end step index, "min": min repeats, "max": max repeats} | |
| # Reference trajectory indices: | |
| # 0-12: outline stage (12 steps) + write_chapters SPAN | |
| # 13-29: single-chapter pattern (17 steps, repeatable 3-5 times) | |
| # 30+: review stage (31 steps) | |
| repeatable_patterns: | |
| # | |
| # Design basis (A2A_mix characteristic - mixing three AI frameworks): | |
| # - orchestrator.py: sequentially executes 3 main stages and calls servers via the A2A protocol | |
| # - Server 1: outline_generator_autogen.py, 2 agents (researcher + outliner) | |
| # - Server 2: chapter_writer_crewai.py, 2 agents per chapter (researcher + writer) | |
| # - Server 3: review_book_langgraph.py, LangGraph StateGraph + ToolNode | |
| # - Tool naming differences: AutoGen uses an execute_tool prefix; CrewAI uses a ._use suffix; LangGraph has no prefix/suffix | |
| # - Chapter count is generated from the outline, typically 3-5 chapters | |
| # | |
| # Ideal trajectory notes (A2A_mix architecture - mixing three frameworks): | |
| # - Top-level SPAN: book_writing_orchestrator (created by orchestrator) | |
| # - Second-level SPAN: crew_execution (contains retry logic) | |
| # - Three stages executed in order: generate_outline → write_chapters → review_book | |
| # - Outline stage (AutoGen): 2 agents + 4 LLM calls + 2 tool calls | |
| # - Chapter stage (CrewAI): per chapter 2 agents + 8 LLM calls + 5 tool calls (single-chapter pattern repeated 3-5 times) | |
| # - Review stage (LangGraph): 5 agent loops + 5 LLM calls + 8 chain nodes + 4 tool calls | |
| # - Single-chapter pattern: 2 SPANs + 1 Chain + 2 agents + 8 LLM calls + 5 tool calls (repeated under write_chapters) | |
| # - This trajectory represents the ideal execution path with no retries or redundancy (70 steps assuming 4 chapters) | |
| # | |
| # Dynamic reference trajectory design (enhanced): | |
| # 1. Dynamic matching of chapter count (3-5 chapters) | |
| # 2. Dynamic matching of AutoGen Outline (researcher) LLM/Tool patterns: | |
| # - Compact: LLM → Tool1 → Tool2 → LLM (adjacent tools) | |
| # - Interleaved: LLM → Tool1 → LLM → Tool2 → LLM (one LLM between tools) | |
| # Rule: must start and end with LLM; between the two tools there can be at most one LLM | |
| # 3. Dynamic matching of LangGraph Review (tools) batch execution patterns: | |
| # - 7 possible groupings: [1,1,1,1], [2,1,1], [1,2,1], [1,1,2], [3,1], [1,3], [4] | |
| # During evaluation, the script enumerates all combinations (chapter count × AutoGen pattern × LangGraph grouping) | |
| # and selects the variant with the best exact_match / in_order_match / any_order_match scores as the sample reference. | |
| # | |
| # Notes: | |
| # - "LLM: *" means any LLM model (wildcard match) | |
| # - Agent names are matched exactly (note AutoGen's invoke_agent prefix) | |
| # - Tool names are matched exactly (note prefix/suffix differences across frameworks) | |
| # - Actual chapter count may be 3-5, which affects exact_match but not in-order match | |
| # - AutoGen and LangGraph dynamic patterns produce multiple reference variants; the evaluator selects the best match | |
| # - Some tool calls may be skipped or repeated depending on agent decisions and framework behavior | |
| # ============================================================================ | |
| reference_trajectory: | |
| # ===== Top-level SPAN ===== | |
| - "SPAN: book_writing_orchestrator" | |
| # ===== Second-level SPAN (includes retry logic) ===== | |
| - "SPAN: crew_execution" | |
| # ===== Stage 1: Generate Outline (AutoGen framework) ===== | |
| - "SPAN: generate_outline" | |
| - "SPAN: a2a_call_outline_generator" | |
| - "SPAN: outline_generator_autogen_execution" | |
| # Agent 1: Researcher (AutoGen framework, note the invoke_agent prefix) | |
| - "AGENT: invoke_agent researcher" | |
| - "LLM: *" # decide research strategy | |
| - "Tool: execute_tool bocha_websearch_tool" # AutoGen tool (execute_tool prefix) | |
| - "Tool: execute_tool extract_keywords" # AutoGen tool (execute_tool prefix) | |
| - "LLM: *" # consolidate findings | |
| # Agent 2: Outliner (AutoGen framework, note the invoke_agent prefix) | |
| - "AGENT: invoke_agent outliner" | |
| - "LLM: *" # generate the book outline | |
| # ===== Stage 2: Write Chapters (CrewAI framework, at least 1 chapter, typically 3-5) ===== | |
| - "SPAN: write_chapters" | |
| # Standard per-chapter pattern (appears at least once; repeatable 3-5 times) | |
| - "SPAN: a2a_call_chapter_writer_*" | |
| - "SPAN: chapter_writer_server_execution" | |
| - "Chain: Crew***.kickoff" # CrewAI framework (UUID wildcard) | |
| # Agent 1: Chapter Researcher (CrewAI framework) | |
| - "AGENT: Specialized Chapter Research Agent" | |
| - "LLM: *" | |
| - "Tool: bocha_websearch_tool._use" # CrewAI tool (._use suffix) | |
| - "LLM: *" | |
| - "Tool: extract_keywords._use" # CrewAI tool (._use suffix) | |
| - "LLM: *" | |
| # Agent 2: Chapter Writer (CrewAI framework) | |
| - "AGENT: Professional Chapter Content Writer" | |
| - "LLM: *" | |
| - "Tool: count_words._use" # CrewAI tool (._use suffix) | |
| - "LLM: *" | |
| - "Tool: analyze_chapter_quality._use" # CrewAI tool (._use suffix) | |
| - "LLM: *" | |
| - "Tool: validate_markdown_structure._use" # CrewAI tool (._use suffix) | |
| - "LLM: *" | |
| # ===== Stage 3: Review Book (LangGraph framework) ===== | |
| - "SPAN: review_book" | |
| - "SPAN: a2a_call_book_reviewer" | |
| - "SPAN: book_reviewer_server_execution" | |
| - "Chain: LangGraph" # LangGraph main chain | |
| # LangGraph loop 1 - call count_book_words | |
| - "AGENT: agent" | |
| - "LLM: *" | |
| - "Chain: _should_continue" | |
| - "Chain: tools" | |
| - "Tool: count_book_words" # LangGraph tool (no prefix/suffix) | |
| # LangGraph loop 2 - call analyze_book_quality | |
| - "AGENT: agent" | |
| - "LLM: *" | |
| - "Chain: _should_continue" | |
| - "Chain: tools" | |
| - "Tool: analyze_book_quality" # LangGraph tool (no prefix/suffix) | |
| # LangGraph loop 3 - call extract_book_keywords | |
| - "AGENT: agent" | |
| - "LLM: *" | |
| - "Chain: _should_continue" | |
| - "Chain: tools" | |
| - "Tool: extract_book_keywords" # LangGraph tool (no prefix/suffix) | |
| # LangGraph loop 4 - call validate_book_markdown | |
| - "AGENT: agent" | |
| - "LLM: *" | |
| - "Chain: _should_continue" | |
| - "Chain: tools" | |
| - "Tool: validate_book_markdown" # LangGraph tool (no prefix/suffix) | |
| # LangGraph loop 5 - generate final review report | |
| - "AGENT: agent" | |
| - "LLM: *" | |
| - "Chain: _should_continue" | |
| - "Chain: format_output" | |
| # Target tool list (used for the single-tool use metric) | |
| # Note: tool naming differs across frameworks | |
| target_tools: | |
| # Outline generation stage (AutoGen framework, execute_tool prefix) | |
| - "Tool: execute_tool bocha_websearch_tool" | |
| - "Tool: execute_tool extract_keywords" | |
| # Chapter writing stage (CrewAI framework, ._use suffix, used per chapter) | |
| - "Tool: bocha_websearch_tool._use" | |
| - "Tool: extract_keywords._use" | |
| - "Tool: count_words._use" | |
| - "Tool: analyze_chapter_quality._use" | |
| - "Tool: validate_markdown_structure._use" | |
| # Book review stage (LangGraph framework, no prefix/suffix; inside Chain: tools; not in the reference trajectory) | |
| - "Tool: count_book_words" | |
| - "Tool: analyze_book_quality" | |
| - "Tool: validate_book_markdown" | |
| - "Tool: extract_book_keywords" | |
| # ============================================================================ | |
| # Dynamic tool permutation configuration | |
| # ============================================================================ | |
| # Define permutable tool groups for certain agents to generate reference trajectories | |
| # with different tool orders. | |
| # During evaluation, the script tries all permutations and selects the best-matching | |
| # reference trajectory. | |
| # | |
| # Design basis (based on dependency analysis): | |
| # - The 3 validation tools for Chapter Writer (CrewAI) are independent and can run in any order | |
| # - The 4 analysis tools for Book Reviewer (LangGraph) are independent and can run in any order | |
| # | |
| # Special handling (A2A_mix architecture): | |
| # - CrewAI tools: simple permutation (tool + surrounding LLM) | |
| # - LangGraph tools: permute entire loop blocks (each block contains AGENT → LLM → Chain → Chain tools → Tool) | |
| # * Note: LangGraph already has grouping logic; this permutation applies after grouping | |
| # * The permutation unit is a "loop block", not an individual tool | |
| # | |
| # Number of permutations: | |
| # - Chapter Writer: 3! = 6 | |
| # - Book Reviewer: 4! = 24 | |
| # - Total: 6 × 24 = 144 (for each dynamically generated reference trajectory) | |
| # | |
| # Evaluation strategy: | |
| # - For each sample, apply existing dynamic logic first (chapter count, AutoGen pattern, LangGraph grouping) | |
| # - Then generate all possible tool permutations | |
| # - Compute a match score for each permutation (exact_match * 3 + in_order_match * 2 + any_order_match * 1) | |
| # - Select the permutation with the highest score as the final sample reference | |
| permutable_tool_groups: | |
| # Chapter Writer (CrewAI framework): validation tools can be executed in any order | |
| # These 3 tools are used under "AGENT: Professional Chapter Content Writer" | |
| # Note: CrewAI tools use the ._use suffix | |
| chapter_writer_validation_tools: | |
| - "Tool: count_words._use" | |
| - "Tool: analyze_chapter_quality._use" | |
| - "Tool: validate_markdown_structure._use" | |
| # Book Reviewer (LangGraph framework): analysis tools can be executed in any order | |
| # Note: LangGraph tool names have no prefix/suffix, but each tool is a complete loop block | |
| # During permutation, move the loop blocks as a whole (5 steps: AGENT → LLM → Chain → Chain tools → Tool) | |
| book_reviewer_analysis_tools: | |
| - "Tool: count_book_words" | |
| - "Tool: analyze_book_quality" | |
| - "Tool: extract_book_keywords" | |
| - "Tool: validate_book_markdown" | |
| # 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 - A2A_mix architecture (mixing three AI frameworks) | |
| # ============================================================================ | |
| # | |
| # 1. Trajectory hierarchy (A2A_mix multi-framework nesting): | |
| # - Level 1: SPAN (book_writing_orchestrator) - orchestrator top-level | |
| # - Level 2: SPAN (crew_execution) - orchestrator contains 3 stages | |
| # - Level 3: SPAN (generate_outline, write_chapters, review_book) - orchestrator method layer | |
| # - Level 4: SPAN (a2a_call_*) - HTTP call layer | |
| # - Level 5: SPAN (*_execution) - server execution layer | |
| # - Level 6-8: framework-specific structures | |
| # - Level 5: SPAN (*_execution) - server execution layer for each framework | |
| # - Level 6-8: framework-specific structures | |
| # * AutoGen: AGENT(invoke_agent xxx) → LLM → Tool(execute_tool xxx) → LLM | |
| # * CrewAI: Chain(Crew***.kickoff) → AGENT(xxx) → LLM → Tool(xxx._use) → LLM | |
| # * LangGraph: Chain(LangGraph) → AGENT(agent) → LLM → Chain → Tool → AGENT → LLM → Chain | |
| # | |
| # 2. Wildcard handling: | |
| # - Crew_<UUID>.kickoff -> Crew***.kickoff (handled by evaluate_trajectory.py; CrewAI only) | |
| # - a2a_call_chapter_writer_* -> match any chapter title (wildcard) | |
| # - LLM: * -> match any model name (e.g., gpt-5-chat-latest, deepseek-reasoner, gemini-2.5-flash) | |
| # | |
| # 3. Exact matching requirements (differences across the three frameworks): | |
| # - SPAN names: | |
| # * top-level: "book_writing_orchestrator", "crew_execution" | |
| # * orchestrator method layer: "generate_outline", "write_chapters", "review_book" | |
| # * HTTP call layer: "a2a_call_outline_generator", "a2a_call_chapter_writer_*", "a2a_call_book_reviewer" | |
| # * server execution layer: "outline_generator_autogen_execution", "chapter_writer_server_execution", "book_reviewer_server_execution" | |
| # - AGENT names: | |
| # * AutoGen: "invoke_agent researcher", "invoke_agent outliner" (with invoke_agent prefix) | |
| # * CrewAI: "Specialized Chapter Research Agent", "Professional Chapter Content Writer" (exact match to roles in config/agents.yaml) | |
| # * LangGraph: "agent" (generic name, may repeat) | |
| # - Tool names (naming differences across frameworks): | |
| # * AutoGen: "execute_tool bocha_websearch_tool", "execute_tool extract_keywords" (execute_tool prefix) | |
| # * CrewAI: "bocha_websearch_tool._use", "extract_keywords._use", "count_words._use", "analyze_chapter_quality._use", "validate_markdown_structure._use" (._use suffix) | |
| # * LangGraph: "count_book_words", "analyze_book_quality", "validate_book_markdown", "extract_book_keywords" (no prefix/suffix; inside Chain: tools) | |
| # - Chain names: | |
| # * AutoGen: (no Chain nodes) | |
| # * CrewAI: "Crew***.kickoff" (UUID wildcard) | |
| # * LangGraph: "LangGraph", "_should_continue", "tools", "format_output" | |
| # - LLM name: "LLM: *" (wildcard match to any model) | |
| # | |
| # 4. Dynamic reference trajectory selection (enhanced): | |
| # For each sample: | |
| # a) detect chapter count (3-5) | |
| # b) detect the actual LLM/Tool pattern of AutoGen Outline (researcher) | |
| # - Compact: LLM → Tool1 → Tool2 → LLM | |
| # - Interleaved: LLM → Tool1 → LLM → Tool2 → LLM | |
| # c) enumerate all possible LangGraph Review (tools) groupings (7) | |
| # d) enumerate all possible combinations: | |
| # - e.g., 4 chapters × 2 AutoGen patterns × 7 LangGraph patterns = 14 variants | |
| # e) compute exact_match, in_order_match, any_order_match for each variant | |
| # f) select the variant with the best scores as the final reference trajectory for the sample | |
| # | |
| # 5. Metric definitions: | |
| # - Exact Match: requires identical trajectories (including LLM call counts, but the single-chapter pattern is repeatable) | |
| # - In-order Match: allows extra calls, but core steps must appear in order | |
| # - Any-order Match: requires all mandatory steps regardless of order | |
| # - Precision: fraction of correct steps in the predicted trajectory | |
| # - Recall: fraction of reference steps covered by the predicted trajectory | |
| # - Single-tool Use: checks usage of all 12 required tools (note tool naming differences) | |
| # - 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) | |
| # - Note: chapter count (3-5) does not affect metrics because the single-chapter pattern is defined as repeatable | |
| # - Note: AutoGen and LangGraph dynamic patterns generate multiple reference variants; the evaluator selects the best match | |
| # | |
| # 6. Run command: | |
| # cd /Users/wzr/TOSEM-2025/RESULTS/RQ-Failure_Breakdown/BookWriter-H_A2A | |
| # python3 evaluate_trajectory-mix.py --config reference_trajectory.yaml | |
| # | |
| # 7. Design notes (A2A_mix architecture - mixing three AI frameworks): | |
| # - This reference trajectory represents the ideal execution path (defines a repeatable single-chapter pattern to match 3-5 chapters) | |
| # - The orchestrator calls 3 independent servers via the A2A protocol (HTTP/JSONRPC) | |
| # - Each A2A call has 3 nested SPAN layers (method layer + HTTP call layer + server execution layer) | |
| # - Stage 1 (AutoGen): 2 agents + 4 LLM calls + 2 tools (execute_tool) | |
| # - Stage 2 (CrewAI): per chapter 1 chain + 2 agents + 8 LLM calls + 5 tools (._use) | |
| # - Stage 3 (LangGraph): 1 chain + 2 agent loops + 2 LLM calls + 4 chain nodes (number of tools inside Chain: tools is not fixed) | |
| # - Single-chapter pattern: 2 SPANs + 1 chain + 2 agents + 8 LLM calls + 5 tools (repeats within write_chapters) | |
| # - In-order Match and Recall are typically more suitable for evaluating real performance | |
| # - Note: the reference defines a single-chapter pattern; in practice it repeats 3-5 times to avoid mismatches due to fixed chapter count | |
| # | |
| # 8. Differences from actual trajectories (mixed-framework behavior): | |
| # - AutoGen: some models may not call tools (e.g., GPT-5 outputs directly), or may call tools a different number of times | |
| # - CrewAI: may call the same tool multiple times (retries or quality improvements), or skip certain tools | |
| # - LangGraph: the number and order of tools inside Chain: tools is flexible (1-4 tools in parallel) and is not part of trajectory evaluation | |
| # - Actual trajectories may include more LLM calls (thinking, planning, execution, summarization), especially for reasoning models | |
| # - Some models (e.g., Gemini) may skip certain tool calls and generate results directly | |
| # - These differences do not necessarily indicate errors; they reflect different execution strategies and framework characteristics | |
| # - The repeatable single-chapter pattern ensures in_order_match can be evaluated correctly regardless of chapter count | |
| # - AutoGen dynamic pattern matching helps adapt to different tool-calling behaviors | |
| # | |
| # 9. A2A_mix architecture characteristics (three frameworks mixed): | |
| # - Agent-to-agent communication uses HTTP/JSONRPC | |
| # - Each A2A server runs independently and uses a different AI framework | |
| # - Server 1: AutoGen (RoundRobinGroupChat + MCP tools) | |
| # - Server 2: CrewAI (Crew + Agent + Task + MCPServerAdapter) | |
| # - Server 3: LangGraph (StateGraph + ToolNode + conditional edges) | |
| # - The SPAN hierarchy is deeper than the single-framework A2A version (3 nested SPAN layers) | |
| # - Tracing code in orchestrator.py creates the multi-layer SPAN structure | |
| # - Each server returns results to the orchestrator after completion | |
| # - Supports distributed deployment and independent scaling | |
| # - Demonstrates collaboration across multiple frameworks | |
| # | |
| # 10. Known model behavior differences (across frameworks): | |
| # - AutoGen framework: | |
| # * GPT-5/Gemini: may not call tools (generate outline directly) | |
| # * DeepSeek-V3-1/R1: typically calls 2 tools | |
| # * Qwen3-235b: stable behavior, typically calls tools | |
| # - CrewAI framework: | |
| # * All models: usually at least 1 search + 1 writing quality check | |
| # * GPT-5: may call quality tools multiple times | |
| # * DeepSeek-R1: may skip some quality tools | |
| # * Gemini: may skip search tools and generate content directly | |
| # - LangGraph framework: | |
| # * All models: typically 1-4 tools in parallel inside Chain: tools | |
| # * GPT-5: usually calls all 4 tools | |
| # * DeepSeek-V3-1/R1: may call 2-3 tools | |
| # * Gemini: may call only 1-2 tools | |
| # - These differences reflect different planning/execution strategies and framework characteristics | |