From 49b2b12e04ec43709c4dda29cdd51d9cef83cac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Thu, 4 Dec 2025 14:55:06 -0800 Subject: [PATCH] frames: change function call frame base types --- changelog/3189.changed.md | 3 + src/pipecat/frames/frames.py | 110 +++++++++++++++++++---------------- 2 files changed, 62 insertions(+), 51 deletions(-) create mode 100644 changelog/3189.changed.md diff --git a/changelog/3189.changed.md b/changelog/3189.changed.md new file mode 100644 index 000000000..f8f24a856 --- /dev/null +++ b/changelog/3189.changed.md @@ -0,0 +1,3 @@ +- `FunctionCallInProgressFrame` and `FunctionCallResultFrame` have changed from + system frames to a control frame and a data frame, respectively, and are now + both marked as `UninterruptibleFrame`. diff --git a/src/pipecat/frames/frames.py b/src/pipecat/frames/frames.py index f02433e8c..9cb969f28 100644 --- a/src/pipecat/frames/frames.py +++ b/src/pipecat/frames/frames.py @@ -710,6 +710,44 @@ class LLMConfigureOutputFrame(DataFrame): skip_tts: bool +@dataclass +class FunctionCallResultProperties: + """Properties for configuring function call result behavior. + + Parameters: + run_llm: Whether to run the LLM after receiving this result. + on_context_updated: Callback to execute when context is updated. + """ + + run_llm: Optional[bool] = None + on_context_updated: Optional[Callable[[], Awaitable[None]]] = None + + +@dataclass +class FunctionCallResultFrame(DataFrame, UninterruptibleFrame): + """Frame containing the result of an LLM function call. + + This is an uninterruptible frame because once a result is generated we + always want to update the context. + + Parameters: + function_name: Name of the function that was executed. + tool_call_id: Unique identifier for the function call. + arguments: Arguments that were passed to the function. + result: The result returned by the function. + run_llm: Whether to run the LLM after this result. + properties: Additional properties for result handling. + + """ + + function_name: str + tool_call_id: str + arguments: Any + result: Any + run_llm: Optional[bool] = None + properties: Optional[FunctionCallResultProperties] = None + + @dataclass class TTSSpeakFrame(DataFrame): """Frame containing text that should be spoken by TTS. @@ -1103,23 +1141,6 @@ class FunctionCallsStartedFrame(SystemFrame): function_calls: Sequence[FunctionCallFromLLM] -@dataclass -class FunctionCallInProgressFrame(SystemFrame): - """Frame signaling that a function call is currently executing. - - Parameters: - function_name: Name of the function being executed. - tool_call_id: Unique identifier for this function call. - arguments: Arguments passed to the function. - cancel_on_interruption: Whether to cancel this call if interrupted. - """ - - function_name: str - tool_call_id: str - arguments: Any - cancel_on_interruption: bool = False - - @dataclass class FunctionCallCancelFrame(SystemFrame): """Frame signaling that a function call has been cancelled. @@ -1133,40 +1154,6 @@ class FunctionCallCancelFrame(SystemFrame): tool_call_id: str -@dataclass -class FunctionCallResultProperties: - """Properties for configuring function call result behavior. - - Parameters: - run_llm: Whether to run the LLM after receiving this result. - on_context_updated: Callback to execute when context is updated. - """ - - run_llm: Optional[bool] = None - on_context_updated: Optional[Callable[[], Awaitable[None]]] = None - - -@dataclass -class FunctionCallResultFrame(SystemFrame): - """Frame containing the result of an LLM function call. - - Parameters: - function_name: Name of the function that was executed. - tool_call_id: Unique identifier for the function call. - arguments: Arguments that were passed to the function. - result: The result returned by the function. - run_llm: Whether to run the LLM after this result. - properties: Additional properties for result handling. - """ - - function_name: str - tool_call_id: str - arguments: Any - result: Any - run_llm: Optional[bool] = None - properties: Optional[FunctionCallResultProperties] = None - - @dataclass class STTMuteFrame(SystemFrame): """Frame to mute/unmute the Speech-to-Text service. @@ -1664,6 +1651,27 @@ class LLMFullResponseEndFrame(ControlFrame): self.skip_tts = None +@dataclass +class FunctionCallInProgressFrame(ControlFrame, UninterruptibleFrame): + """Frame signaling that a function call is currently executing. + + This is an uninterruptible frame because we always want to update the + context. + + Parameters: + function_name: Name of the function being executed. + tool_call_id: Unique identifier for this function call. + arguments: Arguments passed to the function. + cancel_on_interruption: Whether to cancel this call if interrupted. + + """ + + function_name: str + tool_call_id: str + arguments: Any + cancel_on_interruption: bool = False + + @dataclass class TTSStartedFrame(ControlFrame): """Frame indicating the beginning of a TTS response.