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 IFunctionCall

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

Overview

Abstract base class for C++ built-in function calls in the AGenUI SDK, defining the `execute` interface that all built-in functions implement.

Description

The `IFunctionCall` interface is the contract for all C++ built-in function calls. It is subclassed to create specific builtins (e.g., `FormatStringFunctionCall`, `RequiredFunctionCall`, `ResolveCallsFunctionCall`). Instances are registered as `shared_ptr<IFunctionCall>` (aliased as `FunctionCallPtr`) in the `FunctionCallManager`.

The interface has two `execute` overloads:

  • `execute(args)`: the basic pure-virtual method. Takes a JSON argument object and returns a `FunctionCallResolution`.
  • `execute(args, context)`: the context-aware overload. `FunctionCallManager` always calls this one. The default implementation defers to `execute(args)`, so a pure function of its arguments needs no change. Override when the result depends on the invocation site (e.g., `resolveCalls` needs the `FunctionCallManager` for recursive resolution, platform-service functions need `instanceId`).

The `getConfig()` method returns a `FunctionCallConfig` with namespace, name, description, and returnType. The `getName()` and `getFullName()` helpers extract the short and fully-qualified names from the config.

The 15 built-in C++ functions are:

  • Formatters: `formatString`, `formatNumber`, `formatCurrency`, `formatDate`, `pluralize`, `parseToken`
  • Validators: `required`, `regex`, `length`, `numeric`, `email`
  • Logic: `and`, `or`, `not`
  • Special: `resolveCalls` (recursive resolution, receives `FunctionCallManager*`)

Usage

  • Creating a builtin: subclass `IFunctionCall`, implement `execute(args)` and `getConfig()`.
  • Context-aware builtin: override `execute(args, context)` instead, using `context.instanceId` and `context.surfaceId`.
  • Registration: pass `std::make_shared<MyFunctionCall>()` to `FunctionCallManager::registerFunctionCall(FunctionCallPtr)`.

Code Reference

Source Location

  • Repository: AGenUI
  • Interface: `core/src/function_call/agenui_ifunctioncall.h:L17-72`
  • Builtins: `core/src/function_call/builtins/*.cpp` and `.h`

Signature

// core/src/function_call/agenui_ifunctioncall.h
namespace agenui {

class IFunctionCall {
public:
    virtual ~IFunctionCall() = default;

    // Pure virtual: execute with arguments only
    virtual FunctionCallResolution execute(const nlohmann::json& args) = 0;

    // Context-aware overload (FunctionCallManager always calls this one)
    // Default defers to execute(args)
    virtual FunctionCallResolution execute(const nlohmann::json& args,
                                           const FunctionCallContext&) {
        return execute(args);
    }

    // Returns the function call configuration (namespace, name, description, returnType)
    virtual FunctionCallConfig getConfig() const = 0;

    // Short name (from config)
    virtual std::string getName() const { return getConfig().getName(); }

    // Fully qualified name (namespace::name)
    virtual std::string getFullName() const { return getConfig().getFullName(); }
};

using FunctionCallPtr = std::shared_ptr<IFunctionCall>;

} // namespace agenui

Import

#include "function_call/agenui_ifunctioncall.h"

I/O Contract

Inputs

Name Type Required Description
args `const nlohmann::json&` Yes Function arguments as a JSON object
context `const FunctionCallContext&` Yes {instanceId: int, surfaceId: string}

Outputs

Name Type Description
execute returns Status (Success/Error) + JSON value + error message
getConfig returns Namespace, name, description, returnType

Usage Examples

Creating a Custom Builtin Function

#include "function_call/agenui_ifunctioncall.h"
#include "function_call/agenui_functioncall_config.h"
#include "function_call/agenui_functioncall_resolution.h"

class UppercaseFunctionCall : public agenui::IFunctionCall {
public:
    agenui::FunctionCallResolution execute(const nlohmann::json& args) override {
        std::string text = args.value("text", "");
        std::transform(text.begin(), text.end(), text.begin(), ::toupper);
        return agenui::FunctionCallResolution::createSuccess(text);
    }

    agenui::FunctionCallConfig getConfig() const override {
        agenui::FunctionCallConfig config;
        config.setNamespace("myapp");
        config.setName("uppercase");
        config.setDescription("Converts text to uppercase");
        config.setReturnType("string");
        return config;
    }
};

// Register
auto fcManager = engineContext->getFunctionCallManager();
fcManager->registerFunctionCall(std::make_shared<UppercaseFunctionCall>());

// Now A2UI protocol can use: {"call":"uppercase","args":{"text":"hello"}}

Context-Aware Builtin

class SurfaceSizeFunctionCall : public agenui::IFunctionCall {
public:
    // Override the context-aware overload
    agenui::FunctionCallResolution execute(
        const nlohmann::json& args,
        const agenui::FunctionCallContext& context) override {
        // Use context.instanceId and context.surfaceId
        auto size = getSurfaceSize(context.instanceId, context.surfaceId);
        nlohmann::json result = {{"width", size.width}, {"height", size.height}};
        return agenui::FunctionCallResolution::createSuccess(result);
    }

    // Must still implement the pure virtual execute(args)
    agenui::FunctionCallResolution execute(const nlohmann::json& args) override {
        return agenui::FunctionCallResolution::createError("Context required");
    }

    agenui::FunctionCallConfig getConfig() const override {
        agenui::FunctionCallConfig config;
        config.setNamespace("agenui.platform");
        config.setName("surfaceSize");
        config.setDescription("Gets the surface dimensions");
        config.setReturnType("object");
        return config;
    }
};

Related Pages

Implements Principle

Requires Environment

Page Connections

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