agent-apprenticeship 0.1.9 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -109,6 +109,30 @@ def _input_source(value: Any, meta: dict[str, Any]) -> dict[str, Any] | None:
109
109
  meta["original_input_source"] = value
110
110
  return None
111
111
 
112
+ def _actor_to_string(value: Any, action: str, meta: dict[str, Any]) -> str:
113
+ if action == "user_message":
114
+ return "user"
115
+ if isinstance(value, str) and value.strip():
116
+ return value.strip()
117
+ if isinstance(value, dict):
118
+ meta["original_actor"] = value
119
+ actor_kind = str(value.get("actor_kind") or value.get("kind") or "").strip()
120
+ role = str(value.get("role") or value.get("actor_role") or value.get("name") or "").strip()
121
+ agent_id = str(value.get("agent_id") or value.get("id") or "").strip()
122
+ if actor_kind and role:
123
+ return f"{actor_kind}:{role}"
124
+ if actor_kind and agent_id:
125
+ return f"{actor_kind}:{agent_id}"
126
+ if actor_kind:
127
+ return actor_kind
128
+ if role:
129
+ return role
130
+ if agent_id:
131
+ return f"agent:{agent_id}"
132
+ elif value is not None:
133
+ meta["original_actor"] = value
134
+ return "agent:worker"
135
+
112
136
  def _infer_environment_domain(tool: Any, operation: Any = None, input_value: Any = None, output_value: Any = None) -> str:
113
137
  text = " ".join(str(x or "") for x in [tool, operation, input_value, output_value]).lower()
114
138
  if any(x in text for x in ["mcp__", "mcp ", "model context protocol"]):
@@ -714,8 +738,7 @@ def _normalize_step(raw_step: Any, ordinal: int, used_steps: set[int], report: T
714
738
  if warnings:
715
739
  meta['normalization_warnings']=warnings; report.warnings.extend(warnings)
716
740
 
717
- actor=raw.get('actor') or ('user' if action == 'user_message' else 'agent:worker')
718
- if action == 'user_message': actor='user'
741
+ actor=_actor_to_string(raw.get('actor'), action, meta)
719
742
  raw_execution_mode = raw.get('execution_mode') if raw.get('execution_mode') in {'serial','parallel'} else None
720
743
  execution_mode = None if action == 'user_message' else (raw_execution_mode or 'serial')
721
744
  parallel_group = _string_or_none(raw.get('parallel_group'), meta, 'parallel_group') if execution_mode == 'parallel' else None