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

Implementation:AGenUI AGenUI ResolveCallsFunctionCall

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

Overview

Built-in `resolveCalls` function that recursively walks a JSON payload, replacing every nested function-call node with its resolved value, provided by the AGenUI C++ core.

Description

The `ResolveCallsFunctionCall` is a C++ built-in function (subclass of `IFunctionCall`) registered automatically during `SurfaceCoordinator::initFunctionCalls()`. It receives a `FunctionCallManager*` pointer in its constructor, which it uses to recursively resolve nested function calls.

The function takes a JSON argument with a `json` field containing the payload to resolve. The `execute(args, context)` method walks the payload tree:

  • Scalars are returned untouched (a `{"path":...}` binding object stays as-is — built-in function calls have no data model context to resolve bindings).
  • Function call objects (`{"call": "name", "args": {...}}`) are resolved by calling `FunctionCallManager::executeFunctionCallSync(name, context, args)`. The node is replaced with the result.
  • Failed calls are dropped (returned as `nullopt`), causing the parent node to omit that entry. The failure is logged with the node's JSONPath location.
  • Objects and arrays are traversed recursively, with each child resolved.

A nested `resolveCalls` is resolved in-place rather than routed through the manager again, so its payload is walked once instead of twice.

The `execute(args)` (context-less) overload delegates to the context-aware one, but since `FunctionCallManager` always calls the context-aware version, the context-less path is only reached by direct callers.

Usage

  • In A2UI protocol: use `{"call": "resolveCalls", "args": {"json": <payload>}}` to resolve all nested function calls in a JSON literal.
  • Auto-registered: no host action needed; registered with 14 other builtins during `SurfaceCoordinator` construction.
  • Data bindings preserved: `{"path":...}` nodes are left as-is for later resolution in a data-binding context.

Code Reference

Source Location

  • Repository: AGenUI
  • Header: `core/src/function_call/builtins/agenui_resolve_calls_functioncall.h:L22-70`
  • Implementation: `core/src/function_call/builtins/agenui_resolve_calls_functioncall.cpp` (153 lines)
  • Registration: `core/src/surface/agenui_surface_coordinator.cpp:L254`

Signature

// core/src/function_call/builtins/agenui_resolve_calls_functioncall.h
namespace agenui {

class ResolveCallsFunctionCall : public IFunctionCall {
public:
    // Constructor receives the FunctionCallManager for recursive resolution
    // The manager outlives this object (it is the one holding it)
    explicit ResolveCallsFunctionCall(FunctionCallManager* manager);

    // Context-less overload (defers to context-aware)
    FunctionCallResolution execute(const nlohmann::json& args) override;

    // Context-aware overload (FunctionCallManager always calls this)
    FunctionCallResolution execute(const nlohmann::json& args,
                                   const FunctionCallContext& context) override;

    FunctionCallConfig getConfig() const override;

private:
    // Walk one node, resolving if it's a function call, descending otherwise
    // Returns nullopt when a call failed (caller drops it)
    std::optional<nlohmann::json> resolveNode(const nlohmann::json& node,
                                              const FunctionCallContext& context,
                                              const std::string& path) const;

    // Resolve one {"call":..., "args":...} node
    std::optional<nlohmann::json> resolveCall(const nlohmann::json& node,
                                              const FunctionCallContext& context,
                                              const std::string& path) const;

    FunctionCallManager* _manager;
};

} // namespace agenui

Import

#include "function_call/builtins/agenui_resolve_calls_functioncall.h"

I/O Contract

Inputs

Name Type Required Description
args["json"] `nlohmann::json` Yes The JSON payload to recursively resolve
context `FunctionCallContext` Yes {instanceId, surfaceId} passed to nested calls

Outputs

Name Type Description
execute returns Success with resolved JSON, or Error
Nested calls Each {"call":...} node replaced with its resolved value
Failed calls Failed nested calls are omitted from the result
Data bindings {"path":...} nodes left as-is (no data model context)

Usage Examples

Using resolveCalls in A2UI Protocol

{
    "component": "Text",
    "id": "t1",
    "text": {
        "call": "resolveCalls",
        "args": {
            "json": {
                "greeting": {"call": "formatString", "args": {"template": "Hello, {0}!", "args": [{"path": "user.name"}]}},
                "total": {"call": "formatCurrency", "args": {"value": {"path": "order.total"}, "currency": "USD"}}
            }
        }
    }
}

The `resolveCalls` builtin will:

  1. Walk the `json` object
  2. Find `{"call": "formatString", ...}` → resolve via FunctionCallManager → replace with result
  3. Find `{"call": "formatCurrency", ...}` → resolve via FunctionCallManager → replace with result
  4. Leave `{"path": "user.name"}` and `{"path": "order.total"}` untouched (data bindings)
  5. Return the resolved object: `{"greeting": "Hello, Alice!", "total": "$99.50"}`

Manual Invocation (SDK Internal)

// Registered during SurfaceCoordinator construction:
fcManager->registerFunctionCall(
    std::make_shared<ResolveCallsFunctionCall>(fcManager));

// Called during expression evaluation:
auto resolution = fcManager->executeFunctionCallSync(
    "resolveCalls",
    context,
    nlohmann::json{{"json", payloadWithNestedCalls}}
);
// resolution.getValue() now contains the resolved payload

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

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