Skip to content

Class FTryllAgent

ClassList > FTryllAgent

More...

  • #include <TryllAgent.h>

Inherits the following classes: TSharedFromThis< FTryllAgent >, FGCObject

Public Functions

Type Name
virtual void AddReferencedObjects (FReferenceCollector & Collector) override
void AppendInteractions (const TArray< FTryllDialogInteraction > & Interactions, TFunction< void(uint32 Count, const FTryllError &)> OnComplete=nullptr)
void Cancel (ETryllCancelMode Mode=ETryllCancelMode::StopAndKeep)
void ChangeParams (const FString & NodeName, UTryllNodeParamsBase * Params, TFunction< void(const FTryllError &)> OnComplete=nullptr)
void ClearAfterDestroyRequest ()
void ClearPausedToolBatch ()
void DispatchError (const FTryllError & Error) const
void DrainPendingLifecycleCallbacks (const FTryllError & TerminalError)
void EvictKvCache (TFunction< void(const FTryllKvCacheEvictResult &, const FTryllError &)> OnComplete=nullptr)
FTryllAgent (TSharedPtr< FTryllConnection > InConnection, std::uint64_t InAgentId, const TArray< FTryllVariableDecl > & InDeclaredVariables={})
std::uint64_t GetAgentId () noexcept const
const FString & GetDisplayName () const
void GetKvCacheStatus (TFunction< void(const FTryllKvCacheStatus &, const FTryllError &)> OnComplete=nullptr)
UTryllNodeParamsBase * GetNodeParamsBaseline (const FString & NodeName) const
virtual FString GetReferencerName () override const
FTryllAgentVariables & GetVariables () const
void HandleAnswerText (const FString & NodeName, const FString & Text, bool bIsDelta, bool bIsFinal)
void HandleAppendInteractionsResult (std::uint64_t RequestId, uint32 Count, const FTryllError & Error)
void HandleChangeParamResult (std::uint64_t RequestId, const FTryllError & Error)
void HandleError (const FTryllError & Error)
void HandleEvictKvCacheResult (std::uint64_t RequestId, const FTryllKvCacheEvictResult & Result, const FTryllError & Error)
void HandleGetVariablesResult (std::uint64_t RequestId, const TArray< FTryllVariableDecl > & Variables, const FTryllError & Error)
void HandleKvCacheStatusResult (std::uint64_t RequestId, const FTryllKvCacheStatus & Result, const FTryllError & Error)
void HandlePaused (const FString & NodeName)
void HandlePrefillKvCacheResult (std::uint64_t RequestId, const FTryllKvCachePrefillResult & Result, const FTryllError & Error)
void HandleRemoveInteractionsFromEndResult (std::uint64_t RequestId, uint32 Count, const FTryllError & Error)
void HandleResumeResult (std::uint64_t RequestId, const FTryllError & Error)
void HandleToolCall (const FString & CallId, const FString & NodeName, const FString & ToolName, const FString & ArgumentsJson, const FString & Disposition={})
void HandleTtsAudio (const FString & NodeName, TArrayView< const int16 > Pcm)
void HandleTtsAudioFormat (const FString & NodeName, uint32 SampleRate, uint16 Channels, uint16 BitsPerSample)
void HandleTurnComplete (ETryllTurnStatus Status, const FString & DebugInfo, int32 TokensGenerated)
void HandleUpdateVariablesResult (std::uint64_t RequestId, const FTryllError & Error)
bool HasPausedToolBatch () const
bool IsValid () noexcept const
void PrefillKvCache (TFunction< void(const FTryllKvCachePrefillResult &, const FTryllError &)> OnComplete=nullptr)
void RegisterTool (const FString & ToolName, FTryllToolHandler Handler)
void RegisterTool (const FString & ToolName, FTryllSimpleToolHandler Handler)
void RemoveInteractionsFromEnd (int32 Count, TFunction< void(uint32 RemovedCount, const FTryllError &)> OnComplete=nullptr)
void Resume (const FString & ResumeNode=FString{}, TFunction< void(const FTryllError &)> OnComplete=nullptr)
void ResumeWithToolResult (const FTryllToolResult & ToolResult, const FString & ResumeNode=FString{}, TFunction< void(const FTryllError &)> OnComplete=nullptr)
void ResumeWithToolResults (const TArray< FTryllToolResult > & ToolResults, const FString & ResumeNode=FString{}, TFunction< void(const FTryllError &)> OnComplete=nullptr)
void RetryPausedToolBatch ()
void SendGetVariables (TArray< FString > Names, TFunction< void(const TArray< FTryllVariableDecl > &, const FTryllError &)> OnComplete)
void SendMessage (const FString & Text)
void SendUpdateVariables (TArray< FTryllVariableUpdate > Updates, TFunction< void(const FTryllError &)> OnComplete, uint64 CarrierRequestId=0)
void SetCreatedWithDiagnostics (bool bValue)
void SetDisplayName (FString InName)
void SetNodeParamsBaseline (const FString & NodeName, UTryllNodeParamsBase * Params)
void SetOnAnswerText (TFunction< void(const FString &NodeName, const FString &Text, bool bIsDelta, bool bIsFinal)> Callback)
void SetOnError (TFunction< void(const FTryllError &Error)> Callback)
void SetOnToolHandlerError (TFunction< void(const FTryllError &)> Callback)
void SetOnTtsAudio (TFunction< void(const FString &NodeName, TArrayView< const int16 > Pcm)> Callback)
void SetOnTtsAudioFormat (TFunction< void(const FString &NodeName, uint32 SampleRate, uint16 Channels, uint16 BitsPerSample)> Callback)
void SetOnTurnComplete (TFunction< void(ETryllTurnStatus Status, const FString &DebugInfo, int32 TokensGenerated)> Callback)
bool UnregisterTool (const FString & ToolName)
bool WasCreatedWithDiagnostics () noexcept const
~FTryllAgent ()

