类:VertexAiSessionService

java.lang.Object
com.google.adk.sessions.VertexAiSessionService
All Implemented Interfaces:
BaseSessionService

public final class VertexAiSessionService extends Object implements BaseSessionService
连接到托管的 Vertex AI 会话服务(managed Vertex AI Session Service)。
  • 构造函数详细信息

    • VertexAiSessionService

      public VertexAiSessionService(String project, String location, HttpApiClient apiClient)
      创建一个新的 Vertex AI Session Service 实例,并为其配置一个自定义的 ApiClient 以用于测试。
    • VertexAiSessionService

      public VertexAiSessionService()
      创建一个使用默认配置的会话服务。
    • VertexAiSessionService

      public VertexAiSessionService(String project, String location, @Nullable com.google.auth.oauth2.GoogleCredentials credentials, @Nullable com.google.genai.types.HttpOptions httpOptions)
      创建一个会话服务,该服务使用指定的项目、位置、凭据以及 HTTP 配置选项。
  • 方法详细信息(Method Details)

    • createSession

      public io.reactivex.rxjava3.core.Single<Session> createSession(String appName, String userId, @Nullable ConcurrentMap<String,Object> state, @Nullable String sessionId)
      描述内容复制自接口文档: BaseSessionService
      使用指定的参数创建一个新的会话。
      Specified by:
      createSession in interface BaseSessionService
      Parameters:
      appName - The name of the application associated with the session.
      userId - The identifier for the user associated with the session.
      state - An optional map representing the initial state of the session. Can be null or empty.
      sessionId - An optional client-provided identifier for the session. If empty or null, the service should generate a unique ID.
      Returns:
      The newly created Session instance.
    • createSession

      public io.reactivex.rxjava3.core.Single<Session> createSession(String appName, String userId, @Nullable Map<String,Object> state, @Nullable String sessionId)
      创建一个会话,并发出相应的请求。 sessionId 当给定一个 ID 时,该 ID 就会被用作对象的标识符。这个 ID 必须是非空的,并且必须与对象的实际 ID 相匹配。 [a-zA-Z0-9_-]+如果该参数为空或为 `null`,系统会请求后端为其生成相应的值。

      后端的规则更加严格:允许输入的长度最多为 63 个字符(从……开始计算)。 [a-z0-9-]字符串必须以字母开头,以字母或数字结尾;因此,一些通过验证的字符串会被拒绝。

      Specified by:
      createSession in interface BaseSessionService
      Parameters:
      appName - The name of the application associated with the session.
      userId - The identifier for the user associated with the session.
      state - An optional map representing the initial state of the session. Can be null or empty.
      sessionId - An optional client-provided identifier for the session. If empty or null, the service should generate a unique ID.
      Returns:
      The newly created Session instance.
    • listSessions

      public io.reactivex.rxjava3.core.Single<ListSessionsResponse> listSessions(String appName, String userId)
      描述内容复制自接口文档: BaseSessionService
      列出与特定应用程序和用户关联的会话(session)。

      The Session 响应中的对象通常只包含元数据(如 ID、创建时间等),而不包含完整的事件列表或系统状态,这样有助于优化性能。

      Specified by:
      listSessions in interface BaseSessionService
      Parameters:
      appName - The name of the application.
      userId - The identifier of the user whose sessions are to be listed.
      Returns:
      A ListSessionsResponse containing a list of matching sessions.
    • listEvents

      public io.reactivex.rxjava3.core.Single<ListEventsResponse> listEvents(String appName, String userId, String sessionId)
      描述内容复制自接口文档: BaseSessionService
      列出特定会话中的所有事件。支持通过响应对象实现分页功能。
      Specified by:
      listEvents in interface BaseSessionService
      Parameters:
      appName - The name of the application.
      userId - The identifier of the user.
      sessionId - The unique identifier of the session whose events are to be listed.
      Returns:
      A ListEventsResponse containing a list of events and an optional token for retrieving the next page.
    • getSession

      public io.reactivex.rxjava3.core.Maybe<Session> getSession(String appName, String userId, String sessionId, Optional<GetSessionConfig> config)
      描述内容复制自接口文档: BaseSessionService
      检索特定的会话(session),并可选择性地过滤其中包含的事件(events)。
      Specified by:
      getSession in interface BaseSessionService
      Parameters:
      appName - The name of the application.
      userId - The identifier of the user.
      sessionId - The unique identifier of the session to retrieve.
      config - Optional configuration to filter the events returned within the session (e.g., limit number of recent events, filter by timestamp). If empty, default retrieval behavior is used (potentially all events or a service-defined limit).
      Returns:
      An Optional containing the Session if found, otherwise Optional.empty().
    • deleteSession

      public io.reactivex.rxjava3.core.Completable deleteSession(String appName, String userId, String sessionId)
      描述内容复制自接口文档: BaseSessionService
      删除特定的会话。
      Specified by:
      deleteSession in interface BaseSessionService
      Parameters:
      appName - The name of the application.
      userId - The identifier of the user.
      sessionId - The unique identifier of the session to delete.
    • appendEvent

      public io.reactivex.rxjava3.core.Single<Event> appendEvent(Session session, Event event)
      描述内容复制自接口文档: BaseSessionService
      将一个事件添加到内存中的会话对象中,并根据该事件的状态变化(如果适用的话)更新会话的状态。

      此方法主要修改传入的参数(即 `passed` 参数)。 session 这些数据存储在内存中。要使这些更改持久化(即让它们在系统重启后仍然存在),通常需要调用特定服务提供的 `update` 或 `save` 方法;不过,根据该服务的实现方式,这一过程也可能被隐式地完成(即无需用户进行任何操作)。

      如果该事件被标记为“部分完成”(例如:……), event.isPartial() == true当数据被返回时,它会直接被发送出去,而不会修改会话状态或事件列表。以 “State delta keys starting with” 开头的键用于表示状态变化的相关信息。 State.TEMP_PREFIX 在状态更新过程中,这些内容会被忽略。

      Specified by:
      appendEvent in interface BaseSessionService
      Parameters:
      session - The Session object to which the event should be appended (will be mutated).
      event - The Event to append.
      Returns:
      The appended Event instance (or the original event if it was partial).