File size: 16,528 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 | # Full reference trajectory configuration - BookWriter-A2A
#
# Version: ideal trajectory derived from the 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:
# 1. Three main stages are executed sequentially (orchestrator.py):
# - OutlineGenerator: generate the book outline (2 agents: Researcher + Outliner)
# - WriteBookChapterCrew: concurrently write multiple chapters (2 agents per chapter: Researcher + Writer)
# - ReviewBookCrew: review the complete book (1 agent: Editor)
#
# 2. A2A-specific characteristics:
# - The orchestrator calls three independent A2A servers via HTTP/JSON-RPC
# - Each server runs a Crew and uses MCP tools
# - Extra SPAN layers are added: a2a_call_* and *_server_execution
# - Chapter writing is executed in concurrent batches (batch_size=4)
#
# 3. Tool usage analysis:
# - OutlineGenerator:
# - Researcher: bocha_websearch_tool, extract_keywords
# - Outliner: no tools (pure reasoning)
# - WriteBookChapterCrew (per chapter):
# - Researcher: bocha_websearch_tool, extract_keywords
# - Writer: count_words, analyze_chapter_quality, validate_markdown_structure
# - ReviewBookCrew:
# - Editor: count_book_words, analyze_book_quality, validate_book_markdown, extract_book_keywords
#
# 4. SPAN hierarchy (A2A version):
# - book_writing_orchestrator (top-level, orchestrator.py line 691)
# └─ crew_execution (includes retry logic, orchestrator.py line 724)
# ├─ generate_outline (orchestrator.py line 285)
# │ └─ a2a_call_outline_generator (orchestrator.py line 184)
# │ └─ outline_crew_server_execution (A2A server side)
# ├─ write_chapters (orchestrator.py line 416)
# │ └─ [repeat the following pattern per chapter 3-5 times]
# │ └─ a2a_call_chapter_writer_* (per chapter, orchestrator.py line 184)
# │ └─ chapter_writer_server_execution (A2A server side)
# └─ review_book (orchestrator.py line 472)
# └─ a2a_call_book_reviewer (orchestrator.py line 184)
# └─ book_reviewer_server_execution (A2A server side)
# Project name
project_name: "BookWriter-A2A"
# Trajectory extraction types
extract_types:
- "SPAN" # Multi-layer SPAN structure (including the A2A call layer)
- "Chain" # kickoff chain for each Crew
- "Agent" # agent nodes within each Crew
- "LLM" # LLM calls
- "Tool" # MCP tool calls
# Repeatable pattern configuration (for handling varying chapter counts)
# Format: {"start": start-step index (0-based), "end": end-step index, "min": min repeats, "max": max repeats}
# Reference indices: 0-14 Outline+write_chapters, 15-31 single-chapter pattern (full), 32+ Review
repeatable_patterns:
- start: 15 # SPAN: a2a_call_chapter_writer_* (step 1 of the single-chapter pattern, including SPAN layers)
end: 31 # LLM: * (last step of the single-chapter pattern, after validate_markdown_structure)
min: 3 # At least 3 chapters (business requirement)
max: 5 # At most 5 chapters
name: "chapter_writing_pattern" # Pattern name (for debugging)
# ============================================================================
# Reference Trajectory (Ground Truth) - Based on Code Design
# ============================================================================
#
# Graph view (ideal execution path; the single-chapter pattern repeats 3-5 times):
#
# [SPAN] book_writing_orchestrator
# └─ [SPAN] crew_execution
# ├─ [SPAN] generate_outline
# │ └─ [SPAN] a2a_call_outline_generator
# │ └─ [SPAN] outline_crew_server_execution
# │ └─ [Chain] Crew***.kickoff
# │ ├─ [Agent] Expert Research Agent for Book Outline Planning
# │ │ ├─ [LLM] *
# │ │ ├─ [Tool] bocha_websearch_tool
# │ │ ├─ [LLM] *
# │ │ ├─ [Tool] extract_keywords
# │ │ └─ [LLM] *
# │ └─ [Agent] Strategic Book Structure Architect
# │ └─ [LLM] *
# ├─ [SPAN] write_chapters
# │ └─ [repeat the following pattern per chapter 3-5 times]
# │ └─ [SPAN] a2a_call_chapter_writer_*
# │ └─ [SPAN] chapter_writer_server_execution
# │ └─ [Chain] Crew***.kickoff
# │ ├─ [Agent] Specialized Chapter Research Agent
# │ │ ├─ [LLM] *
# │ │ ├─ [Tool] bocha_websearch_tool
# │ │ ├─ [LLM] *
# │ │ ├─ [Tool] extract_keywords
# │ │ └─ [LLM] *
# │ └─ [Agent] Professional Chapter Content Writer
# │ ├─ [LLM] *
# │ ├─ [Tool] count_words
# │ ├─ [LLM] *
# │ ├─ [Tool] analyze_chapter_quality
# │ ├─ [LLM] *
# │ ├─ [Tool] validate_markdown_structure
# │ └─ [LLM] *
# └─ [SPAN] review_book
# └─ [SPAN] a2a_call_book_reviewer
# └─ [SPAN] book_reviewer_server_execution
# └─ [Chain] Crew***.kickoff
# └─ [Agent] Senior Book Editor and Quality Assurance Specialist
# ├─ [LLM] *
# ├─ [Tool] count_book_words
# ├─ [LLM] *
# ├─ [Tool] analyze_book_quality
# ├─ [LLM] *
# ├─ [Tool] validate_book_markdown
# ├─ [LLM] *
# ├─ [Tool] extract_book_keywords
# └─ [LLM] *
# Design rationale:
# - orchestrator.py: executes three main stages sequentially and calls servers via the A2A protocol
# - OutlineGenerator has 2 agents (Researcher + Outliner)
# - WriteBookChapterCrew has 2 agents per chapter (Researcher + Writer)
# - ReviewBookCrew has 1 agent (Editor)
# - Agent roles are defined in each crew's config/agents.yaml
# - Tools are provided via MCPServerAdapter
# - The number of chapters is generated from the outline (typically 3-5)
# Ideal-trajectory notes:
# - Top-level SPAN: book_writing_orchestrator
# - Second-level SPAN: crew_execution (contains retry logic)
# - Three child SPANs execute in order: generate_outline → write_chapters → review_book
# - Each stage includes an A2A call layer (a2a_call_*) and a server execution layer (*_server_execution)
# - Outline stage: Researcher uses 2 tools; Outliner uses pure reasoning
# - Chapter stage: per chapter, Researcher uses 2 tools; Writer uses 3 tools
# - Review stage: Editor uses 4 tools for whole-book quality checks
# - This reference represents an ideal path (no retries, no redundant steps), using 4 chapters as the baseline
# Notes:
# - "LLM: *" means any LLM model (wildcard)
# - Agent names must match the role field in agents.yaml exactly
# - Tool names must match the tool names exposed by the MCP server
# - The actual chapter count may be 3-5, which affects exact_match but not in_order_match
# - Some tool calls may be skipped or repeated depending on agent decisions
# ============================================================================
reference_trajectory:
# ===== Top-level SPAN =====
- "SPAN: book_writing_orchestrator"
# ===== Second-level SPAN (includes retry logic) =====
- "SPAN: crew_execution"
# ===== Stage 1: Generate Outline =====
- "SPAN: generate_outline"
- "SPAN: a2a_call_outline_generator"
- "SPAN: outline_crew_server_execution"
- "Chain: Crew***.kickoff"
# Agent 1: Researcher
- "Agent: Expert Research Agent for Book Outline Planning"
- "LLM: *" # Decide the research strategy
- "Tool: bocha_websearch_tool" # Web search for topics
- "LLM: *" # Process search results
- "Tool: extract_keywords" # Extract keywords
- "LLM: *" # Summarize research findings
# Agent 2: Outliner
- "Agent: Strategic Book Structure Architect"
- "LLM: *" # Generate the book outline
# ===== Stage 2: Write Chapters (at least 1 chapter; typically 3-5) =====
- "SPAN: write_chapters"
# Standard per-chapter pattern (appears at least once; repeats 3-5 times)
- "SPAN: a2a_call_chapter_writer_*"
- "SPAN: chapter_writer_server_execution"
- "Chain: Crew***.kickoff"
- "Agent: Specialized Chapter Research Agent"
- "LLM: *"
- "Tool: bocha_websearch_tool"
- "LLM: *"
- "Tool: extract_keywords"
- "LLM: *"
- "Agent: Professional Chapter Content Writer"
- "LLM: *"
- "Tool: count_words"
- "LLM: *"
- "Tool: analyze_chapter_quality"
- "LLM: *"
- "Tool: validate_markdown_structure"
- "LLM: *"
# ===== Stage 3: Review Book =====
- "SPAN: review_book"
- "SPAN: a2a_call_book_reviewer"
- "SPAN: book_reviewer_server_execution"
- "Chain: Crew***.kickoff"
- "Agent: Senior Book Editor and Quality Assurance Specialist"
- "LLM: *" # Start reviewing
- "Tool: count_book_words" # Count words
- "LLM: *" # Analyze word count
- "Tool: analyze_book_quality" # Quality analysis
- "LLM: *" # Assess quality
- "Tool: validate_book_markdown" # Format validation
- "LLM: *" # Check formatting
- "Tool: extract_book_keywords" # Extract keywords
- "LLM: *" # Generate review report
# Target tool list (for the single-tool use metric)
# This list includes all required tools
target_tools:
# Outline generation stage
- "Tool: bocha_websearch_tool"
- "Tool: extract_keywords"
# Chapter Writing stage (used per chapter)
- "Tool: count_words"
- "Tool: analyze_chapter_quality"
- "Tool: validate_markdown_structure"
# Book Review stage
- "Tool: count_book_words"
- "Tool: analyze_book_quality"
- "Tool: validate_book_markdown"
- "Tool: extract_book_keywords"
# ============================================================================
# Dynamic tool arrangement configuration
# ============================================================================
# Define permutable tool groups for certain agents to generate different reference trajectories
# The evaluation will try all possible permutations and choose the one with the highest match score
#
# Rationale:
# - Chapter Writer's 3 validation tools (count_words, analyze_chapter_quality, validate_markdown_structure)
# depend only on the chapter draft and have no inter-dependencies, so they can run in any order.
# - Book Editor's 4 analysis tools (count_book_words, analyze_book_quality, validate_book_markdown, extract_book_keywords)
# depend only on book files and are independent, so they can run in any order.
#
# Number of permutations:
# - Chapter Writer: 3! = 6 permutations
# - Book Editor: 4! = 24 permutations
#
# Evaluation strategy:
# - For each sample, generate all permuted reference trajectories
# - Compute a match score (exact_match * 3 + in_order_match * 2 + any_order_match * 1)
# - Choose the highest-scoring permutation as the sample's reference trajectory
# - This fairly evaluates models that use different tool invocation orders
permutable_tool_groups:
# Chapter Writer validation tools can be in any order
# These 3 tools are used under "Agent: Professional Chapter Content Writer"
chapter_writer_validation_tools:
- "Tool: count_words"
- "Tool: analyze_chapter_quality"
- "Tool: validate_markdown_structure"
# Book Editor analysis tools can be in any order
# These 4 tools are used under "Agent: Senior Book Editor and Quality Assurance Specialist"
book_editor_analysis_tools:
- "Tool: count_book_words"
- "Tool: analyze_book_quality"
- "Tool: validate_book_markdown"
- "Tool: extract_book_keywords"
# 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
# ============================================================================
#
# 1. Trajectory hierarchy (A2A version):
# - Level 1: SPAN (book_writing_orchestrator)
# - Level 2: SPAN (crew_execution)
# - Level 3: SPAN (generate_outline, write_chapters, review_book)
# - Level 4: SPAN (a2a_call_*: A2A call layer for each stage)
# - Level 5: SPAN (*_server_execution: server-side execution layer)
# - Level 6: Chain (Crew***.kickoff; UUID is wildcarded)
# - Level 7: AGENT (agent role must match exactly)
# - Level 8: LLM (wildcard match any model)
# - Level 8: Tool (tool name must match exactly)
#
# 2. Differences between the A2A version and the MCP version:
# - The A2A version adds two extra SPAN layers: a2a_call_* and *_server_execution
# - These SPANs represent the HTTP communication between the orchestrator and A2A servers
# - Tool invocation is the same, but wrapped inside the server execution layer
# - In execution_path.md, SPAN names may include chapter titles (e.g., a2a_call_chapter_writer_(chapter_title))
#
# 3. Wildcard handling:
# - Crew_<UUID>.kickoff -> Crew***.kickoff (handled automatically by evaluate_trajectory.py)
# - a2a_call_chapter_writer_* -> matches any chapter title
# - LLM: * -> matches any model name (e.g., gpt-5-chat-latest, deepseek-reasoner)
# - Agent names must match fully (including prefixes/suffixes)
#
# 4. Exact match requirements:
# - Orchestrator-layer SPANs: "book_writing_orchestrator", "crew_execution", "generate_outline", "write_chapters", "review_book"
# - A2A call-layer SPANs: "a2a_call_outline_generator", "a2a_call_chapter_writer_*", "a2a_call_book_reviewer" (chapter writer uses wildcard)
# - Server-layer SPANs: "outline_crew_server_execution", "chapter_writer_server_execution", "book_reviewer_server_execution"
# - Chain: "Crew***.kickoff" (wildcard)
# - Agents: names must match the role fields in agents.yaml exactly (including full names and formatting)
# - LLM: "LLM: *" (wildcard match any model)
# - Tools: must match MCP server tool names exactly
# - Actual chapter count may be 3-5; this affects exact_match but not in_order_match
# - Some tool calls may be skipped or repeated depending on agent decisions
#
# 5. Metric meanings:
# - Exact Match: trajectories must be identical (including LLM call counts; single-chapter pattern is repeatable)
# - In-order Match: extra calls are 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 that are covered
# - Single-tool Use: checks whether all required tools are used
# - unique_path_ratio: path diversity (unique complete trajectories / sample count)
# - path_entropy: Shannon entropy of trajectory frequencies, normalized to 0-1
#
# 6. Example command:
# python3 evaluate_trajectory.py --config reference_trajectory.yaml
#
# 7. Design notes:
# - This reference represents an ideal execution path (single-chapter pattern matches 3-5 chapters)
# - Three main stages execute in order: Outline → Chapters → Review
# - In-order Match and Recall are often more informative for real-world behavior
#
# 8. Differences from real trajectories:
# - The reference defines a single-chapter pattern; real runs repeat it 3-5 times (depending on outline chapter count)
# - Real trajectories may contain extra LLM calls (planning, reasoning, summarization)
# - Some models may call tools multiple times (retries or extra checks)
# - Some models may skip certain tool calls and still produce results
# - These differences reflect strategy choices and do not necessarily indicate errors
#
# 9. A2A-specific notes:
# - The orchestrator calls three independent A2A servers via HTTP/JSON-RPC
# - Each A2A server runs a Crew and uses MCP tools internally
# - Extra SPAN layers are added to trace A2A communication and server-side execution
# - Tool categories: search (bocha_websearch_tool), analysis (extract_keywords),
# quality checks (count_words, analyze_*_quality), and format validation (validate_*)
# - Chapter writing is executed in concurrent batches; each chapter has an independent trajectory
# - Compared to the MCP version, the A2A version has deeper span nesting but the same core logic
|