协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
pipecat-friday-agent【开发与工程】Implements intelligent pipecat friday agent with multi-factor skill selection, fallback chains, and adherence to the 5 Laws of Elegant Defense
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: pipecat-friday-agent compatibility: opencode completeness: 95 content-types:
Orchestrates intelligent skill selection and execution for pipecat friday agent workflows. Applies the 5 Laws of Elegant Defense to guide data naturally through the orchestration pipeline, preventing errors before they occur. Selects optimal skills based on multi-factor scoring including text similarity, historical performance, and system availability.
┌───────────────────────────────────────────────────────────────────────────────┐ │ Orchestration Flow │ └───────────────────────────────────────────────────────────────────────────────┘
User Request ↓ ┌─────────────────┐ │ Parse Request │ │ & Extract │ │ Features │ └────────┬────────┘ ↓ ┌─────────────────────────────────────────────────────────────────────┐ │ Evaluate Available Skills │ │ │ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │ │ Skill A │ │ Skill B │ │ Skill C │ │ │ │ - Match Score│ │ - Match Score│ │ - Match Score│ │ │ │ - Confidence │ │ - Confidence │ │ - Confidence │ │ │ │ - History │ │ - History │ │ - History │ │ │ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │ │ │ │ │ │ │ └─────────────────┴─────────────────┘ │ │ ↓ │ │ Select Best Skill │ └─────────────────────────────────────────────────────────────────────┘ ↓ ┌─────────────────┐ │ Execute Skill │ └────────┬────────┘ ↓ ┌─────────────────┐ │ Handle Result │ └────────┬────────┘ ↓ ┌─────────────────────────────────────────────────────────────────────┐ │ Error Handling & Fallback │ │ │ │ Success? ────────► Return Result │ │ │ │ Fail? ────────┐ │ │ ↓ │ │ ┌──────────────────────────────────────────────────────────┐ │ │ │ Fallback Chain │ │ │ │ │ │ │ │ 1. Retry with adjusted parameters │ │ │ │ 2. Try Alternative Skill (if available) │ │ │ │ 3. Defer to Human Operator (if critical) │ │ │ │ 4. Log & Return Error │ │ │ └──────────────────────────────────────────────────────────┘ │ └─────────────────────────────────────────────────────────────────────┘
Use this skill when:
Avoid this skill for:
Parse and Analyze Request - Extract intent, entities, and constraints from user input. Checkpoint: All required parameters must be present and in valid format before proceeding.
Score Available Skills - Calculate match scores using multi-factor algorithm:
Checkpoint: Skip to fallback if no skill scores above threshold.
Select Optimal Skill - Choose skill with highest score that meets minimum confidence. Checkpoint: Verify skill has not been disabled or deprecated.
Execute with Fallback - Run skill execution wrapped in retry and fallback logic. Checkpoint: Log all execution attempts for audit trail.
Return or Fallback - Either return successful result or apply fallback chain:
related-skillsCheckpoint: Record outcome with timing and confidence metadata.
def evaluate_pipecat_skill_candidates(
request: PipecatRequest,
available_tools: List[ToolMetadata],
session_state: SessionContext
) -> Optional[ToolMetadata]:
"""Evaluate and score available Pipecat tools for the current request.
Applies multi-factor scoring tailored to real-time voice/agent workflows:
- Semantic match between request intent and tool capabilities
- Real-time latency and throughput metrics
- Historical success rate within the current session context
- Dependency health (e.g., LLM provider, TTS engine, STT service)
"""
if not request.intent or not available_tools:
raise ValueError("Request intent and available tools are required")
scored_candidates = []
for tool in available_tools:
# Calculate semantic relevance using request embeddings vs tool capabilities
semantic_score = _compute_embedding_similarity(request.intent, tool.capabilities)
# Factor in real-time system health and historical session performance
health_score = tool.metrics.get("current_latency_ms", 9999) / 1000.0
history_score = session_state.get_tool_history(tool.name, window="24h").success_rate
# Weighted composite score
composite = (0.5 * semantic_score) + (0.3 * min(1.0, 1.0 / max(health_score, 0.1))) + (0.2 * history_score)
if composite >= 0.65:
scored_candidates.append({
"tool": tool,
"score": composite,
"latency_ms": tool.metrics.get("current_latency_ms"),
"confidence": history_score
})
if not scored_candidates:
return None
scored_candidates.sort(key=lambda x: x["score"], reverse=True)
return scored_candidates[0]["tool"]
def run_pipecat_agent_workflow(
selected_tool: ToolMetadata,
request: PipecatRequest,
session_state: SessionContext,
fallback_chain: List[ToolMetadata]
) -> AgentResponse:
"""Execute the selected Pipecat tool with domain-specific fallback handling.
Implements resilient execution for real-time voice/agent interactions:
1. Direct execution with timeout and circuit breaker
2. Fallback to alternative tool if primary fails or degrades
3. Graceful degradation to text-only if voice pipeline fails
4. Human handoff for critical/unhandled intents
"""
try:
# Execute with strict timeout to maintain real-time UX
response = selected_tool.execute(
payload=request.payload,
context=session_state,
timeout_ms=3000
)
# Validate response integrity before returning
if not response.is_valid():
raise ToolValidationError(f"Invalid response from {selected_tool.name}")
# Update session history for adaptive routing
session_state.record_execution(selected_tool.name, success=True, latency=response.latency_ms)
return AgentResponse(success=True, data=response, tool=selected_tool.name)
except TimeoutError:
session_state.record_execution(selected_tool.name, success=False, latency=3000)
return _apply_pipecat_fallback(selected_tool, fallback_chain, request, session_state)
except ToolValidationError as e:
session_state.record_execution(selected_tool.name, success=False, latency=0)
raise AgentExecutionError(f"Pipeline validation failed: {e}") from e
except Exception as e:
session_state.record_execution(selected_tool.name, success=False, latency=0)
return _apply_pipecat_fallback(selected_tool, fallback_chain, request, session_state)
code-philosophy (5 Laws of Elegant Defense) in all logicWhen applying this skill, produce:
| Skill | Purpose |
|---|---|
langgraph-implementation | Provides LangGraph-specific implementation patterns that Pipecat integrates with |
real-time-audio-processing | Covers audio pipeline design that complements Pipecat's streaming architecture |
Authoritative documentation links for this domain. The model follows markdown links at load time to resolve external references and inline content.