Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:AGenUI AGenUI Recursive Function Call Resolution

From Leeroopedia
Knowledge Sources
Domains Parsing, UI_Framework
Last Updated 2026-10-24 17:21 GMT

Overview

A recursive resolution technique that walks a JSON payload tree and replaces every nested function-call node with its resolved value, enabling a single JSON literal to carry function calls at any depth.

Description

In the A2UI protocol, function calls are typically expressed as `{"call": "functionName", "args": {...}}` nodes within component attribute JSON. When an attribute value is a complex JSON object (e.g., a data model payload or a custom component property), these function calls may be nested at any depth within the structure.

The `resolveCalls` built-in function implements recursive tree traversal: it walks every node in the provided JSON argument. When it encounters a `{"call": ..., "args": ...}` object, it invokes the `FunctionCallManager` to execute that call and replaces the node with the result. Scalars and non-call objects are passed through untouched. Data bindings (`{"path": ...}`) are deliberately left as-is, since a built-in function call has no data model context to resolve them against.

A call that fails is dropped (returns `nullopt`), causing the parent node to omit that entry — analogous to how `StructuredDataValue` drops an unresolved field. The failure is logged with the node's JSONPath location for debugging.

Usage

Use this principle when:

  • A JSON payload contains function calls at unknown or arbitrary depth
  • A single function call should resolve all nested calls in its argument
  • Failed nested calls should be dropped rather than left as unresolved markers
  • Data bindings in the payload should be preserved for later resolution

Theoretical Basis

The recursive resolution algorithm:

# Abstract algorithm (NOT real implementation)
def resolve_node(node, context, path):
    if is_function_call(node):
        return resolve_call(node, context, path)  # returns value or None (drop)
    elif is_object(node):
        result = {}
        for key, child in node.items():
            resolved = resolve_node(child, context, path + "." + key)
            if resolved is not None:  # skip dropped (failed) calls
                result[key] = resolved
        return result
    elif is_array(node):
        return [resolve_node(child, ...) for child in node if resolved is not None]
    else:
        return node  # scalar: pass through untouched

Practical Guide

  • Use `{"call": "resolveCalls", "args": {"json": <payload>}}` in A2UI protocol to resolve nested calls.
  • The `resolveCalls` builtin is registered automatically during `SurfaceCoordinator` construction.
  • Failed calls are dropped, not left as `null` — design payloads accordingly.
  • Data bindings (`{"path": ...}`) are preserved; resolve them separately in a data-binding context.

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment