Session Data Exit Point
In addition to the Authentication payload, you may want to integrate other user session data from your application. This is done by specifying an exit program, which is a Node.js script that receives something like a session id and returns an object with custom session data from the application.
Client-side code can provide information to the agent via the data
parameter. The agent will pass this information along to the exit point. For example:
profound.ai.startAgent({
agent: "my-assistant.agent.json",
data: () => ({
"sessionId": currentSessionId
})
});
The server-side exit point can process the information as follows:
function sessionExitPoint(data) {
const sessionId = data.sessionId;
const identity = data.identity;
// logic to retrieve session data goes here
return myData;
}
exports.default = sessionExitPoint;
Agent Instructions can access session data through the sessionData
variable. For example:
You are helping ${identity.name} work with customer information.
The current customer number is ${sessionData.customerNumber}.
To access sessionData
within a routine, use pjs.session
. For example: pjs.session.sessionData.customerNumber
.