Detailed Description

Plain C++ handle for a server-side agent. Created by UTryllSubsystem after a successful CreateAgentResponse.

Ownership: typically held as TSharedPtr<FTryllAgent> by UTryllAgentComponent. Lifetime: deterministic — the owning component releases the shared_ptr; this triggers PushDestroyAgent via UTryllSubsystem::RequestDestroyAgent().

All callbacks are invoked on the game thread (from UTryllSubsystem::Tick).

Public Functions Documentation

function AddReferencedObjects

virtual void FTryllAgent::AddReferencedObjects (
    FReferenceCollector & Collector
) override

function AppendInteractions

void FTryllAgent::AppendInteractions (
    const TArray< FTryllDialogInteraction > & Interactions,
    TFunction< void(uint32 Count, const FTryllError &)> OnComplete=nullptr
) 

Append scripted user/assistant interactions without running the graph. Idle-only.


function Cancel

void FTryllAgent::Cancel (
    ETryllCancelMode Mode=ETryllCancelMode::StopAndKeep
) 

Cooperatively cancel the agent's in-flight turn. The turn ends with ETryllTurnStatus::Cancelled via the OnTurnComplete callback. No-op if idle. Mode selects whether the partial interaction is kept (default) or discarded.


function ChangeParams

void FTryllAgent::ChangeParams (
    const FString & NodeName,
    UTryllNodeParamsBase * Params,
    TFunction< void(const FTryllError &)> OnComplete=nullptr
) 

Apply typed node parameters to a workflow node at runtime. The agent must not be processing a turn. Completion is invoked on the game thread via the OnComplete callback.

Clone-set-send idiom (C++): auto* P = UTryllNodeParamsFactory::CloneParams(AgentComp->GetNodeParamsBaseline("gen"), this); Cast<UTryllGenerateParams>(P)->SystemPrompt = TEXT("New prompt"); Agent->ChangeParams(TEXT("gen"), P);


function ClearAfterDestroyRequest

void FTryllAgent::ClearAfterDestroyRequest () 

Called by UTryllSubsystem when the destroy Ack arrives; clears the local agent id.


function ClearPausedToolBatch

void FTryllAgent::ClearPausedToolBatch () 

Discard the retained paused tool-call batch without resuming (terminal disconnect).


function DispatchError

void FTryllAgent::DispatchError (
    const FTryllError & Error
) const

