55
66_CACHED_COMMIT = None
77_CACHED_RUN_ID = None
8+ _CACHED_PROFILE = None
89
910
1011def run_id ():
@@ -14,6 +15,41 @@ def run_id():
1415 return _CACHED_RUN_ID
1516
1617
18+ def profile ():
19+ """Return the active harness profile name, or "default" when unknown.
20+
21+ Harnesses that run multiple isolated agent identities against the same
22+ portable brain (e.g. Hermes's --profile flag spawning distinct
23+ specialist agents) should set ``AGENT_PROFILE`` to the active name so
24+ every episodic entry is tagged. Enables cross-profile clustering and
25+ per-specialist retrospectives in the dream cycle.
26+
27+ Fallback detection covers known harnesses without code changes there:
28+ * ``AGENT_PROFILE`` - canonical, any harness.
29+ * ``HERMES_HOME`` - if it points under ``<...>/profiles/<name>``
30+ use that name; otherwise "default".
31+ """
32+ global _CACHED_PROFILE
33+ if _CACHED_PROFILE is not None :
34+ return _CACHED_PROFILE
35+
36+ explicit = os .environ .get ("AGENT_PROFILE" , "" ).strip ()
37+ if explicit :
38+ _CACHED_PROFILE = explicit
39+ return _CACHED_PROFILE
40+
41+ hermes_home = os .environ .get ("HERMES_HOME" , "" ).rstrip ("/" )
42+ if hermes_home :
43+ if "/profiles/" in hermes_home :
44+ _CACHED_PROFILE = hermes_home .rsplit ("/" , 1 )[- 1 ]
45+ else :
46+ _CACHED_PROFILE = "default"
47+ return _CACHED_PROFILE
48+
49+ _CACHED_PROFILE = "default"
50+ return _CACHED_PROFILE
51+
52+
1753def commit_sha ():
1854 global _CACHED_COMMIT
1955 if _CACHED_COMMIT is None :
@@ -30,4 +66,9 @@ def commit_sha():
3066
3167
3268def build_source (skill ):
33- return {"skill" : skill , "run_id" : run_id (), "commit_sha" : commit_sha ()}
69+ return {
70+ "skill" : skill ,
71+ "profile" : profile (),
72+ "run_id" : run_id (),
73+ "commit_sha" : commit_sha (),
74+ }
0 commit comments