Skip to content

Feedback to users when the wiring is wrong #5868

@msteiner-google

Description

@msteiner-google

In v 2.0+ if you add an agent as a part of a workflow graph with mode="chat" the node input is silently dropped here.

While I am aware that LLMAgents shouldn't be added with chat mode into the a workflow, I did it by mistake and spent a lot of time figuring out the issue albeit in hindsight was obvious.

This "feature request" is about at least sending a warning to the user so that he/she can notice the problem right away.

Willingness to contribute

Are you interested in implementing this feature yourself or submitting a PR? - Yes


🟡 Recommended Information

Proposed API / Implementation

def prepare_llm_agent_input(agent: Any, ctx: Context, node_input: Any) -> None:
  """Prepares the input for running LlmAgent as a node.

  For ``single_turn`` mode, append a user-role event with the input
  directly to session.events (legacy behavior).

  For ``task`` mode, the input is the parent's task-delegation FC
  args.  Those are NOT appended here — the content-builder
  transforms the originating FC event into a leading user-role
  content at LLM-request time, so it appears as the first turn in
  the task agent's view.  When no originating FC exists (task agent
  dispatched directly as a Workflow node), the wrapper instead
  overrides ``ic.user_content`` so the content-builder can fall back
  to that as the first user turn.

  No branch is set — task and single_turn agents scope via
  ``isolation_scope`` rather than branch.
  """
  # This is the addition
  if node_input is not None and agent.mode == 'chat':
    logger.warn(
      f'The agent {agent.name} has been added to the workflow with '
      f'mode "{agent.mode}". This is not supported and any input '
      'passed by previous nodes will be dropped.'
    ) 
  if node_input is None or agent.mode != 'single_turn':
    return
  agent_input = _node_input_to_content(node_input)
  user_event = Event(author='user', message=agent_input)
  if user_event.content is not None:
    user_event.content.role = 'user'
  iso = getattr(ctx, 'isolation_scope', None)
  if iso:
    user_event.isolation_scope = iso
  ctx.session.events.append(user_event)

Metadata

Metadata

Assignees

Labels

workflow[Component] This issue is related to ADKworkflow
No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions