类:VertexAiSessionService
java.lang.Object
com.google.adk.sessions.VertexAiSessionService
- All Implemented Interfaces:
BaseSessionService
连接到托管的 Vertex AI 会话服务(managed Vertex AI Session Service)。
-
构造函数概述
ConstructorsConstructorDescription创建一个使用默认配置的会话服务。VertexAiSessionService(String project, String location, HttpApiClient apiClient) 创建一个新的 Vertex AI Session Service 实例,并为其配置一个自定义的 ApiClient 以用于测试。VertexAiSessionService(String project, String location, @Nullable com.google.auth.oauth2.GoogleCredentials credentials, @Nullable com.google.genai.types.HttpOptions httpOptions) 创建一个会话服务,该服务使用指定的项目、位置、凭据以及 HTTP 配置选项。 -
方法概述
Modifier and TypeMethodDescriptionio.reactivex.rxjava3.core.Single<Event> appendEvent(Session session, Event event) 将一个事件添加到内存中的会话对象中,并根据该事件的状态变化(如果适用的话)更新会话的状态。io.reactivex.rxjava3.core.Single<Session> createSession(String appName, String userId, @Nullable Map<String, Object> state, @Nullable String sessionId) 创建一个会话,并发出相应的请求。sessionId当给定某个值时,该值会被用作其 ID。io.reactivex.rxjava3.core.Single<Session> createSession(String appName, String userId, @Nullable ConcurrentMap<String, Object> state, @Nullable String sessionId) 使用指定的参数创建一个新的会话。io.reactivex.rxjava3.core.CompletabledeleteSession(String appName, String userId, String sessionId) 删除特定的会话。io.reactivex.rxjava3.core.Maybe<Session> getSession(String appName, String userId, String sessionId, Optional<GetSessionConfig> config) 检索特定的会话(session),并可选择性地过滤其中包含的事件(events)。io.reactivex.rxjava3.core.Single<ListEventsResponse> listEvents(String appName, String userId, String sessionId) 列出特定会话中的所有事件。io.reactivex.rxjava3.core.Single<ListSessionsResponse> listSessions(String appName, String userId) 列出与特定应用程序和用户关联的会话(session)。Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BaseSessionService
closeSession, createSession, createSession, createSession, deleteSession, getSession, listEvents, listSessionsModifier and TypeMethodDescriptiondefault io.reactivex.rxjava3.core.CompletablecloseSession(Session session) 关闭会话。default io.reactivex.rxjava3.core.Single<Session> createSession(SessionKey sessionKey) 使用指定的应用程序名称和用户 ID 创建一个新的会话,会话初始状态为默认值(null),并允许服务自动生成一个唯一的会话 ID。default io.reactivex.rxjava3.core.Single<Session> createSession(SessionKey sessionKey, @Nullable Map<String, Object> state) 使用指定的参数创建一个新的会话。default io.reactivex.rxjava3.core.Single<Session> createSession(String appName, String userId) 使用指定的应用程序名称和用户 ID 创建一个新的会话,会话初始状态为默认值(null),并允许服务自动生成一个唯一的会话 ID。default io.reactivex.rxjava3.core.CompletabledeleteSession(SessionKey sessionKey) 删除特定的会话。default io.reactivex.rxjava3.core.Maybe<Session> getSession(SessionKey sessionKey, @Nullable GetSessionConfig config) 检索特定的会话(session),并可选择性地过滤其中包含的事件(events)。default io.reactivex.rxjava3.core.Single<ListEventsResponse> listEvents(SessionKey sessionKey) 列出特定会话中的所有事件。default io.reactivex.rxjava3.core.Single<ListSessionsResponse> listSessions(SessionKey sessionKey) 列出与特定应用程序和用户关联的会话(session)。
-
构造函数详细信息
-
VertexAiSessionService
创建一个新的 Vertex AI Session Service 实例,并为其配置一个自定义的 ApiClient 以用于测试。 -
VertexAiSessionService
public VertexAiSessionService()创建一个使用默认配置的会话服务。 -
VertexAiSessionService
-
-
方法详细信息(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:
createSessionin interfaceBaseSessionService- 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
Sessioninstance.
-
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:
createSessionin interfaceBaseSessionService- 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
Sessioninstance.
-
listSessions
public io.reactivex.rxjava3.core.Single<ListSessionsResponse> listSessions(String appName, String userId) 描述内容复制自接口文档:BaseSessionService列出与特定应用程序和用户关联的会话(session)。The
Session响应中的对象通常只包含元数据(如 ID、创建时间等),而不包含完整的事件列表或系统状态,这样有助于优化性能。- Specified by:
listSessionsin interfaceBaseSessionService- Parameters:
appName- The name of the application.userId- The identifier of the user whose sessions are to be listed.- Returns:
- A
ListSessionsResponsecontaining a list of matching sessions.
-
listEvents
public io.reactivex.rxjava3.core.Single<ListEventsResponse> listEvents(String appName, String userId, String sessionId) 描述内容复制自接口文档:BaseSessionService列出特定会话中的所有事件。支持通过响应对象实现分页功能。- Specified by:
listEventsin interfaceBaseSessionService- 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
ListEventsResponsecontaining 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:
getSessionin interfaceBaseSessionService- 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
Optionalcontaining theSessionif found, otherwiseOptional.empty().
-
deleteSession
public io.reactivex.rxjava3.core.Completable deleteSession(String appName, String userId, String sessionId) 描述内容复制自接口文档:BaseSessionService删除特定的会话。- Specified by:
deleteSessionin interfaceBaseSessionService- Parameters:
appName- The name of the application.userId- The identifier of the user.sessionId- The unique identifier of the session to delete.
-
appendEvent
描述内容复制自接口文档:BaseSessionService将一个事件添加到内存中的会话对象中,并根据该事件的状态变化(如果适用的话)更新会话的状态。此方法主要修改传入的参数(即 `passed` 参数)。
session这些数据存储在内存中。要使这些更改持久化(即让它们在系统重启后仍然存在),通常需要调用特定服务提供的 `update` 或 `save` 方法;不过,根据该服务的实现方式,这一过程也可能被隐式地完成(即无需用户进行任何操作)。如果该事件被标记为“部分完成”(例如:……),
event.isPartial() == true当数据被返回时,它会直接被发送出去,而不会修改会话状态或事件列表。以 “State delta keys starting with” 开头的键用于表示状态变化的相关信息。State.TEMP_PREFIX在状态更新过程中,这些内容会被忽略。- Specified by:
appendEventin interfaceBaseSessionService- Parameters:
session- TheSessionobject to which the event should be appended (will be mutated).event- TheEventto append.- Returns:
- The appended
Eventinstance (or the original event if it was partial).
-