chore: upgrade pipecat

This commit is contained in:
Abhishek Kumar 2026-03-06 16:49:14 +05:30
parent 7b77721964
commit e34e4f8f3c
13 changed files with 45 additions and 58 deletions

View file

@ -49,7 +49,6 @@ from api.services.workflow.tools.timezone import (
get_current_time,
get_time_tools,
)
from pipecat.utils.tracing.context_registry import get_current_turn_context
class PipecatEngine:
@ -116,6 +115,17 @@ class PipecatEngine:
# Fallback for when manager is not yet initialized
return await get_organization_id_from_workflow_run(self._workflow_run_id)
def _get_otel_context(self):
"""Extract the OTel Context from the task's TracingContext.
Returns the turn-level context if available, otherwise the
conversation-level context, or None.
"""
tracing_ctx = getattr(self.task, "_tracing_context", None)
if not tracing_ctx:
return None
return tracing_ctx.get_turn_context() or tracing_ctx.get_conversation_context()
@property
def builtin_function_schemas(self) -> list[dict]:
"""Get built-in function schemas (calculator and timezone tools)."""
@ -356,6 +366,7 @@ class PipecatEngine:
embeddings_api_key=self._embeddings_api_key,
embeddings_model=self._embeddings_model,
embeddings_base_url=self._embeddings_base_url,
tracing_context=self._get_otel_context(),
)
await function_call_params.result_callback(result)
@ -383,8 +394,8 @@ class PipecatEngine:
return
# Capture the current turn context for otel tracing
# before creating the background task
parent_context = get_current_turn_context()
# before creating the background task.
parent_context = self._get_otel_context()
extraction_prompt = self._format_prompt(node.extraction_prompt)
extraction_variables = node.extraction_variables
@ -416,11 +427,11 @@ class PipecatEngine:
async def _setup_llm_context(self, node: Node) -> None:
"""Common method to set up LLM context"""
# Set node name for tracing
# Set OTel span name for tracing
try:
self.context.set_node_name(node.name)
self.context.set_otel_span_name(f"llm-{node.name}")
except AttributeError:
logger.warning(f"context has no set_node_name method")
logger.warning(f"context has no set_otel_span_name method")
# Register transition functions if not an end node
if not node.is_end:

View file

@ -128,14 +128,14 @@ class CustomToolManager:
function_name = schema["function"]["name"]
# Create and register the handler
handler, disable_timeout, cancel_on_interruption = self._create_handler(
handler, timeout_secs, cancel_on_interruption = self._create_handler(
tool, function_name
)
self._engine.llm.register_function(
function_name,
handler,
cancel_on_interruption=cancel_on_interruption,
disable_timeout=disable_timeout,
timeout_secs=timeout_secs,
)
logger.debug(
@ -156,21 +156,20 @@ class CustomToolManager:
Returns:
Async handler function for the tool
"""
# Whether to disable function call timeout
disable_timeout = False
timeout_secs: Optional[float] = None
cancel_on_interruption = True
if tool.category == ToolCategory.END_CALL.value:
cancel_on_interruption = False
handler = self._create_end_call_handler(tool, function_name)
elif tool.category == ToolCategory.TRANSFER_CALL.value:
disable_timeout = True
timeout_secs = 120.0
cancel_on_interruption = False
handler = self._create_transfer_call_handler(tool, function_name)
else:
handler = self._create_http_tool_handler(tool, function_name)
return handler, disable_timeout, cancel_on_interruption
return handler, timeout_secs, cancel_on_interruption
def _create_http_tool_handler(self, tool: Any, function_name: str):
"""Create a handler function for an HTTP API tool.

View file

@ -178,6 +178,7 @@ async def run_per_node_qa_analysis(
model=model,
messages=messages,
temperature=0,
extra_body={"stream": False},
)
raw_response = response.choices[0].message.content
accumulate_token_usage(total_token_usage, response)

View file

@ -15,10 +15,6 @@ from opentelemetry import trace
from api.db import db_client
from api.services.gen_ai import OpenAIEmbeddingService
from api.services.pipecat.tracing_config import is_tracing_enabled
from pipecat.utils.tracing.context_registry import (
get_current_conversation_context,
get_current_turn_context,
)
async def retrieve_from_knowledge_base(
@ -29,6 +25,7 @@ async def retrieve_from_knowledge_base(
embeddings_api_key: Optional[str] = None,
embeddings_model: Optional[str] = None,
embeddings_base_url: Optional[str] = None,
tracing_context=None,
) -> Dict[str, Any]:
"""Retrieve relevant information from the knowledge base using vector similarity search.
@ -45,6 +42,7 @@ async def retrieve_from_knowledge_base(
embeddings_api_key: Optional API key for embedding service
embeddings_model: Optional model ID for embedding service
embeddings_base_url: Optional base URL for embedding service
tracing_context: Optional OpenTelemetry context for tracing
Returns:
Dictionary containing:
@ -55,10 +53,7 @@ async def retrieve_from_knowledge_base(
# Create span for retrieval operation if tracing is enabled
if is_tracing_enabled():
try:
# Get parent context from turn or conversation
turn_context = get_current_turn_context()
conversation_context = get_current_conversation_context()
parent_context = turn_context or conversation_context
parent_context = tracing_context
# Get tracer
tracer = trace.get_tracer("pipecat")