Creates a new session with the specified configuration.
The configuration for the session, including the platform.
Retrieves the conversation history from a JSON file. The history is sorted by message timestamp and response timestamp.
The path to the JSON file containing the conversation history.
An array of CoreMessage objects representing the conversation history.
Starts a new session for the user. If the session file does not exist, it creates a new one. If it exists, it resumes the session from the file.
The name of the folder where session files are stored. This is required to create or resume a session.
OptionalsessionFileNameSuffix?: stringThe name of the session file. If not provided, it defaults to a combination of the sessionFilePrefix and the user's username, email, phone, or name.
The user for whom the session is being started. This is required to create or resume a session.
An object containing the user and the session history.
const agentSession = new AgentSession({
platform: "test",
});
const { user, session, saveHistory } = await agentSession.useJSONFileSession({
folderName: "sessions",
sessionFileNameSuffix: "testuser",
user: {
username: "testuser",
email: "testuser@example.com"
}
});
const userMessage = await Question("[You]");
await saveHistory<string>({
role: "user",
text: userMessage,
timestamp: Time.getCurrentTime(),
});
Starts a new session for the user using in-memory storage. This method is useful for quick sessions that do not require persistent storage.
An object containing the user and the session history.
const agentSession = new AgentSession({
platform: "test",
});
const { user, session, saveHistory } = await agentSession.useMemorySession({
user: {
username: "testuser",
email: "testuser@example.com"
}
});
const userMessage = await Question("[You]");
await saveHistory<string>({
role: "user",
text: userMessage,
timestamp: Time.getCurrentTime(),
});
Represents a session for an AI agent. This class is used to manage the session configuration and operations. It can be extended to implement specific session functionalities.
Example