asNode

fun BaseTool.asNode(name: String = this.name, config: NodeConfig = NodeConfig()): Node

Returns a workflow node that runs this tool as a fixed step: the predecessor's output becomes the tool's arguments, and the tool's result becomes the node's output.

Use it to put an existing tool into a graph, such as an MCP tool or an agent wrapped as a tool.

Tools that run inside the model. Some tools, such as Google Search, URL context and Vertex AI Search, work only inside a model call and have no local implementation, so running one as a node fails the node. To use such a tool in a graph, give it to an LlmAgent and use that agent as the node.

Input. The node accepts:

  • a map of arguments;

  • a string, or a Content, whose text is a JSON object;

  • null, or a string or Content whose text is blank or the JSON literal null, which calls the tool with no arguments.

Anything else fails the node, including plain text that is not JSON, a JSON array, and a number. A required parameter that the input lacks is read from session state when state holds that key, as in Python ADK.

Validation. The node declares no input or output schema and checks the arguments against none. The tool validates its own arguments in BaseTool.run, as it does when a model calls it.

Output. The tool's return value, unchanged, is the node's output; a tool that returns nothing, including a long-running tool that defers its result, gives the node no output. The tool's state and artifact changes travel on the node's output event. Actions that only a model call can honor are dropped: a confirmation request, an agent transfer, and the skip-summarization flag.

Errors. An exception the tool throws fails the node, and the retry policy in config applies. A retry runs the tool again, so a tool with side effects should be safe to repeat. A tool may instead report a problem, such as a missing required parameter, by returning an error map for a model to read. In a graph no model reads it: the error map becomes the node's output and reaches the next node like any other value. A tool that requires confirmation returns its placeholder error the same way.

Identity. Each call returns a new node. To use one tool at several places in a graph, convert it once and reuse the returned node: two conversions share the tool's name, and a graph rejects two distinct nodes with the same name.

The tool receives a function call id generated for each run, because no model call produced one.

Parameters

name

the node's name. Defaults to the tool's name, which must then be a valid node name: no /, @ or ..

config

the node's retry policy and execution timeout.