google / google/adk-docs

Transfer_to_agent does not actually transfer?

Open
#644 14 comments 2 reactions 1 assignee Assigned to @joefernandez View on GitHub
Dominant language
Shell
Stars
1.5k
Forks
1.3k
Avg merge
7d 1h
Merged PRs (30d)
34

Description

**Describe the bug**
I'm trying to build a `CustomAgent` by extending the `BaseAgent` class and adding a few subagents. In particular I want this custom agent to orchestrate manually between the different agents that I have. The `EventActions` parameter `transfer_to_agent` does not work, it does nothing.

**To Reproduce**
The only problem is that doing something like:

```
class Orchestrator(BaseAgent):
# Define fields with type hints
name: str
description: str

def __init__(
self,
name: str | None = None,
description: str | None = None,
report_planner: LlmAgent | None = None,
report_executor: LlmAgent | None = None,
report_aggregator: LlmAgent | None = None,
# Add **kwargs to capture any other arguments BaseAgent might need
**kwargs: Any
):

# Determine the final values for initialization
# Use passed values or defaults (including class-level defaults for name/description)
final_name = name if name is not None else "RecursiveOrchestrator"
final_description = description if description is not None else "Manages task planning, execution, decomposition, and aggregation."
# Ensure sub-agents are instantiated here if not passed in
report_planner = report_planner if report_planner is not None else PlannerAgent()
final_sub_agents_list = [report_planner]

super().__init__(
name=final_name,
description=final_description,
#Pass the list of top-level sub-agents this orchestrator uses
sub_agents=final_sub_agents_list,
**kwargs
)

async def _run_async_impl(self, ctx: InvocationContext) -> AsyncGenerator[Event, None]:
"""
Main entry point for the recursive orchestrator.
Handles initial setup and recursive task processing.
"""
initial_task = ctx.session.events[0].content.parts[0].text
logger.info(f"Initial task: {initial_task}")
# Create a response event
response_text = f"Processing task: {initial_task}"
yield Event(
author=self.name,
actions=EventActions(transfer_to_agent=self.find_sub_agent("PlannerAgent").name)
)

```

This will just return an EventActions object but will not actually transfer to the agent. How can I fix? Or am I doing something wrong...
**Expected behavior**
It should handoff to another agent and that should take over, but it does not...

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.