Skip to content

Transfer_to_agent does not actually transfer? #367

@salzubi401

Description

@salzubi401

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...

Metadata

Metadata

Assignees

Labels

documentation[Component] This issue is related to documentation, it will be transferred to adk-docs

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions