request_strategies
Request strategies: how a delegate call becomes the backend’s request.
A BackendRequestStrategy defines the delegate tool the frontend
calls and turns each call into the request the backend receives. There are
two, chosen by frontend kind when the app gives none.
TranscriptBackendRequestStrategy hands over the conversation since
the previous delegation: the default for a text frontend, whose context is
current when the tool runs. ExplicitBackendRequestStrategy has the
frontend model word the request itself: the default for a speech-to-speech
frontend, which responds to audio before the transcript of that audio
reaches its context, so the turns that prompted a handoff may not be in the
context yet, and a transcript taken then would miss them.
- class pipecat.pipeline.llm_with_backend.request_strategies.BackendRequestStrategy[source]
Bases:
objectDefines the
delegatetool the frontend calls, and turns a call into the request the backend receives.The tool’s parameters are this strategy’s to declare, so the connector’s handler has one signature and reads whatever was declared back from
params.argumentsincompose_request().- tool_parameters: dict[str, Any] = {}
JSON-schema properties of the
delegatetool; empty when it takes none.
- frontend_instruction: str | None = None
how the request is worded. It goes where the pairing instruction’s
PAIRING_INSTRUCTION_STRATEGY_PLACEHOLDERstands.- Type:
The strategy’s guidance to the frontend model, if any
- requires_context: bool = False
Whether the strategy reads the conversation from the frontend’s context, so it needs that context to be current when the
delegatetool runs. A speech-to-speech frontend’s context lags the audio, so the connector refuses such a strategy there.
- delegate_needs_arguments: bool = True
Whether a
delegatecall has to carry arguments for the request to be built. Predictive delegation makes itsdelegatecall with none, so it works only with a strategy that sets this False.
- async compose_request(params: FunctionCallParams) str | None[source]
Turn a
delegatecall into the text put to the backend.- Parameters:
params – The call, carrying the arguments the tool declared and the frontend’s context.
- Returns:
The request text, or
Nonewhen the call carries nothing new for the backend, in which case nothing is sent.
- class pipecat.pipeline.llm_with_backend.request_strategies.TranscriptBackendRequestStrategy(*, frontend_instruction: str | None = 'A delegation hands over the whole conversation, not one item: the backend reads it and does everything in it that is its job, so delegate once per reply however many things the user asked for, and do not word the request.', tool_description: str = "The only way to start, change or stop the backend's work. Hands the conversation over to the backend, which reads it and does everything in it that needs a backend tool or careful reasoning, and stops or changes what the user has called off or changed. Call it as soon as any part of what the user says concerns that work, even while the backend is still working, and do the rest yourself. Not for a question about how the work is going, which you answer from the backend's notes. One handoff per reply, however many things the user asked for. It takes no arguments. Keep talking with the user while it works.", request_instruction: str = "Act on the user's most recent request in the conversation above. If it asks for something, tell the user the result as soon as you have it, before going on with other work, in a message that begins with >>. If it only stops or changes work already under way, tell them nothing: the assistant already has.")[source]
Bases:
BackendRequestStrategyHands the backend the conversation and lets it work out the request.
The frontend model calls the tool with no arguments; the request is the transcript of what was said since the previous delegation (the whole conversation the first time), rendered by
_render_transcript_request(). The backend’s own messages in the conversation are left out: the backend already has what it said. The default for a text frontend, whose context is current when the tool runs.The cursor assumes the conversation accrues. A rewritten context or a failed delegation’s turns are not re-sent; the user’s next request carries what matters. A call that finds no new turn since the previous delegation sends nothing.
- requires_context: bool = True
Whether the strategy reads the conversation from the frontend’s context, so it needs that context to be current when the
delegatetool runs. A speech-to-speech frontend’s context lags the audio, so the connector refuses such a strategy there.
- delegate_needs_arguments: bool = False
Whether a
delegatecall has to carry arguments for the request to be built. Predictive delegation makes itsdelegatecall with none, so it works only with a strategy that sets this False.
- __init__(*, frontend_instruction: str | None = 'A delegation hands over the whole conversation, not one item: the backend reads it and does everything in it that is its job, so delegate once per reply however many things the user asked for, and do not word the request.', tool_description: str = "The only way to start, change or stop the backend's work. Hands the conversation over to the backend, which reads it and does everything in it that needs a backend tool or careful reasoning, and stops or changes what the user has called off or changed. Call it as soon as any part of what the user says concerns that work, even while the backend is still working, and do the rest yourself. Not for a question about how the work is going, which you answer from the backend's notes. One handoff per reply, however many things the user asked for. It takes no arguments. Keep talking with the user while it works.", request_instruction: str = "Act on the user's most recent request in the conversation above. If it asks for something, tell the user the result as soon as you have it, before going on with other work, in a message that begins with >>. If it only stops or changes work already under way, tell them nothing: the assistant already has.")[source]
Initialize the strategy.
- Parameters:
frontend_instruction – The strategy’s guidance to the frontend model, placed in the pairing instruction: that a delegation hands over the whole conversation, unworded.
tool_description – How the
delegatetool is described.request_instruction – What the backend should do with the transcript, placed after it.
- async compose_request(params: FunctionCallParams) str | None[source]
Render the turns since the previous delegation as the request.
- class pipecat.pipeline.llm_with_backend.request_strategies.ExplicitBackendRequestStrategy(*, frontend_instruction: str | None = "Word the request so it stands on its own: the user's goal, the exact details they gave and their latest correction, with everything new they asked for in the one request, so you delegate once per reply however many things that is. Work already handed over stays with the backend: a new request joins it, so do not restate earlier requests; a correction names what changes, and a stop names what to stop.", tool_description: str = "The only way to start, change or stop the backend's work. Hands a request to the backend, which does everything in it that needs a backend tool or careful reasoning, and stops or changes what the user has called off or changed. Call it as soon as any part of what the user says concerns that work, even while the backend is still working, with the request worded to stand on its own, and do the rest yourself. Not for a question about how the work is going, which you answer from the backend's notes. One call per reply, however many things the user asked for. Work already handed over stays with the backend, so send only what is new, including anything the user says about that work, such as to stop or change it. Keep talking with the user while it works.", request_instruction: str = 'If this request asks for something, tell the user the result as soon as you have it, before going on with other work, in a message that begins with >>. If it only stops or changes work already under way, tell them nothing: the assistant already has.')[source]
Bases:
BackendRequestStrategyHas the frontend model word the request itself.
The tool takes a
requestargument, which is sent to the backend as it stands. The default for a speech-to-speech frontend, which responds to audio before the transcript of that audio reaches its context, so the turns that prompted a handoff may not be recorded when the tool runs.- tool_parameters: dict[str, Any] = {'request': {'description': 'What the user is asking for now, self-contained: their goal, the details they gave (places, dates, names) and their latest correction, or what they said about work already under way, such as to stop it or change it. Work already handed over stays with the backend; a new request joins it, so do not restate earlier requests.', 'type': 'string'}}
JSON-schema properties of the
delegatetool; empty when it takes none.
- __init__(*, frontend_instruction: str | None = "Word the request so it stands on its own: the user's goal, the exact details they gave and their latest correction, with everything new they asked for in the one request, so you delegate once per reply however many things that is. Work already handed over stays with the backend: a new request joins it, so do not restate earlier requests; a correction names what changes, and a stop names what to stop.", tool_description: str = "The only way to start, change or stop the backend's work. Hands a request to the backend, which does everything in it that needs a backend tool or careful reasoning, and stops or changes what the user has called off or changed. Call it as soon as any part of what the user says concerns that work, even while the backend is still working, with the request worded to stand on its own, and do the rest yourself. Not for a question about how the work is going, which you answer from the backend's notes. One call per reply, however many things the user asked for. Work already handed over stays with the backend, so send only what is new, including anything the user says about that work, such as to stop or change it. Keep talking with the user while it works.", request_instruction: str = 'If this request asks for something, tell the user the result as soon as you have it, before going on with other work, in a message that begins with >>. If it only stops or changes work already under way, tell them nothing: the assistant already has.')[source]
Initialize the strategy.
- Parameters:
frontend_instruction – The strategy’s guidance to the frontend model, placed in the pairing instruction: how to word the request.
tool_description – How the
delegatetool is described.request_instruction – What the backend should do with the request, placed after it.
- async compose_request(params: FunctionCallParams) str | None[source]
Send the model’s request as it stands, with the reporting expectation after it.