1313from contextvars import ContextVar
1414from dataclasses import dataclass , field
1515from enum import Enum
16- from typing import Any , Dict , Optional , Union
16+ from typing import Any , Optional
1717
18- from pyrit .identifiers import Identifier
18+ from pyrit .identifiers import AttackIdentifier , Identifier
1919
2020
2121class ComponentRole (Enum ):
@@ -61,11 +61,11 @@ class ExecutionContext:
6161 # The attack strategy class name (e.g., "PromptSendingAttack")
6262 attack_strategy_name : Optional [str ] = None
6363
64- # The identifier from the attack strategy's get_identifier()
65- attack_identifier : Optional [Dict [ str , Any ] ] = None
64+ # The identifier for the attack strategy
65+ attack_identifier : Optional [AttackIdentifier ] = None
6666
6767 # The identifier from the component's get_identifier() (target, scorer, etc.)
68- component_identifier : Optional [Dict [ str , Any ] ] = None
68+ component_identifier : Optional [Identifier ] = None
6969
7070 # The objective target conversation ID if available
7171 objective_target_conversation_id : Optional [str ] = None
@@ -192,8 +192,8 @@ def execution_context(
192192 * ,
193193 component_role : ComponentRole ,
194194 attack_strategy_name : Optional [str ] = None ,
195- attack_identifier : Optional [Dict [ str , Any ] ] = None ,
196- component_identifier : Optional [Union [ Identifier , Dict [ str , Any ]] ] = None ,
195+ attack_identifier : Optional [AttackIdentifier ] = None ,
196+ component_identifier : Optional [Identifier ] = None ,
197197 objective_target_conversation_id : Optional [str ] = None ,
198198 objective : Optional [str ] = None ,
199199) -> ExecutionContextManager :
@@ -203,9 +203,8 @@ def execution_context(
203203 Args:
204204 component_role: The role of the component being executed.
205205 attack_strategy_name: The name of the attack strategy class.
206- attack_identifier: The identifier from attack.get_identifier() .
206+ attack_identifier: The attack identifier .
207207 component_identifier: The identifier from component.get_identifier().
208- Can be an Identifier object or a dict (legacy format).
209208 objective_target_conversation_id: The objective target conversation ID if available.
210209 objective: The attack objective if available.
211210
@@ -215,22 +214,15 @@ def execution_context(
215214 # Extract endpoint and component_name from component_identifier if available
216215 endpoint = None
217216 component_name = None
218- component_id_dict : Optional [Dict [str , Any ]] = None
219217 if component_identifier :
220- if isinstance (component_identifier , Identifier ):
221- endpoint = getattr (component_identifier , "endpoint" , None )
222- component_name = component_identifier .class_name
223- component_id_dict = component_identifier .to_dict ()
224- else :
225- endpoint = component_identifier .get ("endpoint" )
226- component_name = component_identifier .get ("__type__" )
227- component_id_dict = component_identifier
218+ endpoint = getattr (component_identifier , "endpoint" , None )
219+ component_name = component_identifier .class_name
228220
229221 context = ExecutionContext (
230222 component_role = component_role ,
231223 attack_strategy_name = attack_strategy_name ,
232224 attack_identifier = attack_identifier ,
233- component_identifier = component_id_dict ,
225+ component_identifier = component_identifier ,
234226 objective_target_conversation_id = objective_target_conversation_id ,
235227 endpoint = endpoint ,
236228 component_name = component_name ,
0 commit comments