Files
hermes-agent/tools/skill_provenance.py
T

38 lines
1.4 KiB
Python

"""Skill write-origin provenance: a ContextVar separating agent-sediment skill writes from foreground
user-directed writes. The curator only curates skills the background self-improvement review fork created;
skills a user asked for belong to the user. run_agent.py binds the origin before each tool loop (mirroring
AIAgent._memory_write_origin) so handlers such as skill_manage create can check it::
token = set_current_write_origin("background_review")
try:
... # tool runs here
finally:
reset_current_write_origin(token)
"""
import contextvars
_write_origin: contextvars.ContextVar[str] = contextvars.ContextVar("skill_write_origin", default="foreground")
# Sentinel used by the background review fork (run_agent._spawn_background_review).
BACKGROUND_REVIEW = "background_review"
def set_current_write_origin(origin: str) -> contextvars.Token[str]:
"""Bind the active write origin; pass the Token to reset_current_write_origin."""
return _write_origin.set(origin or "foreground")
def reset_current_write_origin(token: contextvars.Token[str]) -> None:
_write_origin.reset(token)
def get_current_write_origin() -> str:
""""foreground" for any regular agent (CLI, gateway, cron, subagent); "background_review" for the review fork."""
return _write_origin.get()
def is_background_review() -> bool:
return get_current_write_origin() == BACKGROUND_REVIEW