Invoke the OnError callback (if set). Used by FTryllAgentVariables to surface an auto-flush rejection on the agent's normal error path.


function DrainPendingLifecycleCallbacks

void FTryllAgent::DrainPendingLifecycleCallbacks (
    const FTryllError & TerminalError
) 

Fail in-flight KV-cache lifecycle callbacks before the agent handle is cleared.


function EvictKvCache

void FTryllAgent::EvictKvCache (
    TFunction< void(const FTryllKvCacheEvictResult &, const FTryllError &)> OnComplete=nullptr
) 

Release backend KV contexts for every eligible language-model node.


function FTryllAgent

FTryllAgent::FTryllAgent (
    TSharedPtr< FTryllConnection > InConnection,
    std::uint64_t InAgentId,
    const TArray< FTryllVariableDecl > & InDeclaredVariables={}
) 

function GetAgentId

inline std::uint64_t FTryllAgent::GetAgentId () noexcept const

function GetDisplayName

inline const FString & FTryllAgent::GetDisplayName () const

function GetKvCacheStatus

void FTryllAgent::GetKvCacheStatus (
    TFunction< void(const FTryllKvCacheStatus &, const FTryllError &)> OnComplete=nullptr
) 

Query aggregate language-model KV-cache lifecycle state.


function GetNodeParamsBaseline

UTryllNodeParamsBase * FTryllAgent::GetNodeParamsBaseline (
    const FString & NodeName
) const

Return a deep copy of the last authored params for the named node. Use this as the starting point for a clone-set-send mutation; structural fields are automatically propagated from the baseline.


function GetReferencerName

inline virtual FString FTryllAgent::GetReferencerName () override const

function GetVariables

inline FTryllAgentVariables & FTryllAgent::GetVariables () const

Local mirror of this agent's declared per-agent Variables.


function HandleAnswerText

void FTryllAgent::HandleAnswerText (
    const FString & NodeName,
    const FString & Text,
    bool bIsDelta,
    bool bIsFinal
) 

function HandleAppendInteractionsResult

void FTryllAgent::HandleAppendInteractionsResult (
    std::uint64_t RequestId,
    uint32 Count,
    const FTryllError & Error
) 

function HandleChangeParamResult

void FTryllAgent::HandleChangeParamResult (
    std::uint64_t RequestId,
    const FTryllError & Error
) 

Invoked by UTryllSubsystem when a ChangeParamOk or ChangeParamErr arrives.


function HandleError

void FTryllAgent::HandleError (
    const FTryllError & Error
) 

function HandleEvictKvCacheResult

void FTryllAgent::HandleEvictKvCacheResult (
    std::uint64_t RequestId,
    const FTryllKvCacheEvictResult & Result,
    const FTryllError & Error
) 

function HandleGetVariablesResult

void FTryllAgent::HandleGetVariablesResult (
    std::uint64_t RequestId,
    const TArray< FTryllVariableDecl > & Variables,
    const FTryllError & Error
) 

Invoked by UTryllSubsystem when a GetVariablesOk or GetVariablesErr arrives.


function HandleKvCacheStatusResult

void FTryllAgent::HandleKvCacheStatusResult (
    std::uint64_t RequestId,
    const FTryllKvCacheStatus & Result,
    const FTryllError & Error
) 

function HandlePaused

void FTryllAgent::HandlePaused (
    const FString & NodeName
) 

function HandlePrefillKvCacheResult

void FTryllAgent::HandlePrefillKvCacheResult (
    std::uint64_t RequestId,
    const FTryllKvCachePrefillResult & Result,
    const FTryllError & Error
) 

Invoked by UTryllSubsystem when a KV-cache lifecycle response arrives.


function HandleRemoveInteractionsFromEndResult

void FTryllAgent::HandleRemoveInteractionsFromEndResult (
    std::uint64_t RequestId,
    uint32 Count,
    const FTryllError & Error
) 

function HandleResumeResult

void FTryllAgent::HandleResumeResult (
    std::uint64_t RequestId,
    const FTryllError & Error
) 

Invoked by UTryllSubsystem when a ResumeOk or ResumeErr arrives.


function HandleToolCall

