Skip to content

Commit 833c1d2

Browse files
shawn-yang-googlecopybara-github
authored andcommitted
feat: Add the system tests for Langgraph prebuilt template
PiperOrigin-RevId: 734299775
1 parent 924afa1 commit 833c1d2

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

tests/system/vertexai/test_reasoning_engines.py

+71
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,74 @@ def runnable_builder(**kwargs):
106106
bucket = client.bucket(shared_state["staging_bucket_name"])
107107
assert bucket.exists()
108108
assert bucket.get_blob(f"test-gcs-dir-name/{_BLOB_FILENAME}").exists()
109+
110+
def test_langgraph_template(self, shared_state):
111+
super().setup_method()
112+
credentials, _ = auth.default(
113+
scopes=["https://www.googleapis.com/auth/cloud-platform"]
114+
)
115+
vertexai.init(
116+
project=e2e_base._PROJECT,
117+
location=e2e_base._LOCATION,
118+
staging_bucket=f"gs://{shared_state['staging_bucket_name']}",
119+
credentials=credentials,
120+
)
121+
122+
# System tests are currently affected by contamination in the Gemini
123+
# model and ToolConfig test fixture.
124+
# To eliminate false positives, we are mocking the runnnable builder to
125+
# make the system tests hermetic.
126+
# This change will be reverted once the the test fixture is corrected.
127+
class LanggraphAgentNoDependencies:
128+
"""LangGraph Agent with no dependencies."""
129+
130+
def invoke(self, input, **kwargs) -> str:
131+
return "Testing langgraph agent with no dependencies."
132+
133+
def runnable_builder(**kwargs):
134+
"""Creates a LangGraph Runnable."""
135+
return LanggraphAgentNoDependencies()
136+
137+
# Test prebuilt langgraph_template
138+
created_app = reasoning_engines.ReasoningEngine.create(
139+
reasoning_engines.LanggraphAgent(
140+
model="gemini-1.5-pro-preview-0409",
141+
runnable_builder=runnable_builder,
142+
),
143+
requirements=["google-cloud-aiplatform[reasoningengine,langchain]"],
144+
display_name="test-display-name",
145+
description="test-description",
146+
gcs_dir_name="test-gcs-dir-name",
147+
)
148+
shared_state.setdefault("resources", [])
149+
shared_state["resources"].append(created_app) # Deletion at teardown.
150+
got_app = reasoning_engines.ReasoningEngine(created_app.resource_name)
151+
152+
# Test resource attributes
153+
assert isinstance(created_app.resource_name, str)
154+
assert got_app.resource_name == created_app.resource_name
155+
assert got_app.gca_resource.name == got_app.resource_name
156+
assert got_app.gca_resource.display_name == "test-display-name"
157+
assert got_app.gca_resource.description == "test-description"
158+
159+
# Test operation schemas
160+
assert got_app.operation_schemas() == created_app.operation_schemas()
161+
162+
# Test query response
163+
# (Wrap in a try-except block because of non-determinism from Gemini.)
164+
try:
165+
response = created_app.query(input="hello")
166+
assert response.get("input") == "hello"
167+
response = got_app.query(input="hello")
168+
assert response.get("input") == "hello"
169+
except exceptions.FailedPrecondition:
170+
traceback.print_exc()
171+
except Exception:
172+
traceback.print_exc()
173+
174+
# Test GCS Bucket subdirectory creation
175+
# Original: https://github.com/googleapis/python-aiplatform/issues/3650
176+
client = storage.Client(project=e2e_base._PROJECT)
177+
bucket = client.bucket(shared_state["staging_bucket_name"])
178+
assert bucket.exists()
179+
assert bucket.get_blob(f"test-gcs-dir-name/{_BLOB_FILENAME}").exists()

0 commit comments

Comments
 (0)