Skip to content

refactor(agent): extract turn hook assembly - #4848

Merged
Re-bin merged 3 commits into
mainfrom
codex/loop-hook-refactor
Jul 8, 2026
Merged

Re-bin merged 3 commits into
mainfrom
codex/loop-hook-refactor

Conversation

@chengyongru

Copy link
Copy Markdown
Collaborator

Summary

  • Move per-turn hook assembly out of AgentLoop._run_agent_loop into nanobot.agent.turn_hooks.
  • Keep AgentLoop responsible for turn orchestration while turn_hooks owns progress hook composition and ephemeral hook filtering.
  • Add focused tests for hook ordering and ephemeral hook behavior.

Verification

  • PYTHONPATH=. pytest tests/agent/test_turn_hooks.py tests/agent/test_hook_composite.py tests/agent/test_loop_direct_websocket_status.py -q
  • PYTHONPATH=. pytest tests/agent/test_loop_progress.py tests/agent/test_runner_hooks.py -q
  • PYTHONPATH=. pytest tests/test_nanobot_facade.py -q
  • ruff check nanobot/agent/loop.py nanobot/agent/turn_hooks.py tests/agent/test_turn_hooks.py

@chengyongru chengyongru added the priority: p2 Normal backlog: minor bug, enhancement, docs, cleanup, edge case, or unvalidated proposal. label Jul 8, 2026

@Re-bin Re-bin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. This keeps the hook refactor on the right side of the line: loop.py still owns turn flow, while the per-turn hook assembly moves into a focused helper with explicit context and ordering. The new factory path is isolated, ephemeral turns preserve the previous extra-hook behavior, and SelfTool blocks the new private hook factory state from runtime mutation.

Validated locally:

  • python -m pytest tests/agent/test_hook_composite.py tests/agent/test_turn_hooks.py -q
  • python -m ruff check nanobot/agent/hook.py nanobot/agent/turn_hooks.py nanobot/agent/loop.py nanobot/agent/tools/self.py tests/agent/test_hook_composite.py tests/agent/test_turn_hooks.py

GitHub Actions is green across the full matrix.

@Re-bin
Re-bin merged commit 8559458 into main Jul 8, 2026
5 checks passed
@Re-bin
Re-bin deleted the codex/loop-hook-refactor branch July 8, 2026 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: p2 Normal backlog: minor bug, enhancement, docs, cleanup, edge case, or unvalidated proposal. refactor valid

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants