Skip to content

Feat: Add same-action deduplication to prevent repeated firing #228

Merged
yangbaofu007 merged 24 commits intomainfrom
feat-RulesNotAlwaysTrigger
Feb 14, 2026
Merged

Feat: Add same-action deduplication to prevent repeated firing #228
yangbaofu007 merged 24 commits intomainfrom
feat-RulesNotAlwaysTrigger

Conversation

@baabanana
Copy link
Collaborator

@baabanana baabanana commented Feb 7, 2026

问题

状态判断僵化:用户反馈:例如"如果我坐着/如果我睡醒了,就...”出现重复触发

目标

能够区别状态和动作持续状态中只触发一次。
”小孩在读书的时候,给我发通知-->在看书的期间只发一次通知”每动作一次就触发一次。
“我比个耶就给我发送一次通知-->每比一次耶就发送一次通知”

解决方法

  • 重构触发规则条件判断逻辑,新增 is_same_action 判断,解决同一事件被重复触发的问题
  • 引入 _last_happened_cache 内存缓存,保存每个摄像头/通道上次触发时的图像序列,用于与当前画面对比
  • 重写 LLM prompt,从简单的 yes/no JSON 输出改为数字编码(0/1/2),分别表示:未发生、新事件、同一事件
  • 更新 prompt_helper.py,构建 prompt 时附带上次触发的图像帧和时间戳,供 LLM 进行对比判断

修改内容

  • config/prompt_config.yaml: 重写 trigger_rule_condition prompt(中英文),增加 is_same_action 判断流程和输出格式;新增
    current_time_prefix、last_happened_frames_prefix、last_happened_time_prefix 等前缀配置

  • miloco_server/service/trigger_rule_runner.py:

    • 新增 _last_happened_cache 字典缓存上次触发的图像序列
    • 新增 _load_last_happened_img_seq() 和 _parse_llm_output() 方法
    • 重构 _check_trigger_condition() 中的 LLM 响应解析逻辑,从 JSON 解析改为数字解析(0/1/2)
    • 删除规则时自动清理对应缓存
  • miloco_server/utils/prompt_helper.py: build_trigger_rule_prompt() 新增 last_happened_img_seq 参数,构建包含历史帧和时间戳的完整 prompt

    The trigger rule system monitors camera feeds and executes actions when conditions are met. The current implementation has a deduplication issue: rules fire repeatedly while conditions remain satisfied, causing the same action to execute multiple times for a single continuous event.

Summary

  • Add is_same_action detection to prevent the same ongoing event from repeatedly triggering rule execution
  • Introduce _last_happened_cache to store the last triggered image sequence per camera/channel for comparison with current frames
  • Rewrite LLM prompt from simple yes/no JSON output to numeric encoding (0/1/2): not happened, new event, same event
  • Update prompt builder to include last triggered frames and timestamps for LLM comparison

Changes

  • config/prompt_config.yaml: Rewrite trigger_rule_condition prompt (Chinese & English) with is_same_action judgment flow and numeric output
    format; add current_time_prefix, last_happened_frames_prefix, last_happened_time_prefix prefix configs
  • miloco_server/service/trigger_rule_runner.py:
    • Add _last_happened_cache dict to cache last triggered image sequences
    • Add _load_last_happened_img_seq() and _parse_llm_output() methods
    • Refactor LLM response parsing in _check_trigger_condition() from JSON to numeric (0/1/2)
    • Auto-clean cache entries when a rule is removed
  • miloco_server/utils/prompt_helper.py: Add last_happened_img_seq parameter to build_trigger_rule_prompt(), building complete prompts with
    historical frames and timestamps

update prompts and prompts create method
update llm response and exclutable logic
@baabanana baabanana marked this pull request as ready for review February 7, 2026 14:04
…che loading and enhancing logging for LLM output and condition results.
…ptimize camera loading, and adjust logging levels.
…simplify its cleanup logic in `remove_trigger_rule`.
…ing for LLM proxy status and task completion.
…enhance trigger condition results, including a fix for sending state deletion.
…lls, improve LLM output parsing, and safely remove trigger rule states.
…s, and adjust trigger condition result and sending state updates.
…e processing and prompt building, and refine scheduled task execution flow.
…larity in trigger rule configuration and usage.
@yangbaofu007 yangbaofu007 merged commit d49f343 into main Feb 14, 2026
2 checks passed
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.

3 participants