Practical web applications increasingly need agents that can interpret long conversations or documents. When inputs exceed the context window of large language models (LLMs), memory agents split the text into segments and retain past information in a bounded memory. Existing approaches cut inputs into flat token chunks, ignoring structure and hierarchy, which leads to three major issues: (1) fixed‑length segmentation can split fields of the same record, breaking their relationships; (2) segments lack hierarchical cues, making it hard to locate them within the overall structure; (3) successive memory updates may discard details of earlier sibling records, hampering later reasoning.\n\nTo overcome these limitations, we propose TreeAgent, a structure‑aware agent that leverages the input hierarchy for both segment processing and memory access. Specifically, it:\n- builds segments from complete subtrees or groups of adjacent sibling subtrees, preserving local structural relationships;\n- attaches structural paths to each segment so the agent can identify ancestors and hierarchical positions;\n- introduces residual memory links that connect low‑level child segments directly to high‑level parent segments, enabling information flow beyond sequential memory updates.\n\nWe provide a theoretical upper bound on the number of segments, guiding token‑budget selection to match the segment count of fixed‑length segmentation. Experiments with four representative memory agents on eight retrieval and aggregation tasks—using real‑world JSON, HTML, YAML, and JavaScript data ranging from 8K to 1M tokens—show that TreeAgent consistently improves average scores, achieving a 3.61% overall gain.\n\nReview: By incorporating hierarchy‑aware segmentation and residual memory links, TreeAgent mitigates information fragmentation in long hierarchical data, offering a practical avenue for extending LLM memory in real‑world applications.