4545from ..utils .feature_decorator import experimental
4646from .base_agent_config import BaseAgentConfig
4747from .callback_context import CallbackContext
48+ from .callback_pipeline import normalize_callbacks
4849
4950if TYPE_CHECKING :
5051 from .invocation_context import InvocationContext
@@ -416,30 +417,6 @@ def _create_invocation_context(
416417 invocation_context = parent_context .model_copy (update = {'agent' : self })
417418 return invocation_context
418419
419- @property
420- def canonical_before_agent_callbacks (self ) -> list [_SingleAgentCallback ]:
421- """The resolved self.before_agent_callback field as a list of _SingleAgentCallback.
422-
423- This method is only for use by Agent Development Kit.
424- """
425- if not self .before_agent_callback :
426- return []
427- if isinstance (self .before_agent_callback , list ):
428- return self .before_agent_callback
429- return [self .before_agent_callback ]
430-
431- @property
432- def canonical_after_agent_callbacks (self ) -> list [_SingleAgentCallback ]:
433- """The resolved self.after_agent_callback field as a list of _SingleAgentCallback.
434-
435- This method is only for use by Agent Development Kit.
436- """
437- if not self .after_agent_callback :
438- return []
439- if isinstance (self .after_agent_callback , list ):
440- return self .after_agent_callback
441- return [self .after_agent_callback ]
442-
443420 async def __handle_before_agent_callback (
444421 self , ctx : InvocationContext
445422 ) -> Optional [Event ]:
@@ -462,11 +439,9 @@ async def __handle_before_agent_callback(
462439
463440 # If no overrides are provided from the plugins, further run the canonical
464441 # callbacks.
465- if (
466- not before_agent_callback_content
467- and self .canonical_before_agent_callbacks
468- ):
469- for callback in self .canonical_before_agent_callbacks :
442+ callbacks = normalize_callbacks (self .before_agent_callback )
443+ if not before_agent_callback_content and callbacks :
444+ for callback in callbacks :
470445 before_agent_callback_content = callback (
471446 callback_context = callback_context
472447 )
@@ -522,11 +497,9 @@ async def __handle_after_agent_callback(
522497
523498 # If no overrides are provided from the plugins, further run the canonical
524499 # callbacks.
525- if (
526- not after_agent_callback_content
527- and self .canonical_after_agent_callbacks
528- ):
529- for callback in self .canonical_after_agent_callbacks :
500+ callbacks = normalize_callbacks (self .after_agent_callback )
501+ if not after_agent_callback_content and callbacks :
502+ for callback in callbacks :
530503 after_agent_callback_content = callback (
531504 callback_context = callback_context
532505 )
0 commit comments