-
Notifications
You must be signed in to change notification settings - Fork 119
Description
Bug Report: Context Tree Formatting & Data Duplication
1. Issue Description
The aworld library's context tree visualization (🌳 CONTEXT TREE) exhibits two primary issues:
- Information Redundancy: For root tasks, the "Requested Input" (
[R]) and "Original Input" ([O]) are typically identical, resulting in the same content being printed twice side-by-side. - Layout Corruption: When task inputs contain newlines (
\n), the tree's visual structure (indentation and borders) breaks. The library fails to "flatten" multiline input, causing subsequent lines to lose their hierarchical prefixes and bleed outside the log borders.
2. Root Cause Analysis
A. Redundant Concatenation logic
In build_context_tree(), the description for a node is hardcoded to show both the current task input and the original user input without a deduplication check.
- File:
apps/api/libs/aworld/aworld/core/context/amni/utils/context_tree_utils.py - Related Code:
context_desc = f"[T]{context_id}: [R]{formatted_task_content} : [O]{origin_user_input}"
B. Lack of Newline Sanitization
The format_task_content utility does not handle newlines within the content. When these are present, they are passed as literal \n characters into the tree string.
- File:
apps/api/libs/aworld/aworld/core/context/amni/utils/context_tree_utils.py
C. Heuristic Failure in Indentation Parsing
The prompt logger attempts to draw borders around the tree by splitting the string into lines. It looks for specific markers (├─, 📍, └─) to calculate indentation. If a line is part of a multiline input (and thus has no marker), it defaults to zero indentation.
- File:
apps/api/libs/aworld/aworld/core/context/amni/logs/prompt_log.py - Function:
_log_context_tree
3. Reproduction Steps
- Initialize a task with a multiline input (e.g., using a structured prompt template).
- Trigger an agent execution that logs the
🌳 CONTEXT TREE. - Observe the
server.logoutput.
Current Output (Broken):
│ Context Tree (from root to current): │
│ ├─ [T]task_abc: [R]Topic: AI │
Identity: Student : [O]Topic: AI │
Identity: Student │
4. Proposed Solution
Fix 1: Flatten content in context_tree_utils.py
Modify format_task_content to replace newlines with a separator (like a space or |) to ensure each node occupies exactly one line in the visualization.
def format_task_content(task_content) -> str:
# ... existing logic ...
res = str(task_content)
return res.replace('\n', ' ') # FlatteningFix 2: Conditional Labeling in context_tree_utils.py
Only append the : [O]{origin_user_input} suffix if the content differs from formatted_task_content.
Fix 3: Robust Logging in prompt_log.py
Improve the _log_context_tree logic to handle lines that do not start with tree markers by inheriting the indentation of the previous line.
Reported by: Antigravity (AI Pair Programmer)
Date: 2026-02-04