@@ -421,6 +421,53 @@ def build_role_binding_summary(contract: dict[str, Any]) -> dict[str, Any]:
421421 }
422422
423423
424+ def build_prompt_artifact (
425+ contract : dict [str , Any ],
426+ * ,
427+ run_id : str = "" ,
428+ task_id : str = "" ,
429+ ) -> dict [str , Any ]:
430+ role_contract = contract .get ("role_contract" ) if isinstance (contract .get ("role_contract" ), dict ) else {}
431+ if not role_contract :
432+ role_contract = _build_role_contract (contract , _load_agent_registry ())
433+ assigned_agent = contract .get ("assigned_agent" ) if isinstance (contract .get ("assigned_agent" ), dict ) else {}
434+ role = str (
435+ assigned_agent .get ("role" )
436+ or (role_contract .get ("identity" , {}) if isinstance (role_contract .get ("identity" ), dict ) else {}).get ("role" )
437+ or "WORKER"
438+ ).strip ().upper () or "WORKER"
439+ role_contract = _merge_role_config_defaults (
440+ role_contract ,
441+ _find_role_config_defaults (_load_role_config_registry (), role ),
442+ )
443+ identity = role_contract .get ("identity" ) if isinstance (role_contract .get ("identity" ), dict ) else {}
444+ runtime_binding_raw = role_contract .get ("runtime_binding" ) if isinstance (role_contract .get ("runtime_binding" ), dict ) else {}
445+ runtime_binding = {
446+ "runner" : _normalize_optional_ref (runtime_binding_raw .get ("runner" )),
447+ "provider" : _normalize_optional_ref (runtime_binding_raw .get ("provider" )),
448+ "model" : _normalize_optional_ref (runtime_binding_raw .get ("model" )),
449+ }
450+ resolved_task_id = str (task_id or contract .get ("task_id" ) or "" ).strip ()
451+ return {
452+ "artifact_type" : "prompt_artifact" ,
453+ "version" : "v1" ,
454+ "source" : "contract-derived" ,
455+ "execution_authority" : "task_contract" ,
456+ "run_id" : str (run_id or "" ).strip (),
457+ "task_id" : resolved_task_id ,
458+ "assigned_agent" : {
459+ "role" : role ,
460+ "agent_id" : str (identity .get ("agent_id" ) or assigned_agent .get ("agent_id" ) or "" ).strip (),
461+ },
462+ "purpose" : str (role_contract .get ("purpose" ) or "" ).strip (),
463+ "system_prompt_ref" : _normalize_optional_ref (role_contract .get ("system_prompt_ref" )),
464+ "skills_bundle_ref" : _normalize_optional_ref (role_contract .get ("skills_bundle_ref" )),
465+ "mcp_bundle_ref" : _normalize_optional_ref (role_contract .get ("mcp_bundle_ref" )),
466+ "runtime_binding" : runtime_binding ,
467+ "role_binding_summary" : build_role_binding_summary (contract ),
468+ }
469+
470+
424471def _build_role_contract (contract : dict [str , Any ], registry : dict [str , Any ] | None ) -> dict [str , Any ]:
425472 assigned_agent = contract .get ("assigned_agent" ) if isinstance (contract .get ("assigned_agent" ), dict ) else {}
426473 role = str (assigned_agent .get ("role" ) or "WORKER" ).strip ().upper () or "WORKER"
0 commit comments