feat(agent): add CompositeHook for composable lifecycle hooks

Introduce a CompositeHook that fans out lifecycle callbacks to an
ordered list of AgentHook instances with per-hook error isolation.
Extract the nested _LoopHook and _SubagentHook to module scope as
public LoopHook / SubagentHook so downstream users can subclass or
compose them.  Add `hooks` parameter to AgentLoop.__init__ for
registering custom hooks at construction time.

Closes #2603
This commit is contained in:
sontianye authored and Xubin Ren committed 2026-03-31 02:19:29 +08:00
1 parent 1814272583
commit f08de72f18
5 files changed
+508 -52

No files matched your search

+15 -2
View File
@@ -1,8 +1,21 @@
"""Agent core module."""
from nanobot.agent.context import ContextBuilder
from nanobot.agent.loop import AgentLoop
from nanobot.agent.hook import AgentHook, AgentHookContext, CompositeHook
from nanobot.agent.loop import AgentLoop, LoopHook
from nanobot.agent.memory import MemoryStore
from nanobot.agent.skills import SkillsLoader
from nanobot.agent.subagent import SubagentHook, SubagentManager
__all__ = ["AgentLoop", "ContextBuilder", "MemoryStore", "SkillsLoader"]
__all__ = [
"AgentHook",
"AgentHookContext",
"AgentLoop",
"CompositeHook",
"ContextBuilder",
"LoopHook",
"MemoryStore",
"SkillsLoader",
"SubagentHook",
"SubagentManager",
]