Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,35 @@ def test_create_session_with_expire_time(client):
client.agent_engines.delete(name=agent_engine.api_resource.name, force=True)


def test_create_session_with_custom_session_id(client):
agent_engine = client.agent_engines.create()
try:
assert isinstance(agent_engine, types.AgentEngine)
assert isinstance(agent_engine.api_resource, types.ReasoningEngine)

operation = client.agent_engines.sessions.create(
name=agent_engine.api_resource.name,
user_id="test-user-123",
config=types.CreateAgentEngineSessionConfig(
display_name="my_session",
session_state={"foo": "bar"},
session_id="my-session-id",
),
)
assert isinstance(operation, types.AgentEngineSessionOperation)
assert operation.response.display_name == "my_session"
assert operation.response.session_state == {"foo": "bar"}
assert operation.response.user_id == "test-user-123"
assert (
operation.response.name
== f"{agent_engine.api_resource.name}/sessions/my-session-id"
)
assert operation.done
finally:
# Clean up resources.
client.agent_engines.delete(name=agent_engine.api_resource.name, force=True)


pytestmark = pytest_helper.setup(
file=__file__,
globals_for_file=globals(),
Expand Down
6 changes: 6 additions & 0 deletions vertexai/_genai/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def _CreateAgentEngineSessionConfig_to_vertex(
if getv(from_object, ["labels"]) is not None:
setv(parent_object, ["labels"], getv(from_object, ["labels"]))

if getv(from_object, ["session_id"]) is not None:
setv(parent_object, ["_query", "sessionId"], getv(from_object, ["session_id"]))

return to_object


Expand Down Expand Up @@ -176,6 +179,9 @@ def _UpdateAgentEngineSessionConfig_to_vertex(
if getv(from_object, ["labels"]) is not None:
setv(parent_object, ["labels"], getv(from_object, ["labels"]))

if getv(from_object, ["session_id"]) is not None:
setv(parent_object, ["_query", "sessionId"], getv(from_object, ["session_id"]))

if getv(from_object, ["update_mask"]) is not None:
setv(
parent_object, ["_query", "updateMask"], getv(from_object, ["update_mask"])
Expand Down
14 changes: 14 additions & 0 deletions vertexai/_genai/types/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10810,6 +10810,10 @@ class CreateAgentEngineSessionConfig(_common.BaseModel):
default=None,
description="""Optional. The labels with user-defined metadata to organize your Sessions. Label keys and values can be no longer than 64 characters (Unicode codepoints), can only contain lowercase letters, numeric characters, underscores and dashes. International characters are allowed. See https://goo.gl/xmQnxf for more information and examples of labels.""",
)
session_id: Optional[str] = Field(
default=None,
description="""Optional. The user defined ID to use for session, which will become the final component of the session resource name. If not provided, Vertex AI will generate a value for this ID. This value may be up to 63 characters, and valid characters are `[a-z0-9-]`. The first character must be a letter, and the last character must be a letter or number.""",
)


class CreateAgentEngineSessionConfigDict(TypedDict, total=False):
Expand Down Expand Up @@ -10838,6 +10842,9 @@ class CreateAgentEngineSessionConfigDict(TypedDict, total=False):
labels: Optional[dict[str, str]]
"""Optional. The labels with user-defined metadata to organize your Sessions. Label keys and values can be no longer than 64 characters (Unicode codepoints), can only contain lowercase letters, numeric characters, underscores and dashes. International characters are allowed. See https://goo.gl/xmQnxf for more information and examples of labels."""

session_id: Optional[str]
"""Optional. The user defined ID to use for session, which will become the final component of the session resource name. If not provided, Vertex AI will generate a value for this ID. This value may be up to 63 characters, and valid characters are `[a-z0-9-]`. The first character must be a letter, and the last character must be a letter or number."""


CreateAgentEngineSessionConfigOrDict = Union[
CreateAgentEngineSessionConfig, CreateAgentEngineSessionConfigDict
Expand Down Expand Up @@ -11287,6 +11294,10 @@ class UpdateAgentEngineSessionConfig(_common.BaseModel):
default=None,
description="""Optional. The labels with user-defined metadata to organize your Sessions. Label keys and values can be no longer than 64 characters (Unicode codepoints), can only contain lowercase letters, numeric characters, underscores and dashes. International characters are allowed. See https://goo.gl/xmQnxf for more information and examples of labels.""",
)
session_id: Optional[str] = Field(
default=None,
description="""Optional. The user defined ID to use for session, which will become the final component of the session resource name. If not provided, Vertex AI will generate a value for this ID. This value may be up to 63 characters, and valid characters are `[a-z0-9-]`. The first character must be a letter, and the last character must be a letter or number.""",
)
update_mask: Optional[str] = Field(
default=None,
description="""The update mask to apply. For the `FieldMask` definition, see
Expand Down Expand Up @@ -11323,6 +11334,9 @@ class UpdateAgentEngineSessionConfigDict(TypedDict, total=False):
labels: Optional[dict[str, str]]
"""Optional. The labels with user-defined metadata to organize your Sessions. Label keys and values can be no longer than 64 characters (Unicode codepoints), can only contain lowercase letters, numeric characters, underscores and dashes. International characters are allowed. See https://goo.gl/xmQnxf for more information and examples of labels."""

session_id: Optional[str]
"""Optional. The user defined ID to use for session, which will become the final component of the session resource name. If not provided, Vertex AI will generate a value for this ID. This value may be up to 63 characters, and valid characters are `[a-z0-9-]`. The first character must be a letter, and the last character must be a letter or number."""

update_mask: Optional[str]
"""The update mask to apply. For the `FieldMask` definition, see
https://protobuf.dev/reference/protobuf/google.protobuf/#field-mask."""
Expand Down
Loading