Skip to main content

Signature

agentrein.newSession(options?: SessionOptions | string): Promise<Session>

Parameters

ParameterTypeRequiredDescription
options.agentIdstringNoDeveloper-defined identifier for the agent. Defaults to a random UUID.
options.intentstringNoNatural language description of what this session is trying to accomplish. Used by drift detection.

Returns

interface Session {
  id: string;
  organizationId: string;
  agentId: string;
  intent: string | null;
  status: string;
  createdAt: string;
  updatedAt: string;
}

Example

const session = await agentrein.newSession({
  agentId: 'billing-agent',
  intent: 'Create an invoice for customer cus_xxx and notify them on Slack',
});
newSession() must always be awaited and will throw AgentReinUnavailableError if authentication with the AgentRein server fails (e.g. invalid API key, server down during token exchange). If auth succeeds but session creation fails due to a network error, an AxiosError is thrown. A session ID is required for all subsequent call() and completeSession() calls.