Implementation:AGenUI AGenUI FunctionCallResolution
| Knowledge Sources | |
|---|---|
| Domains | Software_Architecture, UI_Framework |
| Last Updated | 2026-10-24 17:21 GMT |
Overview
Result type encapsulating the outcome of a function call execution, including status, return value, error message, and async request tracking, provided by the AGenUI C++ core.
Description
The `FunctionCallResolution` class represents the engine-level execution outcome of a function call. It is distinct from `FunctionCallResult` (the platform-level raw return): `FunctionCallResolution` holds a parsed JSON value and has lifecycle awareness for async operations.
The class supports four statuses via named factory methods:
- `createSuccess(value)` — synchronous success with a JSON return value.
- `createError(error)` — execution failure with an error message.
- `createPending(requestId)` — async operation started; not yet complete.
- `createCompleted(requestId, value)` — async operation finished with result.
The `fromPlatformResult()` static method converts a raw `FunctionCallResult` (string-based data from the platform layer) into a `FunctionCallResolution` with parsed JSON, handling empty data as null and invalid JSON as an error.
Usage
- Function call execution: returned by `FunctionCallManager::executeFunctionCallSync()` and `IFunctionCall::execute()`.
- Builtin functions: each builtin returns `FunctionCallResolution::createSuccess()` or `createError()` from its `execute()` method.
- Platform bridge: `fromPlatformResult()` converts platform-level results into engine-level resolutions.
- Async tracking: `isAsync()` / `isCompleted()` query the lifecycle state.
Code Reference
Source Location
- Repository: AGenUI
- Header: core/src/function_call/agenui_functioncall_resolution.h
- Implementation: `core/src/function_call/agenui_functioncall_resolution.cpp` (101 lines)
- Lines: Header L16-101, Implementation L1-101
Signature
// core/src/function_call/agenui_functioncall_resolution.h
namespace agenui {
class FunctionCallResolution {
public:
FunctionCallResolution();
~FunctionCallResolution();
static FunctionCallResolution createSuccess(const nlohmann::json& value);
static FunctionCallResolution createError(const std::string& error);
static FunctionCallResolution createPending(const std::string& requestId);
static FunctionCallResolution createCompleted(const std::string& requestId,
const nlohmann::json& value);
static FunctionCallResolution fromPlatformResult(const FunctionCallResult& platformResult);
nlohmann::json toJson() const;
bool isAsync() const;
bool isCompleted() const;
// Getters
FunctionCallStatus getStatus() const;
const nlohmann::json& getValue() const;
const std::string& getError() const;
const std::string& getRequestId() const;
// Setters
void setStatus(FunctionCallStatus status);
void setValue(const nlohmann::json& value);
void setError(const std::string& error);
void setRequestId(const std::string& requestId);
private:
FunctionCallStatus _status;
nlohmann::json _value;
std::string _error;
std::string _requestId;
};
using ResolutionCallback = std::function<void(const FunctionCallResolution&)>;
} // namespace agenui
Import
#include "function_call/agenui_functioncall_resolution.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| value (createSuccess) | `const nlohmann::json&` | Yes | Return value for successful execution |
| error (createError) | `const std::string&` | Yes | Error message describing failure |
| requestId (createPending) | `const std::string&` | Yes | Identifier for tracking the async request |
| platformResult (fromPlatformResult) | `const FunctionCallResult&` | Yes | Raw platform-level result to convert |
Outputs
| Name | Type | Description |
|---|---|---|
| createSuccess returns | `FunctionCallResolution` | Resolution with Success status and JSON value |
| createError returns | `FunctionCallResolution` | Resolution with Error status and error message |
| createPending returns | `FunctionCallResolution` | Resolution with Pending status and request ID |
| createCompleted returns | `FunctionCallResolution` | Resolution with Completed status, request ID, and value |
| fromPlatformResult returns | `FunctionCallResolution` | Parsed JSON from platform string data; empty data becomes null |
| toJson returns | `nlohmann::json` | JSON with "status", optional "value", "error", "requestId" |
| isAsync returns | `bool` | True if Pending or Completed |
| isCompleted returns | `bool` | True if Success, Error, or Completed |
Usage Examples
Returning a Success Result from a Builtin
#include "function_call/agenui_functioncall_resolution.h"
FunctionCallResolution MyBuiltin::execute(const nlohmann::json& args) {
if (!args.contains("value")) {
return FunctionCallResolution::createError("Missing 'value' parameter");
}
int result = args["value"].get<int>() * 2;
return FunctionCallResolution::createSuccess(result);
}
Converting a Platform Result
// Platform function returns a string-based result
FunctionCallResult platformResult;
platformResult.status = FunctionCallStatus::Success;
platformResult.data = R"({"formatted": "$99.50"})";
// Convert to engine-level resolution with parsed JSON
FunctionCallResolution resolution =
FunctionCallResolution::fromPlatformResult(platformResult);
if (resolution.getStatus() == FunctionCallStatus::Success) {
auto& value = resolution.getValue();
printf("Formatted: %s\n", value["formatted"].get<std::string>().c_str());
}
// Serialize to JSON for protocol response
nlohmann::json json = resolution.toJson();
Checking Async State
FunctionCallResolution res = manager->executeFunctionCallSync("asyncOp", context, args);
if (res.isAsync() && !res.isCompleted()) {
// Pending — need to wait for completion callback
printf("Async request started: %s\n", res.getRequestId().c_str());
} else if (res.getStatus() == FunctionCallStatus::Success) {
// Synchronous success
processResult(res.getValue());
} else {
// Error
printf("Error: %s\n", res.getError().c_str());
}
Related Pages
Implements Principle
Requires Environment
Related Implementations
- Implementation:AGenUI_AGenUI_FunctionCallManager — produces FunctionCallResolution from executeFunctionCallSync()
- Implementation:AGenUI_AGenUI_FunctionCallConfig — companion config type in the dispatch system