Fold BaseTask.handoff_to into activate_task(deactivate_self=...)
BaseTask.handoff_to was just deactivate_self + activate_task. Remove it and add a deactivate_self flag on activate_task instead, so there's one entry point for activating another task. LLMTask now overrides activate_task (mirroring its end() override) to keep the messages / result_callback hooks that finish an in-progress tool call before the target is activated. All multi-task examples and unit tests switch to the new call.
This commit is contained in:
@@ -68,7 +68,7 @@ uv run local-handoff/local-handoff-two-agents.py --transport daily
|
||||
|
||||
### Overview
|
||||
|
||||
- **[`local-handoff-two-agents.py`](local-handoff/local-handoff-two-agents.py)** — Two LLM tasks (greeter + support) that hand off via `BaseTask.handoff_to(...)`. The main task owns STT, TTS, transport, and a `BusBridgeProcessor`.
|
||||
- **[`local-handoff-two-agents.py`](local-handoff/local-handoff-two-agents.py)** — Two LLM tasks (greeter + support) that hand off via `activate_task(..., deactivate_self=True)`. The main task owns STT, TTS, transport, and a `BusBridgeProcessor`.
|
||||
- **[`local-handoff-two-agents-tts.py`](local-handoff/local-handoff-two-agents-tts.py)** — Same shape, but each child task ships with its own `CartesiaTTSService` in a custom pipeline. The main task has no TTS — audio comes from whichever child is active over the bus.
|
||||
|
||||
## Parallel debate
|
||||
|
||||
@@ -122,11 +122,10 @@ class AcmeLLMTask(LLMTask):
|
||||
reason (str): Why the user is being transferred.
|
||||
"""
|
||||
logger.info(f"Task '{self.name}': transferring to '{agent}' ({reason})")
|
||||
await self.handoff_to(
|
||||
await self.activate_task(
|
||||
agent,
|
||||
activation_args=LLMTaskActivationArgs(
|
||||
messages=[{"role": "developer", "content": reason}]
|
||||
),
|
||||
args=LLMTaskActivationArgs(messages=[{"role": "developer", "content": reason}]),
|
||||
deactivate_self=True,
|
||||
result_callback=params.result_callback,
|
||||
)
|
||||
|
||||
|
||||
@@ -104,11 +104,10 @@ class AcmeLLMTask(LLMTask):
|
||||
reason (str): Why the user is being transferred.
|
||||
"""
|
||||
logger.info(f"Task '{self.name}': transferring to '{agent}' ({reason})")
|
||||
await self.handoff_to(
|
||||
await self.activate_task(
|
||||
agent,
|
||||
activation_args=LLMTaskActivationArgs(
|
||||
messages=[{"role": "developer", "content": reason}]
|
||||
),
|
||||
args=LLMTaskActivationArgs(messages=[{"role": "developer", "content": reason}]),
|
||||
deactivate_self=True,
|
||||
result_callback=params.result_callback,
|
||||
)
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ class AcmeTTSTask(LLMTask):
|
||||
reason (str): Why the user is being transferred.
|
||||
"""
|
||||
logger.info(f"Task '{self.name}': transferring to '{agent}' ({reason})")
|
||||
await self.handoff_to(
|
||||
await self.activate_task(
|
||||
agent,
|
||||
messages=[
|
||||
{
|
||||
@@ -114,9 +114,10 @@ class AcmeTTSTask(LLMTask):
|
||||
"content": f"Tell the user about the transfer ({reason}).",
|
||||
}
|
||||
],
|
||||
activation_args=LLMTaskActivationArgs(
|
||||
args=LLMTaskActivationArgs(
|
||||
messages=[{"role": "developer", "content": reason}],
|
||||
),
|
||||
deactivate_self=True,
|
||||
result_callback=params.result_callback,
|
||||
)
|
||||
|
||||
|
||||
@@ -85,11 +85,12 @@ class AcmeLLMTask(LLMTask):
|
||||
reason (str): Why the user is being transferred.
|
||||
"""
|
||||
logger.info(f"Task '{self.name}': transferring to '{agent}' ({reason})")
|
||||
await self.handoff_to(
|
||||
await self.activate_task(
|
||||
agent,
|
||||
activation_args=LLMTaskActivationArgs(
|
||||
args=LLMTaskActivationArgs(
|
||||
messages=[{"role": "developer", "content": reason}],
|
||||
),
|
||||
deactivate_self=True,
|
||||
result_callback=params.result_callback,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user