Skip to content

refactor: consolidate agent node input conversion into a helper and add validation test coverage#991

Open
hanorik wants to merge 1 commit into
v2from
hanorik/agent_node_input_validation
Open

refactor: consolidate agent node input conversion into a helper and add validation test coverage#991
hanorik wants to merge 1 commit into
v2from
hanorik/agent_node_input_validation

Conversation

@hanorik

@hanorik hanorik commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Consolidated AgentNode input validation and conversion logic. Input schemas are now fully integrated with BaseNode, and input data is parsed into genai.Content before invoking the wrapped agent.

Key Changes

  • Schema Handling: Removed local inputSchema / outputSchema fields from AgentNode. These schemas now reside entirely in BaseNode and are passed via the constructor.
  • Input Conversion Helper: Introduced nodeInputToContent, which handles:
    • nil
    • *genai.Content
    • string
    • json.Marshaler
    • Fallback/default types (struct / map / list / primitives) using JSON marshaling.
  • AgentNode Execution: AgentNode.Run converts the validated input into a *genai.Content and passes it to the wrapped agent, which observes it as InvocationContext.UserContent().

Tests Added

  • Struct input → JSON text part is delivered to the agent.
  • String input → Text part is delivered directly.
  • Nil input → Agent runs without overriding the user-content.
  • Input fails InputSchema validation → Scheduler rejects the activation, and the agent is never invoked.

@hanorik hanorik requested a review from wolo-lab June 9, 2026 14:25
Comment thread workflow/agent_node.go
Parts: []*genai.Part{{Text: string(b)}},
}
}
if userContent == nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove this fallback. Is there a strong reason to keep it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that there might be situations when agent node could receive nil input so the agent could reference the original UserContent rather than being invoked with completely empty context, wdyt?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please verify what adk python does in this scenario.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that they don't fallback and just provide None input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants