feat(observability): observer-grade telemetry hooks + NeMo-Relay plugin
Adds backend-neutral observer hooks for plugins: session, turn, API request, tool, approval, and subagent lifecycle events with stable correlation IDs (session_id, task_id, turn_id, api_request_id, tool_call_id, parent/child subagent ids). Extends VALID_HOOKS with api_request_error and subagent_start. Hot path is zero-cost when no plugin subscribes: has_hook()/presence checks gate all payload construction, request payloads are returned by reference when no middleware rewrites, and the sanitized response payload no longer embeds raw response objects. Bundles the optional NeMo-Relay observability plugin (plugins/observability/nemo_relay) as an in-repo consumer of the new hooks, peer to the existing langfuse plugin. Fails open when the optional nemo-relay package is not installed. Authored-by: Bryan Bednarski <bbednarski@nvidia.com> Salvaged from #29722 onto current main.
This commit is contained in:
@@ -1146,6 +1146,7 @@ def _build_child_agent(
|
||||
child._subagent_id = subagent_id
|
||||
child._parent_subagent_id = parent_subagent_id
|
||||
child._subagent_goal = goal
|
||||
child._parent_turn_id = getattr(parent_agent, "_current_turn_id", "") or ""
|
||||
|
||||
# Share a credential pool with the child when possible so subagents can
|
||||
# rotate credentials on rate limits instead of getting pinned to one key.
|
||||
@@ -1171,6 +1172,21 @@ def _build_child_agent(
|
||||
except Exception as exc:
|
||||
logger.debug("spawn_requested relay failed: %s", exc)
|
||||
|
||||
try:
|
||||
from hermes_cli.plugins import invoke_hook as _invoke_hook
|
||||
_invoke_hook(
|
||||
"subagent_start",
|
||||
parent_session_id=getattr(parent_agent, "session_id", None),
|
||||
parent_turn_id=getattr(parent_agent, "_current_turn_id", "") or "",
|
||||
parent_subagent_id=parent_subagent_id,
|
||||
child_session_id=getattr(child, "session_id", None),
|
||||
child_subagent_id=subagent_id,
|
||||
child_role=effective_role,
|
||||
child_goal=goal,
|
||||
)
|
||||
except Exception:
|
||||
logger.debug("subagent_start hook invocation failed", exc_info=True)
|
||||
|
||||
return child
|
||||
|
||||
|
||||
@@ -2265,9 +2281,17 @@ def delegate_task(
|
||||
if _invoke_hook is None:
|
||||
continue
|
||||
try:
|
||||
_child_index = entry.get("task_index", -1)
|
||||
_child_agent = (
|
||||
children[_child_index][2]
|
||||
if isinstance(_child_index, int) and 0 <= _child_index < len(children)
|
||||
else None
|
||||
)
|
||||
_invoke_hook(
|
||||
"subagent_stop",
|
||||
parent_session_id=_parent_session_id,
|
||||
parent_turn_id=getattr(parent_agent, "_current_turn_id", "") or "",
|
||||
child_session_id=getattr(_child_agent, "session_id", None),
|
||||
child_role=child_role,
|
||||
child_summary=entry.get("summary"),
|
||||
child_status=entry.get("status"),
|
||||
|
||||
Reference in New Issue
Block a user