Connect and Manage a Session¶
Open a connection to a running Tryll server, handle reconnection, and shut down cleanly.
Prerequisites
- The Tryll server is running and reachable — see Run the Tryll Server.
- You know the host and port (default
127.0.0.1:9100).
Steps¶
from tryll_client import TryllClient, TryllError, InferenceEngine
# 1. Open the socket. Blocks briefly until SessionReady arrives.
client = TryllClient.connect("127.0.0.1", 9100)
# 2. Pick the inference engine for this session.
# Affects agents you create *after* this call.
try:
client.configure_session(InferenceEngine.LlamaCpp)
except TryllError as e:
print(f"configure failed: {e}")
raise
# 3. Do your work — create storages, agents, send messages.
# See build-chat-agent-with-graph.md for the next step.
# 4. Clean shutdown.
client.shutdown()
#include <tryll/TryllClient.h>
namespace TC = Tryll::Client;
try
{
auto client = Tryll::TryllClient::Connect("127.0.0.1", 9100);
client.ConfigureSession(TC::InferenceEngine::LlamaCpp);
// ... create agents, send messages ...
client.Shutdown();
}
catch (const Tryll::TryllError& ex)
{
// ex.GetCode() is an ErrorCode; see reference/error-codes.md
std::cerr << "session error " << ex.GetCode()
<< ": " << ex.what() << "\n";
}
In Blueprint: on Event BeginPlay, get the
UTryllSubsystem and call Connect. Bind
On Connection Changed — when bConnected = true, call
Configure Session with your chosen ETryllInferenceEngine
and wait for On Configure Session Complete.
In C++, the same subsystem API is available:
Handle reconnection¶
If the socket drops (server restart, network blip, etc.), the server destroys every agent and storage the session owned. The client libraries surface this as a connection-changed event or an async error:
- Python / C++: catch the
TryllErrorfrom the next request and callTryllClient.connect(...)/Tryll::TryllClient::Connect(...)again to make a fresh client. The old client's storages and agents are gone; re-create them. - Unreal: bind
OnConnectionChanged(false)to a handler that re-callsConnectafter a short delay.
There is no server-side session persistence. Everything is rebuilt from scratch on reconnect.
Session lifetime rules to remember¶
ConfigureSessionis idempotent and can be called repeatedly. It only affects futureCreateAgentcalls — existing agents keep their engine.- String storages and embedded string storages die with the session.
- Model downloads and loads are global, not per-session. Pinning a model in one session keeps it warm for all sessions.
- Agent ids are session-scoped. A stored
agent_idis meaningless after reconnect.
See Lifetime and Ownership for the full picture of what survives session close and what does not.
Verify it worked¶
Connecting and configuring produces these server-side log lines (at
info level):
If you do not see a configure line, check that
OnConfigureSessionComplete fired with bSuccess = true on the
client. A failure is almost always a server-side inference-engine
issue — see error codes 2xxx.