Skip to content

TryllClient

Type: MonoBehaviour (singleton)
Namespace: Tryll.Client
Source: Runtime/TryllClient.cs

Singleton MonoBehaviour that manages the TCP session to the Tryll server. Created automatically at game start by TryllClientModule via [RuntimeInitializeOnLoadMethod(BeforeSceneLoad)] — you do not add it to a scene yourself.

In Play mode it lives on a DontDestroyOnLoad GameObject. In the Editor outside Play mode the static helper EnsureEditorInstance() creates a hidden HideAndDontSave instance.


Connection settings

These are read from TryllRuntimeSettings on Awake.

Field Type Default
ServerHost string "127.0.0.1"
ServerPort int 9100

Public API

// Singleton access
public static TryllClient Instance { get; }

// Connection state
public bool  IsConnected { get; }
public ulong SessionId   { get; }

// Connection
public void Connect();
public void Disconnect();

// Session
public void ConfigureSession(TryllInferenceEngine engine,
                             bool allowAutoModelDownloading = false,
                             string gameName = "",
                             TryllInferenceEngine sttEngine       = TryllInferenceEngine.Mock,
                             TryllInferenceEngine ttsEngine       = TryllInferenceEngine.Mock,
                             TryllInferenceEngine embeddingEngine = TryllInferenceEngine.Mock);

// Agent lifecycle — always check error.IsOk before using the agent
public Task<(TryllAgent agent, TryllError error)>
    RequestCreateAgentAsync(TryllGraphDescription graph, bool enableDiagnostics = false);

// Model management
public Task<(List<TryllModelInfo> models, TryllError error)> RequestListModelsAsync();
public void RequestDownloadModel(string modelName);
public void RequestLoadModel(string modelName);
public void RequestUnloadModel(string modelName);

// StringStorage
public Task<TryllError> RequestCreateStringStorageAsync(string name, List<string> strings);
public Task<TryllError> RequestCreateStringStorageFromFileAsync(string name, string filePath);
public Task<TryllError> RequestDestroyStringStorageAsync(string name);

// EmbeddedStringStorage (RAG)
public Task<(EmbeddedStorageInfo info, TryllError error)>
    RequestCreateEmbeddedStringStorageAsync(string name, string configPath, string embeddingModel = "");
public Task<(EmbeddedStorageInfo info, TryllError error)>
    RequestCreateEmbeddedStringStorageFromStringsAsync(string name, List<string> strings, string embeddingModel);
public Task<TryllError> RequestDestroyEmbeddedStringStorageAsync(string name);

// Editor utility
public static TryllClient EnsureEditorInstance();

Events

All events fire on the Unity main thread.

Event Signature Description
ConnectionChanged Action<bool> Connection state changed. Parameter: isConnected.
Error Action<TryllError> Session-level or unroutable error.
ConfigureSessionComplete Action<TryllError> Server acknowledged ConfigureSession.
DownloadProgress Action<string, float> (modelName, percent 0–1) — streaming progress.
DownloadComplete Action<string, bool> (modelName, success) — download finished or failed.
LoadModelComplete Action<string, bool> (modelName, success)
UnloadModelComplete Action<string, bool> (modelName, success)
AgentDestroyed Action<ulong> (agentId) — server confirmed agent teardown.
ToolCallNotification Action<ulong, string, string> (agentId, toolName, argumentsJson)
IntentClassified Action<ulong, string, string, ulong, float> (agentId, intent, recordId, recordIndex, distance)
NodeEvent Action<ulong, string, string, IReadOnlyList<KeyValuePair<string,string>>> Generic fallback for unknown or unsubscribed typed events. (agentId, nodeName, eventType, kvPairs)
StringStorageChanged Action<string, bool> (name, isCreate)
EmbeddedStringStorageChanged Action<string, int, bool> (name, recordCount, isCreate)

EmbeddedStorageInfo

public struct EmbeddedStorageInfo
{
    public string Name;
    public uint   RecordCount;
    public uint   EmbeddingDim;
}

Lifecycle

  1. TryllClientModule creates the singleton at BeforeSceneLoad.
  2. Awake reads TryllRuntimeSettings and applies ServerHost / ServerPort.
  3. Call Connect() to open the TCP session (or enable Auto Launch Server in settings).
  4. Call ConfigureSession(...) to select the inference engine.
  5. Use RequestCreateAgentAsync or attach a TryllAgentComponent.
  6. Call Disconnect() when done, or let OnDestroy clean up on exit.

See also