void FTryllAgent::HandleToolCall (
    const FString & CallId,
    const FString & NodeName,
    const FString & ToolName,
    const FString & ArgumentsJson,
    const FString & Disposition={}
) 

function HandleTtsAudio

void FTryllAgent::HandleTtsAudio (
    const FString & NodeName,
    TArrayView< const int16 > Pcm
) 

function HandleTtsAudioFormat

void FTryllAgent::HandleTtsAudioFormat (
    const FString & NodeName,
    uint32 SampleRate,
    uint16 Channels,
    uint16 BitsPerSample
) 

function HandleTurnComplete

void FTryllAgent::HandleTurnComplete (
    ETryllTurnStatus Status,
    const FString & DebugInfo,
    int32 TokensGenerated
) 

function HandleUpdateVariablesResult

void FTryllAgent::HandleUpdateVariablesResult (
    std::uint64_t RequestId,
    const FTryllError & Error
) 

Invoked by UTryllSubsystem when an UpdateVariablesOk or UpdateVariablesErr arrives.


function HasPausedToolBatch

inline bool FTryllAgent::HasPausedToolBatch () const

True while a paused tool-call batch is retained: surfaced by the current pause and not yet cleared by a successful resume Ack, turn end/cancel, destroy, or a terminal disconnect. A retained batch may already have some handlers succeeded (see RetryPausedToolBatch).


function IsValid

inline bool FTryllAgent::IsValid () noexcept const

function PrefillKvCache

void FTryllAgent::PrefillKvCache (
    TFunction< void(const FTryllKvCachePrefillResult &, const FTryllError &)> OnComplete=nullptr
) 

Synchronise every eligible language-model context to its reusable prefix.


function RegisterTool [1/2]

void FTryllAgent::RegisterTool (
    const FString & ToolName,
    FTryllToolHandler Handler
) 

Register game-thread tool sugar. A paused batch auto-resumes only when every call has a handler and every handler reports success.


function RegisterTool [2/2]

void FTryllAgent::RegisterTool (
    const FString & ToolName,
    FTryllSimpleToolHandler Handler
) 

function RemoveInteractionsFromEnd

void FTryllAgent::RemoveInteractionsFromEnd (
    int32 Count,
    TFunction< void(uint32 RemovedCount, const FTryllError &)> OnComplete=nullptr
) 

Remove whole interactions from the end of the dialog. count=0 is a no-op. Idle-only.


function Resume

void FTryllAgent::Resume (
    const FString & ResumeNode=FString{},
    TFunction< void(const FTryllError &)> OnComplete=nullptr
) 

Resume a turn that is currently paused (see the Pause node / typed OnNodeEvent event_type="paused" wiring on UTryllSubsystem). ResumeNode empty continues via the paused node's pending exit route; non-empty jumps to that node by name. Completion is invoked on the game thread: nullopt-equivalent (Error.IsOk()) on success, AgentNotPaused (3012) if the agent is not currently paused, or UnknownNode (3005) if ResumeNode does not name a node in the graph.


function ResumeWithToolResult

void FTryllAgent::ResumeWithToolResult (
    const FTryllToolResult & ToolResult,
    const FString & ResumeNode=FString{},
    TFunction< void(const FTryllError &)> OnComplete=nullptr
) 

Resume with one result correlated to a tool-call ID.


function ResumeWithToolResults

void FTryllAgent::ResumeWithToolResults (
    const TArray< FTryllToolResult > & ToolResults,
    const FString & ResumeNode=FString{},
    TFunction< void(const FTryllError &)> OnComplete=nullptr
) 

Resume with the complete result batch for one paused tool-call pass.


function RetryPausedToolBatch

void FTryllAgent::RetryPausedToolBatch () 

Re-attempt the retained paused tool-call batch: handlers that already produced a result on a previous attempt are skipped (not re-run — no duplicate side effects), remaining handlers run, and a fresh Resume is sent. No-op if there is no retained batch (HasPausedToolBatch() is false). Use after OnToolHandlerError reports a failed handler or a rejected/disconnected resume.


function SendGetVariables

void FTryllAgent::SendGetVariables (
    TArray< FString > Names,
    TFunction< void(const TArray< FTryllVariableDecl > &, const FTryllError &)> OnComplete
) 

