Skip to content

TryllAgentComponent

Type: MonoBehaviour
Namespace: Tryll.Client
Source: Runtime/TryllAgentComponent.cs

Manages one TryllAgent lifetime on a GameObject. Drop it on any GameObject to get an agent that connects, creates itself, and fires UnityEvents as tokens arrive — no code required.


Inspector fields

Field Type Default Description
WorkflowAsset TryllWorkflowAsset Workflow graph asset to use. When set, InlineGraphDescription is ignored.
InlineGraphDescription TryllGraphDescription Inline graph used when no WorkflowAsset is assigned. Populate programmatically.
EnableDiagnostics bool false When true, the server includes LLM diagnostic info in TurnComplete payloads.
AutoCreateOnConnect bool true Automatically calls CreateAgent() when TryllClient connects or when this component is enabled while already connected.

Public API

// Runtime state
public TryllAgent Agent   { get; }
public bool       HasAgent { get; }

// Actions
public async void CreateAgent();
public void       DestroyAgent();
public new void   SendMessage(string text);

CreateAgent is ignored when HasAgent is already true. On success it populates Agent and fires OnAgentCreated. On failure it fires OnError and logs to the console.

SendMessage fires OnError and logs a warning if no agent is ready.


Events

Wire these up in the Inspector or call AddListener in code.

Event Signature Description
OnAnswerText (string text, bool isDelta, bool isFinal) Fired for each token chunk. isDelta=true when the chunk is a streaming delta; isFinal=true on the last chunk of the turn.
OnTurnComplete (TryllTurnStatus status, string debugInfo, int tokensGenerated) Fired once per turn after the last OnAnswerText. debugInfo is non-empty only when EnableDiagnostics is true.
OnError (TryllError error) Fired on any agent-level error.
OnAgentCreated UnityEvent Fired when CreateAgent() completes successfully.
OnAgentDestroyed UnityEvent Fired when the agent is destroyed (by this component, by the server, or on disconnect).

Lifetime and ownership

  • The component owns its agent. It calls Agent.Dispose() in OnDisable and OnDestroy.
  • Do not retain the Agent reference beyond the component's lifetime.
  • If you need an agent that outlives the component, create it directly via TryllClient.RequestCreateAgentAsync and manage its lifetime yourself.
  • On disconnect the component clears its local state without sending a DestroyAgent wire message (the TCP connection is gone).

See also