Skip to content

Commit

Permalink
Merge pull request #57 from pipecat-ai/mb/improve-static-transitions
Browse files Browse the repository at this point in the history
Improve static transitions by adding a transition_to field in the function call
  • Loading branch information
markbackman authored Dec 6, 2024
2 parents 4d997f1 + ea40b29 commit 8816ed0
Show file tree
Hide file tree
Showing 26 changed files with 1,015 additions and 704 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ All notable changes to **Pipecat Flows** will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.7] - 2024-12-06

### Added

- New `transition_to` field for static flows
- Combines function handlers with state transitions
- Supports all LLM providers (OpenAI, Anthropic, Gemini)
- Static examples updated to use this new transition

### Changed

- Static flow transitions now use `transition_to` instead of matching function names
- Before: Function name had to match target node name
- After: Function explicitly declares target via `transition_to`

### Fixed

- Duplicate LLM responses during transitions

## [0.0.6] - 2024-12-02

### Added
Expand Down
42 changes: 30 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ If you're starting fresh:
pip install pipecat-ai-flows

# Install Pipecat with specific LLM provider options:
pip install "pipecat-ai[daily,openai,deepgram]" # For OpenAI
pip install "pipecat-ai[daily,anthropic,deepgram]" # For Anthropic
pip install "pipecat-ai[daily,google,deepgram]" # For Google
pip install "pipecat-ai[daily,openai,deepgram,cartesia]" # For OpenAI
pip install "pipecat-ai[daily,anthropic,deepgram,cartesia]" # For Anthropic
pip install "pipecat-ai[daily,google,deepgram,cartesia]" # For Google
```

## Quick Start
Expand Down Expand Up @@ -93,14 +93,15 @@ Functions come in two types:
"type": "function",
"function": {
"name": "select_size",
"handler": select_size_handler, # Required for node functions
"handler": select_size_handler,
"description": "Select pizza size",
"parameters": {
"type": "object",
"properties": {
"size": {"type": "string", "enum": ["small", "medium", "large"]}
}
}
},
"transition_to": "next_node" # Optional: Specify next node
}
}
```
Expand All @@ -111,13 +112,21 @@ Functions come in two types:
{
"type": "function",
"function": {
"name": "next_node", # Must match a node name
"name": "next_step",
"description": "Move to next state",
"parameters": {"type": "object", "properties": {}}
"parameters": {"type": "object", "properties": {}},
"transition_to": "target_node" # Required: Specify target node
}
}
```

Functions can:

- Have a handler (for data processing)
- Have a transition_to (for state changes)
- Have both (process data and transition)
- Have neither (end node functions)

#### Actions

Actions execute during state transitions:
Expand Down Expand Up @@ -183,7 +192,16 @@ flow_config = {
"nodes": {
"greeting": {
"messages": [...],
"functions": [...]
"functions": [{
"type": "function",
"function": {
"name": "collect_name",
"description": "Record user's name",
"parameters": {...},
"handler": collect_name_handler, # Specify handler
"transition_to": "next_step" # Specify transition
}
}]
}
}
}
Expand Down Expand Up @@ -250,16 +268,16 @@ To run these examples:
Install Pipecat with required options for examples:

```bash
pip install "pipecat-ai[daily,openai,deepgram,silero,examples]"
pip install "pipecat-ai[daily,openai,deepgram,cartesia,silero,examples]"
```

If you're running Google or Anthropic examples, you will need to update the installed options. For example:

```bash
# Install Google Gemini
pip install "pipecat-ai[daily,google,deepgram,silero,examples]"
pip install "pipecat-ai[daily,google,deepgram,cartesia,silero,examples]"
# Install Anthropic
pip install "pipecat-ai[daily,anthropic,deepgram,silero,examples]"
pip install "pipecat-ai[daily,anthropic,deepgram,cartesia,silero,examples]"
```

3. **Configuration**:
Expand All @@ -273,6 +291,7 @@ To run these examples:
Add your API keys and configuration:

- DEEPGRAM_API_KEY
- CARTESIA_API_KEY
- OPENAI_API_KEY
- ANTHROPIC_API_KEY
- GOOGLE_API_KEY
Expand Down Expand Up @@ -409,7 +428,6 @@ Open the page in your browser: http://localhost:5173.
The `editor/examples/` directory contains sample flow configurations:

- `food_ordering.json`
- `movie_booking.json`
- `movie_explorer.py`
- `patient_intake.json`
- `restaurant_reservation.json`
Expand Down
88 changes: 54 additions & 34 deletions editor/examples/food_ordering.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@
"type": "function",
"function": {
"name": "choose_pizza",
"description": "User wants to order pizza",
"description": "User wants to order pizza. Let's get that order started.",
"parameters": {
"type": "object",
"properties": {}
}
},
"transition_to": "choose_pizza"
}
},
{
"type": "function",
"function": {
"name": "choose_sushi",
"description": "User wants to order sushi",
"description": "User wants to order sushi. Let's get that order started.",
"parameters": {
"type": "object",
"properties": {}
}
},
"transition_to": "choose_sushi"
}
}
]
Expand All @@ -37,60 +39,62 @@
"messages": [
{
"role": "system",
"content": "You are handling a pizza order. Use the available functions:\n - Use select_pizza_size when the user specifies a size (can be used multiple times if they change their mind or want to order multiple pizzas)\n - Use the end function ONLY when the user confirms they are done with their order\n\nAfter each size selection, confirm the selection and ask if they want to change it or complete their order. Only use the end function after the user confirms they are satisfied with their order.\n\nStart off by acknowledging the user's choice. Once they've chosen a size, ask if they'd like anything else. Remember to be friendly and casual."
"content": "You are handling a pizza order. Use the available functions:\n\n- Use select_pizza_order when the user specifies both size AND type\n\n- Use confirm_order when the user confirms they are satisfied with their selection\n\nPricing:\n\n- Small: $10\n\n- Medium: $15\n\n- Large: $20\n\nAfter selection, confirm both the size and type, state the price, and ask if they want to confirm their order. Remember to be friendly and casual."
}
],
"functions": [
{
"type": "function",
"function": {
"name": "select_pizza_size",
"description": "Record the selected pizza size",
"name": "select_pizza_order",
"handler": "select_pizza_order",
"description": "Record the pizza order details",
"parameters": {
"type": "object",
"properties": {
"size": {
"type": "string",
"enum": ["small", "medium", "large"],
"description": "Size of the pizza"
},
"type": {
"type": "string",
"enum": ["pepperoni", "cheese", "supreme", "vegetarian"],
"description": "Type of pizza"
}
},
"required": ["size"]
"required": ["size", "type"]
}
}
},
{
"type": "function",
"function": {
"name": "end",
"description": "Complete the order (use only after user confirms)",
"name": "confirm_order",
"description": "Proceed to order confirmation",
"parameters": {
"type": "object",
"properties": {}
}
},
"transition_to": "confirm"
}
}
],
"pre_actions": [
{
"type": "tts_say",
"text": "Ok, let me help you with your pizza order..."
}
]
},
"choose_sushi": {
"messages": [
{
"role": "system",
"content": "You are handling a sushi order. Use the available functions:\n - Use select_roll_count when the user specifies how many rolls (can be used multiple times if they change their mind or if they want to order multiple sushi rolls)\n - Use the end function ONLY when the user confirms they are done with their order\n\nAfter each roll count selection, confirm the count and ask if they want to change it or complete their order. Only use the end function after the user confirms they are satisfied with their order.\n\nStart off by acknowledging the user's choice. Once they've chosen a size, ask if they'd like anything else. Remember to be friendly and casual."
"content": "You are handling a sushi order. Use the available functions:\n\n- Use select_sushi_order when the user specifies both count AND type\n\n- Use confirm_order when the user confirms they are satisfied with their selection\n\nPricing:\n\n- $8 per roll\n\nAfter selection, confirm both the count and type, state the price, and ask if they want to confirm their order. Remember to be friendly and casual."
}
],
"functions": [
{
"type": "function",
"function": {
"name": "select_roll_count",
"description": "Record the number of sushi rolls",
"name": "select_sushi_order",
"handler": "select_sushi_order",
"description": "Record the sushi order details",
"parameters": {
"type": "object",
"properties": {
Expand All @@ -99,45 +103,61 @@
"minimum": 1,
"maximum": 10,
"description": "Number of rolls to order"
},
"type": {
"type": "string",
"enum": ["california", "spicy tuna", "rainbow", "dragon"],
"description": "Type of sushi roll"
}
},
"required": ["count"]
"required": ["count", "type"]
}
}
},
{
"type": "function",
"function": {
"name": "end",
"description": "Complete the order (use only after user confirms)",
"name": "confirm_order",
"description": "Proceed to order confirmation",
"parameters": {
"type": "object",
"properties": {}
}
},
"transition_to": "confirm"
}
}
]
},
"confirm": {
"messages": [
{
"role": "system",
"content": "Read back the complete order details to the user and ask for final confirmation. Use the available functions:\n\n- Use complete_order when the user confirms\n\n- Use revise_order if they want to change something\n\nBe friendly and clear when reading back the order details."
}
],
"pre_actions": [
"functions": [
{
"type": "tts_say",
"text": "Ok, let me help you with your sushi order..."
"type": "function",
"function": {
"name": "complete_order",
"description": "User confirms the order is correct",
"parameters": {
"type": "object",
"properties": {}
},
"transition_to": "end"
}
}
]
},
"end": {
"messages": [
{
"role": "system",
"content": "The order is complete. Thank the user and end the conversation."
"content": "Concisely end the conversation—1-3 words is appropriate. Just say 'Bye' or something similarly short."
}
],
"functions": [],
"pre_actions": [
{
"type": "tts_say",
"text": "Thank you for your order! Goodbye!"
}
],
"post_actions": [
{
"type": "end_conversation"
Expand Down
Loading

0 comments on commit 8816ed0

Please sign in to comment.