Send a GetAgentVariablesRequest. Empty Names = every declared variable.


function SendMessage

void FTryllAgent::SendMessage (
    const FString & Text
) 

Send a text message to the agent. Response arrives via the OnAnswerText / OnTurnComplete callbacks.


function SendUpdateVariables

void FTryllAgent::SendUpdateVariables (
    TArray< FTryllVariableUpdate > Updates,
    TFunction< void(const FTryllError &)> OnComplete,
    uint64 CarrierRequestId=0
) 

Send a batched UpdateAgentVariablesRequest (deferred-flush from FTryllAgentVariables::FlushIfDirty).


function SetCreatedWithDiagnostics

inline void FTryllAgent::SetCreatedWithDiagnostics (
    bool bValue
) 

function SetDisplayName

inline void FTryllAgent::SetDisplayName (
    FString InName
) 

Optional editor/display label (e.g. owning actor name). Not on the wire.


function SetNodeParamsBaseline

void FTryllAgent::SetNodeParamsBaseline (
    const FString & NodeName,
    UTryllNodeParamsBase * Params
) 

Store/update the authored params baseline for a node (called by the subsystem).


function SetOnAnswerText

void FTryllAgent::SetOnAnswerText (
    TFunction< void(const FString &NodeName, const FString &Text, bool bIsDelta, bool bIsFinal)> Callback
) 

Streaming text callback. Matches the current AnswerText wire message: * NodeName = the workflow node that produced this chunk (multi-sender attribution; ignore it if the graph only ever has one text-producing node). * bIsDelta = true → Text is an incremental token/chunk. * bIsDelta = false → Text is the full response accumulated so far. * bIsFinal = true → This is the last AnswerText before TurnComplete for this node.


function SetOnError

void FTryllAgent::SetOnError (
    TFunction< void(const FTryllError &Error)> Callback
) 

Called on any send-side error (connection loss, server error response, etc.).


function SetOnToolHandlerError

void FTryllAgent::SetOnToolHandlerError (
    TFunction< void(const FTryllError &)> Callback
) 

Set the callback invoked on the game thread when RegisterTool handler execution or its automatic result-bearing Resume fails. The turn remains paused. Mirrors the Unity client's ToolHandlerError event.


function SetOnTtsAudio

void FTryllAgent::SetOnTtsAudio (
    TFunction< void(const FString &NodeName, TArrayView< const int16 > Pcm)> Callback
) 

Streaming TTS audio callback. Fires for each TtsAudioFrame within a turn. NodeName is the producing node's name (multi-sender attribution). The view references the FTryllConnEvent storage and is valid only for the duration of the callback. End-of-stream is signalled by OnTurnComplete — TtsAudioFrame intentionally carries no is_final field.


function SetOnTtsAudioFormat

void FTryllAgent::SetOnTtsAudioFormat (
    TFunction< void(const FString &NodeName, uint32 SampleRate, uint16 Channels, uint16 BitsPerSample)> Callback
) 

TTS audio format callback. Fires once per turn, before any OnTtsAudio. Parameters: (NodeName, SampleRate, Channels, BitsPerSample). NodeName is the producing node's name (multi-sender attribution — mirrors OnAnswerText). Only mono int16 PCM is currently emitted by the server.


function SetOnTurnComplete

void FTryllAgent::SetOnTurnComplete (
    TFunction< void(ETryllTurnStatus Status, const FString &DebugInfo, int32 TokensGenerated)> Callback
) 

Called once per turn after all AnswerText chunks, carrying the turn outcome. TokensGenerated: server-reported total tokens sampled across all generation nodes in this turn (prompt tokens excluded).


function UnregisterTool

bool FTryllAgent::UnregisterTool (
    const FString & ToolName
) 

Remove a previously registered tool handler.


function WasCreatedWithDiagnostics

inline bool FTryllAgent::WasCreatedWithDiagnostics () noexcept const

function ~FTryllAgent

FTryllAgent::~FTryllAgent () 


The documentation for this class was generated from the following file C:/_tryll/_monorepo3/tryll/clients/unreal/Source/TryllClient/Public/TryllAgent.h