halo - v1.0.0
    Preparing search index...

    Class AgentSession

    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.

    const session = new AgentSession({
    platform: "web",
    });
    Index

    Constructors

    • Creates a new session with the specified configuration.

      Parameters

      • config: SessionConfig

        The configuration for the session, including the platform.

      Returns AgentSession

    Methods

    • Retrieves the conversation history from a JSON file. The history is sorted by message timestamp and response timestamp.

      Parameters

      • filePath: string

        The path to the JSON file containing the conversation history.

      Returns Promise<CoreMessage[]>

      An array of CoreMessage objects representing the conversation history.

    • Retrieves user data from a JSON file. If the user exists, it returns the user data; otherwise, it returns null.

      Parameters

      • user: UserBase

        The user object containing the phone number to search for.

      Returns Promise<null | UserBase>

      The user data if found, or null if not found.

    • 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.

      Parameters

      • params: { folderName: string; sessionFileNameSuffix?: string; user: UserBase }
        • folderName: string

          The name of the folder where session files are stored. This is required to create or resume a session.

        • OptionalsessionFileNameSuffix?: string

          The 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.

        • user: UserBase

          The user for whom the session is being started. This is required to create or resume a session.

      Returns Promise<SessionResult>

      An object containing the user and the session history.

      An error if the user is not provided or if the session file cannot be created or resumed.

      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.

      Parameters

      • user: { user: UserBase }

        The user for whom the session is being started.

        • user: UserBase

          The user for whom the session is being started. This is required to create or resume a session.

      Returns Promise<SessionResult>

      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(),
      });