Skip to content

improve TrajectorySummarizer: add type hints, detailed prompt templat…improve TrajectorySummarizer: type hints, paper §3.3 prompt template, and robust fallback#5

Open
KAnchor218 wants to merge 1 commit into
HiAgent2024:mainfrom
KAnchor218:add-summarize-module-v2

Conversation

@KAnchor218
Copy link
Copy Markdown

…e, and robust fallback

  • Add module-level docstring explaining the paper §3.3 context and call signature
  • Add full type annotations (List, Sequence, Tuple from typing)
  • Replace minimal prompt with the explicit §3.3 prompt template including trajectory/subgoal sections and output constraints
  • Extract _format_trajectory and _format_subgoal as dedicated static methods for cleaner separation of concerns
  • Add _last_observation fallback that scans reversed trajectory chunks, consistent with the summarization=False branch in cme_final.py
  • Extract first non-empty line from LLM output to enforce the single-line output requirement stated in the prompt instructions

…e, and robust fallback

- Add module-level docstring explaining the paper §3.3 context and call signature
- Add full type annotations (List, Sequence, Tuple from typing)
- Replace minimal prompt with the explicit §3.3 prompt template including
  trajectory/subgoal sections and output constraints
- Extract _format_trajectory and _format_subgoal as dedicated static methods
  for cleaner separation of concerns
- Add _last_observation fallback that scans reversed trajectory chunks,
  consistent with the summarization=False branch in cme_final.py
- Extract first non-empty line from LLM output to enforce the single-line
  output requirement stated in the prompt instructions
Copilot AI review requested due to automatic review settings April 20, 2026 03:15
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances TrajectorySummarizer to better mirror HiAgent paper §3.3 by expanding documentation, adding type hints, using a more explicit prompt template, and improving robustness of the summarization output/fallback behavior.

Changes:

  • Added module-level docstring describing paper context, call signature, and expected input shapes.
  • Replaced the minimal prompt with the paper §3.3-style prompt template and enforced single-line output by extracting the first non-empty line.
  • Refactored formatting and fallback behavior into _format_trajectory, _format_subgoal, and _last_observation helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +6 to +8
以及 cme_final.py 中对 TrajectorySummarizer 的调用(cme_final.py:160-182)复刻。

调用(来源:cme_final.py):
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

模块注释里引用的 cme_final.py 行号(“cme_final.py:160-182”)与当前仓库实际位置不一致,容易误导后续维护者。建议改为当前准确行号范围,或改成用函数名/搜索关键词引用而不是固定行号。

Suggested change
以及 cme_final.py 中对 TrajectorySummarizer 的调用cme_final.py:160-182复刻
调用来源cme_final.py):
以及 cme_final.py 中对 TrajectorySummarizer 的调用位置可搜索 `TrajectorySummarizer(`
`generate_summary(`复刻
调用来源cme_final.py 中相关调用逻辑可搜索 `TrajectorySummarizer(`):

Copilot uses AI. Check for mistakes.
会被填入 cme_final.py 中作为压缩后的 Observation。

LLM 接口签名(来源:agentboard/llm/openai_gpt.py:74 等):
llm_model.generate(system_message: str, prompt: str) -> Tuple[bool, str]
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里记录的 LLM 接口签名不准确:仓库内多个 generate() 实现失败时会返回 (False, None),因此返回类型应为 Tuple[bool, Optional[str]](或在文档中说明失败时 completion 可能为 None)。否则类型提示和实际行为不一致。

Suggested change
llm_model.generate(system_message: str, prompt: str) -> Tuple[bool, str]
llm_model.generate(system_message: str, prompt: str) -> Tuple[bool, Optional[str]]
其中失败时 completion 可能为 None

Copilot uses AI. Check for mistakes.
Comment on lines +100 to +104
summaries: List[str] = []
for trajectory, subgoal in zip(trajectories, subgoals):
if not trajectory:
summaries.append("Subgoal completed.")
continue
prompt = self._build_prompt(trajectory, subgoal)
success, summary = self.llm_model.generate(
"You are a helpful assistant that summarizes agent trajectories concisely.",
prompt,
formatted_trajectory = self._format_trajectory(trajectory)
subgoal_text = self._format_subgoal(subgoal)
prompt = _PROMPT_TEMPLATE.format(
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当前实现移除了空 trajectory 的显式处理;当 trajectory 为空或不包含 Observation 时,_last_observation() 会返回空字符串,最终会把空 Observation 写回历史(cme_final.py 会 new_history.append(..., ("Observation", summary)))。建议在 generate_summary 中对空/无 Observation 的情况返回一个非空占位文本(例如沿用旧实现的 "Subgoal completed."),避免下游出现空 observation。

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants