Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions api-reference/server/frames/data-frames.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,15 @@ Frames for configuring LLM function calling behavior and output settings at runt

### LLMSetToolsFrame

Sets the available tools for LLM function calling. The format of tool definitions typically follows JSON Schema conventions, though the exact structure depends on the LLM provider.

<ParamField path="tools" type="List[dict] | ToolsSchema | NotGiven" required>
List of tool/function definitions for the LLM.
Changes the set of tools advertised to the LLM mid-conversation.

<ParamField path="tools" type="list[dict] | list[FunctionSchema | DirectFunction] | ToolsSchema | NotGiven" required>
The tools to advertise. May be a `ToolsSchema`, a plain list of direct
functions and/or `FunctionSchema` objects, a list of provider-specific tool
dicts, or `NOT_GIVEN` to clear all tools. Direct functions and
`FunctionSchema`s with a bundled `handler` are auto-registered with the LLM
service, meaning no manual handler registration is needed. Any such tool
dropped from the advertised set is automatically unregistered.
</ParamField>

### LLMSetToolChoiceFrame
Expand Down
11 changes: 9 additions & 2 deletions api-reference/server/services/llm/inception.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,17 @@ llm = InceptionLLMService(
### With Function Calling

```python
from pipecat.processors.aggregators.llm_context import LLMContext
from pipecat.services.inception import InceptionLLMService
from pipecat.services.llm_service import FunctionCallParams

async def get_weather(params: FunctionCallParams):
# A direct function: schema is auto-derived from the signature and docstring
async def get_weather(params: FunctionCallParams, location: str):
"""Get the current weather.

Args:
location: The city and state, e.g. "San Francisco, CA".
"""
await params.result_callback({"temperature": "75", "conditions": "sunny"})

llm = InceptionLLMService(
Expand All @@ -133,7 +140,7 @@ llm = InceptionLLMService(
),
)

llm.register_function("get_weather", get_weather)
context = LLMContext(tools=[get_weather])
```

## Notes
Expand Down
27 changes: 8 additions & 19 deletions api-reference/server/services/llm/novita.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,16 @@ llm = NovitaLLMService(
### With Function Calling

```python
from pipecat.adapters.schemas.function_schema import FunctionSchema
from pipecat.adapters.schemas.tools_schema import ToolsSchema
from pipecat.processors.aggregators.llm_context import LLMContext
from pipecat.services.llm_service import FunctionCallParams

async def get_weather(params: FunctionCallParams):
# A direct function: schema is auto-derived from the signature and docstring
async def get_weather(params: FunctionCallParams, location: str):
"""Get the current weather.

Args:
location: The city and state, e.g. "San Francisco, CA".
"""
await params.result_callback({"temperature": "75", "conditions": "sunny"})

llm = NovitaLLMService(
Expand All @@ -125,22 +129,7 @@ llm = NovitaLLMService(
),
)

llm.register_function("get_weather", get_weather)

weather_function = FunctionSchema(
name="get_weather",
description="Get the current weather",
properties={
"location": {
"type": "string",
"description": "City and state, e.g. San Francisco, CA",
},
},
required=["location"],
)

tools = ToolsSchema(standard_tools=[weather_function])
context = LLMContext(tools=tools)
context = LLMContext(tools=[get_weather])
```

## Notes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ result = await llm_switcher.run_inference(

### register_function()

<Note>
You don't need `register_function` when your tool's handler is bundled on its
`FunctionSchema`: listing it in `LLMContext(tools=[...])` or adding it via
`LLMSetToolsFrame` is enough.
</Note>

Register a function handler with all LLMs in the switcher, regardless of which is currently active.

```python
Expand Down Expand Up @@ -103,7 +109,15 @@ llm_switcher.register_function(

### register_direct_function()

Register a direct function handler with all LLMs in the switcher, regardless of which is currently active. Direct functions provide more control over function call execution.
<Warning>
**Deprecated since 1.4.0.** Direct functions now register automatically on
every member LLM (active or not) when you list them in
`LLMContext(tools=[...])`, so explicit registration is no longer needed — the
tools keep working across service switches. Push an `LLMSetToolsFrame` to
change tools mid-session. This method will be removed in a future version.
</Warning>

Register a direct function handler with all LLMs in the switcher, regardless of which is currently active.

```python
llm_switcher.register_direct_function(
Expand Down
22 changes: 3 additions & 19 deletions pipecat/fundamentals/context-summarization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -137,31 +137,15 @@ from pipecat.frames.frames import LLMSummarizeContextFrame
from pipecat.services.llm_service import FunctionCallParams

async def summarize_conversation(params: FunctionCallParams):
"""Trigger manual context summarization via a pipeline frame."""
"""Summarize and compress the conversation history. Call this when the user asks you to summarize the conversation or when you want to free up context space."""
await params.result_callback({"status": "summarization_requested"})
await params.llm.queue_frame(LLMSummarizeContextFrame())
```

Register this as a function call tool so the LLM can invoke it when the user asks to summarize:
Above, `summarize_conversation` is a [direct function](/pipecat/learn/function-calling#1-define-a-tool). List it in the context's `tools` so the LLM can invoke it when the user asks to summarize:

```python
from pipecat.adapters.schemas.function_schema import FunctionSchema
from pipecat.adapters.schemas.tools_schema import ToolsSchema

llm.register_function("summarize_conversation", summarize_conversation)

summarize_function = FunctionSchema(
name="summarize_conversation",
description=(
"Summarize and compress the conversation history. "
"Call this when the user asks you to summarize the conversation "
"or when you want to free up context space."
),
properties={},
required=[],
)
tools = ToolsSchema(standard_tools=[summarize_function])
context = LLMContext(messages, tools=tools)
context = LLMContext(messages, tools=[summarize_conversation])
```

On-demand summarization works even when `enable_auto_context_summarization` is `False` — the summarizer is always created internally to handle manually pushed frames. You can also pass a per-request `LLMContextSummaryConfig` to override the default settings:
Expand Down
38 changes: 13 additions & 25 deletions pipecat/learn/context-management.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -85,40 +85,28 @@ user_aggregator, assistant_aggregator = LLMContextAggregatorPair(context)
Key properties:

- **`messages`**: List of conversation messages (user, assistant, developer, tool)
- **`tools`**: Optional `ToolsSchema` defining available functions
- **`tools`**: Optional available functions — a list of direct functions and/or `FunctionSchema` objects (or a `ToolsSchema`)
- **`tool_choice`**: Optional strategy for tool selection

### 2. Context with Function Calling

Context can also include tools (function definitions) that the LLM can call during conversations:
Context can also include [tools](/pipecat/learn/function-calling#1-define-a-tool) (function definitions) that the LLM can call during conversations:

```python
from pipecat.adapters.schemas.function_schema import FunctionSchema
from pipecat.adapters.schemas.tools_schema import ToolsSchema

# Define available functions
weather_function = FunctionSchema(
name="get_current_weather",
description="Get the current weather",
properties={
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
"format": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "The temperature unit to use.",
},
},
required=["location", "format"],
)
from pipecat.services.llm_service import FunctionCallParams

# A direct function: schema is auto-derived from the signature and docstring
async def get_current_weather(params: FunctionCallParams, location: str, format: str):
"""Get the current weather.

# Create tools schema
tools = ToolsSchema(standard_tools=[weather_function])
Args:
location: The city and state, e.g. "San Francisco, CA".
format: The temperature unit to use. Must be either "celsius" or "fahrenheit".
"""
await params.result_callback({"conditions": "sunny", "temperature": "75"})

# Create context with both messages and tools
context = LLMContext(messages, tools)
context = LLMContext(messages, tools=[get_current_weather])
user_aggregator, assistant_aggregator = LLMContextAggregatorPair(context)
```

Expand Down
Loading
Loading