google-agents-cli-extensions 1.14.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. core/claude/README.md +35 -0
  2. core/claude/template/.agents/skills/agents-cli-claude/SKILL.md +106 -0
  3. core/claude/template/.agents/skills/agents-cli-claude/references/claude.md +386 -0
  4. core/claude/template/.agents/skills/agents-cli-claude/references/migrate-claude-agent.md +318 -0
  5. core/claude/template/.agents/skills/agents-cli-claude/references/migrate-from-aws.md +132 -0
  6. core/claude/template/.dockerignore +28 -0
  7. core/claude/template/.env +18 -0
  8. core/claude/template/.env.example +17 -0
  9. core/claude/template/.template/templateconfig.yaml +31 -0
  10. core/claude/template/AGENTS.md +33 -0
  11. core/claude/template/Dockerfile +55 -0
  12. core/claude/template/agent_config/README.md +9 -0
  13. core/claude/template/agents-cli-extension.yaml +49 -0
  14. core/claude/template/app/__init__.py +15 -0
  15. core/claude/template/app/agent.py +49 -0
  16. core/claude/template/app/app_utils/a2a.py +245 -0
  17. core/claude/template/app/app_utils/bq_analytics/__init__.py +124 -0
  18. core/claude/template/app/app_utils/bq_analytics/recorder.py +593 -0
  19. core/claude/template/app/app_utils/bq_analytics/redaction.py +209 -0
  20. core/claude/template/app/app_utils/bq_analytics/schema.py +394 -0
  21. core/claude/template/app/app_utils/bq_analytics/tables.py +104 -0
  22. core/claude/template/app/app_utils/bq_analytics/uploader.py +188 -0
  23. core/claude/template/app/app_utils/claude.py +297 -0
  24. core/claude/template/app/app_utils/completions.py +225 -0
  25. core/claude/template/app/app_utils/conversation.py +29 -0
  26. core/claude/template/app/app_utils/memory_bank.py +308 -0
  27. core/claude/template/app/app_utils/project_settings.py +91 -0
  28. core/claude/template/app/app_utils/reasoning_engine.py +237 -0
  29. core/claude/template/app/app_utils/remote_agents.py +349 -0
  30. core/claude/template/app/app_utils/remote_auth.py +159 -0
  31. core/claude/template/app/app_utils/replies.py +143 -0
  32. core/claude/template/app/app_utils/session_store.py +174 -0
  33. core/claude/template/app/app_utils/settings.py +24 -0
  34. core/claude/template/app/app_utils/telemetry/__init__.py +114 -0
  35. core/claude/template/app/app_utils/telemetry/call_counts.py +44 -0
  36. core/claude/template/app/app_utils/telemetry/cli_relay.py +266 -0
  37. core/claude/template/app/app_utils/telemetry/config.py +133 -0
  38. core/claude/template/app/app_utils/telemetry/logs.py +175 -0
  39. core/claude/template/app/app_utils/telemetry/metrics.py +270 -0
  40. core/claude/template/app/app_utils/telemetry/request_flush.py +104 -0
  41. core/claude/template/app/app_utils/telemetry/subagent_spans.py +80 -0
  42. core/claude/template/app/app_utils/telemetry/traces.py +166 -0
  43. core/claude/template/app/app_utils/turn_events.py +463 -0
  44. core/claude/template/app/app_utils/turn_options.py +219 -0
  45. core/claude/template/app/app_utils/workspaces.py +65 -0
  46. core/claude/template/app/fast_api_app.py +71 -0
  47. core/claude/template/app/feature_tools.py +27 -0
  48. core/claude/template/pyproject.toml +100 -0
  49. core/claude/template/scripts/eval_generate.py +340 -0
  50. core/claude/template/scripts/publish.py +66 -0
  51. core/claude/template/scripts/run.py +85 -0
  52. core/claude/template/scripts/unsupported.py +48 -0
  53. core/claude/template/tests/eval/datasets/basic-dataset.json +31 -0
  54. core/claude/template/tests/eval/eval_config.yaml +17 -0
  55. core/claude/template/tests/eval/response_quality.py +60 -0
  56. core/claude/template/tests/integration/test_server_e2e.py +168 -0
  57. core/claude/template/tests/load_test/.results/.placeholder +0 -0
  58. core/claude/template/tests/load_test/README.md +24 -0
  59. core/claude/template/tests/load_test/load_test.py +118 -0
  60. core/claude/template/tests/unit/conftest.py +63 -0
  61. core/claude/template/tests/unit/helpers.py +32 -0
  62. core/claude/template/tests/unit/test_a2a.py +432 -0
  63. core/claude/template/tests/unit/test_bq_analytics.py +928 -0
  64. core/claude/template/tests/unit/test_bq_redaction.py +89 -0
  65. core/claude/template/tests/unit/test_claude.py +825 -0
  66. core/claude/template/tests/unit/test_completions.py +369 -0
  67. core/claude/template/tests/unit/test_fast_api_app.py +59 -0
  68. core/claude/template/tests/unit/test_feature_tools.py +55 -0
  69. core/claude/template/tests/unit/test_memory_bank.py +625 -0
  70. core/claude/template/tests/unit/test_reasoning_engine.py +295 -0
  71. core/claude/template/tests/unit/test_remote_agents.py +517 -0
  72. core/claude/template/tests/unit/test_telemetry.py +991 -0
  73. core/claude/template/tests/unit/test_turn_events.py +309 -0
  74. core/claude/template/tests/unit/test_turn_options.py +394 -0
  75. core/claude/template/uv.lock +3029 -0
  76. core/langchain/README.md +54 -0
  77. core/langchain/template/.agents/skills/agents-cli-langchain/SKILL.md +84 -0
  78. core/langchain/template/.agents/skills/agents-cli-langchain/references/langchain.md +120 -0
  79. core/langchain/template/.agents/skills/agents-cli-langchain/references/samples.md +42 -0
  80. core/langchain/template/.template/templateconfig.yaml +32 -0
  81. core/langchain/template/AGENTS.md +35 -0
  82. core/langchain/template/agents-cli-extension.yaml +54 -0
  83. core/langchain/template/app/__init__.py +19 -0
  84. core/langchain/template/app/agent.py +61 -0
  85. core/langchain/template/app/app_utils/a2a.py +176 -0
  86. core/langchain/template/app/app_utils/content.py +37 -0
  87. core/langchain/template/app/app_utils/telemetry.py +154 -0
  88. core/langchain/template/app/fast_api_app.py +68 -0
  89. core/langchain/template/langgraph.json +7 -0
  90. core/langchain/template/pyproject.toml +102 -0
  91. core/langchain/template/scripts/_content.py +40 -0
  92. core/langchain/template/scripts/eval_generate.py +202 -0
  93. core/langchain/template/scripts/publish.py +59 -0
  94. core/langchain/template/scripts/run.py +59 -0
  95. core/langchain/template/scripts/unsupported.py +48 -0
  96. core/langchain/template/tests/eval/datasets/basic-dataset.json +16 -0
  97. core/langchain/template/tests/eval/eval_config.yaml +32 -0
  98. core/langchain/template/tests/eval/response_quality.py +60 -0
  99. core/langchain/template/tests/integration/test_server_e2e.py +173 -0
  100. core/langchain/template/tests/load_test/.results/.placeholder +0 -0
  101. core/langchain/template/tests/load_test/README.md +20 -0
  102. core/langchain/template/tests/load_test/load_test.py +82 -0
  103. core/langchain/template/uv.lock +3820 -0
  104. google_agents_cli_extensions-1.14.2.dist-info/METADATA +133 -0
  105. google_agents_cli_extensions-1.14.2.dist-info/RECORD +107 -0
  106. google_agents_cli_extensions-1.14.2.dist-info/WHEEL +4 -0
  107. google_agents_cli_extensions-1.14.2.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,369 @@
1
+ # Copyright 2026 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Prompt-response logging: what each model call uploads and logs."""
16
+
17
+ from __future__ import annotations
18
+
19
+ import json
20
+ import logging
21
+ import time
22
+ import uuid
23
+
24
+ import fsspec
25
+ import pytest
26
+ from claude_agent_sdk import (
27
+ AssistantMessage,
28
+ ClaudeAgentOptions,
29
+ StreamEvent,
30
+ TextBlock,
31
+ ThinkingBlock,
32
+ ToolResultBlock,
33
+ ToolUseBlock,
34
+ UserMessage,
35
+ )
36
+ from opentelemetry import trace
37
+ from opentelemetry.sdk.trace import TracerProvider
38
+ from opentelemetry.sdk.trace.export import SimpleSpanProcessor
39
+ from opentelemetry.sdk.trace.export.in_memory_span_exporter import (
40
+ InMemorySpanExporter,
41
+ )
42
+ from opentelemetry.util.genai.completion_hook import load_completion_hook
43
+
44
+ from app.app_utils import completions
45
+ from app.app_utils.telemetry.config import agent_name
46
+ from app.app_utils.telemetry.subagent_spans import SubagentSpans
47
+ from app.app_utils.turn_events import TurnParser
48
+
49
+ MODEL = "claude-haiku-4-5"
50
+
51
+
52
+ @pytest.fixture
53
+ def events(monkeypatch):
54
+ """The completion events sent to Cloud Logging."""
55
+ sent: list = []
56
+ monkeypatch.setattr(completions.telemetry, "emit_event", sent.append)
57
+ return sent
58
+
59
+
60
+ @pytest.fixture
61
+ def upload(monkeypatch):
62
+ """Turn on the upload hook, writing to an in-memory bucket."""
63
+ base = f"memory://bucket-{uuid.uuid4().hex}/completions"
64
+ monkeypatch.setenv("OTEL_INSTRUMENTATION_GENAI_COMPLETION_HOOK", "upload")
65
+ monkeypatch.setenv("OTEL_INSTRUMENTATION_GENAI_UPLOAD_BASE_PATH", base)
66
+ monkeypatch.setenv("OTEL_INSTRUMENTATION_GENAI_UPLOAD_FORMAT", "jsonl")
67
+
68
+
69
+ @pytest.fixture
70
+ def spans():
71
+ """Where the turn's spans go: PromptLog gets this provider's tracer."""
72
+ exporter = InMemorySpanExporter()
73
+ provider = TracerProvider()
74
+ provider.add_span_processor(SimpleSpanProcessor(exporter))
75
+ return provider, exporter
76
+
77
+
78
+ def _call(message_id: str, blocks: list, parent: str | None = None, **fields):
79
+ return AssistantMessage(
80
+ content=blocks,
81
+ model=MODEL,
82
+ message_id=message_id,
83
+ parent_tool_use_id=parent,
84
+ **fields,
85
+ )
86
+
87
+
88
+ def _log(messages: list, spans, system_prompt=None) -> None:
89
+ """Observe `messages` as one turn, under a span standing in for the agent's."""
90
+ provider, _ = spans
91
+ tracer = provider.get_tracer(__name__)
92
+ parser = TurnParser(agent_name())
93
+ turn = completions.PromptLog(
94
+ load_completion_hook(),
95
+ tracer,
96
+ "Weather in SF?",
97
+ ClaudeAgentOptions(system_prompt=system_prompt),
98
+ "conv-1",
99
+ parser.agent_name,
100
+ SubagentSpans(parser.agent_name),
101
+ )
102
+ with tracer.start_as_current_span("turn"):
103
+ for message in messages:
104
+ for event in parser.feed(message):
105
+ turn.handle(event)
106
+ for event in parser.finish():
107
+ turn.handle(event)
108
+
109
+
110
+ def _uploaded(path: str) -> list[dict]:
111
+ """The JSONL file at `path`, once the hook's upload thread has written it."""
112
+ fs, _ = fsspec.url_to_fs(path)
113
+ deadline = time.monotonic() + 5
114
+ # The memory filesystem creates the file, empty, when it's opened to write.
115
+ while not fs.exists(path) or not fs.cat_file(path):
116
+ assert time.monotonic() < deadline, f"{path} was never uploaded"
117
+ time.sleep(0.01)
118
+ with fs.open(path) as file:
119
+ return [json.loads(line) for line in file.read().splitlines() if line]
120
+
121
+
122
+ def _messages(path: str) -> list[tuple[str, list[dict]]]:
123
+ """(role, parts) of each message uploaded to `path`."""
124
+ return [(message["role"], message["parts"]) for message in _uploaded(path)]
125
+
126
+
127
+ _TOOL_TURN = [
128
+ _call(
129
+ "m1",
130
+ [
131
+ TextBlock(text="Checking."),
132
+ ToolUseBlock(id="t1", name="get_weather", input={"city": "SF"}),
133
+ ],
134
+ stop_reason="tool_use",
135
+ usage={"input_tokens": 20, "output_tokens": 5},
136
+ ),
137
+ UserMessage(content=[ToolResultBlock(tool_use_id="t1", content="60F")]),
138
+ _call("m2", [TextBlock(text="It's foggy.")], stop_reason="end_turn"),
139
+ ]
140
+
141
+
142
+ def test_each_call_reads_the_turn_so_far(upload, events, spans):
143
+ _log(_TOOL_TURN, spans, system_prompt="You report the weather.")
144
+
145
+ first, second = events
146
+ attributes = first.attributes
147
+ # The log sink matches on this label.
148
+ assert attributes["event.name"] == completions.EVENT_NAME
149
+ assert attributes["gen_ai.request.model"] == MODEL
150
+ assert attributes["gen_ai.conversation.id"] == "conv-1"
151
+ assert attributes["gen_ai.response.finish_reasons"] == ["tool_use"]
152
+ assert attributes["gen_ai.usage.input_tokens"] == 20
153
+ prompt = ("user", [{"type": "text", "content": "Weather in SF?"}])
154
+ assert _messages(attributes["gen_ai.input.messages_ref"]) == [prompt]
155
+ [(_, output)] = _messages(attributes["gen_ai.output.messages_ref"])
156
+ tool_call = {
157
+ "type": "tool_call",
158
+ "arguments": {"city": "SF"},
159
+ "name": "get_weather",
160
+ "id": "t1",
161
+ }
162
+ assert output == [{"type": "text", "content": "Checking."}, tool_call]
163
+ [instruction] = _uploaded(attributes["gen_ai.system_instructions_ref"])
164
+ assert instruction["content"] == "You report the weather."
165
+ # The last call alone holds the whole turn.
166
+ assert _messages(second.attributes["gen_ai.input.messages_ref"]) == [
167
+ prompt,
168
+ ("assistant", [{"type": "text", "content": "Checking."}, tool_call]),
169
+ (
170
+ "tool",
171
+ [{"type": "tool_call_response", "response": {"result": "60F"}, "id": "t1"}],
172
+ ),
173
+ ]
174
+
175
+
176
+ def test_a_custom_system_prompt_is_the_system_instruction(upload, events, spans):
177
+ _log(
178
+ [_call("m1", [TextBlock(text="It's foggy.")])],
179
+ spans,
180
+ system_prompt={"type": "custom", "prompt": "You report the weather."},
181
+ )
182
+
183
+ [event] = events
184
+ [instruction] = _uploaded(event.attributes["gen_ai.system_instructions_ref"])
185
+ assert instruction["content"] == "You report the weather."
186
+
187
+
188
+ def test_each_call_gets_a_chat_span_carrying_its_entry(upload, events, spans):
189
+ _log(_TOOL_TURN, spans)
190
+
191
+ _, exporter = spans
192
+ *calls, turn = exporter.get_finished_spans()
193
+ assert [span.name for span in calls] == [f"chat {MODEL}"] * 2
194
+ assert {span.parent.span_id for span in calls} == {turn.context.span_id}
195
+ for event, span in zip(events, calls, strict=True):
196
+ assert event.context is not None
197
+ span_context = trace.get_current_span(event.context).get_span_context()
198
+ assert span_context.span_id == span.context.span_id
199
+ assert (
200
+ span.attributes["gen_ai.output.messages_ref"]
201
+ == (event.attributes["gen_ai.output.messages_ref"])
202
+ )
203
+ assert calls[0].attributes["gen_ai.usage.input_tokens"] == 20
204
+
205
+
206
+ def test_a_failed_model_call_marks_its_chat_span_as_an_error(upload, events, spans):
207
+ _log([_call("bad", [TextBlock(text="API Error: 429")], error="rate_limit")], spans)
208
+
209
+ _, exporter = spans
210
+ chat, _ = exporter.get_finished_spans()
211
+ assert chat.status.status_code == trace.StatusCode.ERROR
212
+ assert chat.attributes["error.type"] == "rate_limit"
213
+
214
+
215
+ def test_a_subagent_is_logged_from_its_own_prompt(upload, events, spans):
216
+ task = ToolUseBlock(id="task-1", name="Task", input={"prompt": "Summarize"})
217
+ _log(
218
+ [
219
+ # The main agent's calls stream, so this one ends before the subagent runs.
220
+ _event("message_start", message={}),
221
+ _call("m1", [task]),
222
+ _event("message_stop"),
223
+ UserMessage(content="Summarize the forecast.", parent_tool_use_id="task-1"),
224
+ _call("s1", [TextBlock(text="Foggy all day.")], parent="task-1"),
225
+ UserMessage(
226
+ content=[ToolResultBlock(tool_use_id="task-1", content="Foggy.")]
227
+ ),
228
+ _call("m2", [TextBlock(text="It's foggy.")]),
229
+ ],
230
+ spans,
231
+ system_prompt={
232
+ "type": "preset",
233
+ "preset": "claude_code",
234
+ "append": "Be brief.",
235
+ },
236
+ )
237
+
238
+ agent_call, subagent_call, final_call = events
239
+ assert _messages(subagent_call.attributes["gen_ai.input.messages_ref"]) == [
240
+ ("user", [{"type": "text", "content": "Summarize the forecast."}])
241
+ ]
242
+ assert "gen_ai.system_instructions_ref" not in subagent_call.attributes
243
+ # Only what the agent adds to a preset prompt is its own.
244
+ [instruction] = _uploaded(agent_call.attributes["gen_ai.system_instructions_ref"])
245
+ assert instruction["content"] == "Be brief."
246
+ roles = [
247
+ role
248
+ for role, _ in _messages(final_call.attributes["gen_ai.input.messages_ref"])
249
+ ]
250
+ assert roles == ["user", "assistant", "tool"]
251
+
252
+
253
+ def _event(kind: str, **fields) -> StreamEvent:
254
+ return StreamEvent(uuid="u", session_id="s", event={"type": kind, **fields})
255
+
256
+
257
+ def test_a_streamed_call_takes_its_final_usage_from_the_stream(upload, events, spans):
258
+ _log(
259
+ [
260
+ _event("message_start"),
261
+ _call(
262
+ "m1",
263
+ [ToolUseBlock(id="t1", name="get_weather", input={"city": "SF"})],
264
+ usage={"input_tokens": 20, "output_tokens": 1},
265
+ ),
266
+ # The CLI runs the tool before the call's stream has ended.
267
+ UserMessage(content=[ToolResultBlock(tool_use_id="t1", content="60F")]),
268
+ _event(
269
+ "message_delta",
270
+ usage={"output_tokens": 12},
271
+ delta={"stop_reason": "tool_use"},
272
+ ),
273
+ _event("message_stop"),
274
+ _call("m2", [TextBlock(text="It's foggy.")]),
275
+ ],
276
+ spans,
277
+ )
278
+
279
+ first, second = events
280
+ assert first.attributes["gen_ai.usage.input_tokens"] == 20
281
+ assert first.attributes["gen_ai.usage.output_tokens"] == 12
282
+ assert first.attributes["gen_ai.response.finish_reasons"] == ["tool_use"]
283
+ [(role, _)] = _messages(first.attributes["gen_ai.input.messages_ref"])
284
+ assert role == "user"
285
+ # The tool's result, which came before message_stop, follows the reply.
286
+ roles = [
287
+ role for role, _ in _messages(second.attributes["gen_ai.input.messages_ref"])
288
+ ]
289
+ assert roles == ["user", "assistant", "tool"]
290
+
291
+
292
+ @pytest.mark.parametrize(
293
+ ("content", "is_error", "response"),
294
+ [
295
+ (
296
+ [{"type": "text", "text": "60"}, {"type": "text", "text": "F"}],
297
+ None,
298
+ {"result": "60F"},
299
+ ),
300
+ ("city not found", True, {"error": "city not found"}),
301
+ ],
302
+ )
303
+ def test_tool_results_go_up_as_objects(
304
+ upload, events, spans, content, is_error, response
305
+ ):
306
+ _log(
307
+ [
308
+ _call("m1", [ToolUseBlock(id="t1", name="get_weather", input={})]),
309
+ UserMessage(
310
+ content=[
311
+ ToolResultBlock(
312
+ tool_use_id="t1", content=content, is_error=is_error
313
+ )
314
+ ]
315
+ ),
316
+ _call("m2", [TextBlock(text="Done.")]),
317
+ ],
318
+ spans,
319
+ )
320
+
321
+ *_, (role, parts) = _messages(events[1].attributes["gen_ai.input.messages_ref"])
322
+ assert (role, parts[0]["response"]) == ("tool", response)
323
+
324
+
325
+ def test_one_model_call_in_several_messages_is_one_event(upload, events, spans):
326
+ _log(
327
+ [
328
+ _call("m1", [ThinkingBlock(thinking="SF is foggy.", signature="s")]),
329
+ _call("m1", [TextBlock(text="It's foggy.")]),
330
+ ],
331
+ spans,
332
+ )
333
+
334
+ [event] = events
335
+ [(_, output)] = _messages(event.attributes["gen_ai.output.messages_ref"])
336
+ assert output == [
337
+ {"type": "text", "content": "SF is foggy."},
338
+ {"type": "text", "content": "It's foggy."},
339
+ ]
340
+
341
+
342
+ def test_off_unless_the_upload_hook_is_configured(monkeypatch):
343
+ monkeypatch.delenv("OTEL_INSTRUMENTATION_GENAI_COMPLETION_HOOK", raising=False)
344
+ names = TurnParser(agent_name()).agent_name
345
+ spans = SubagentSpans(names)
346
+ assert (
347
+ completions.start_turn("hi", ClaudeAgentOptions(), "conv-1", names, spans)
348
+ is None
349
+ )
350
+
351
+
352
+ @pytest.mark.parametrize(
353
+ "calls",
354
+ [
355
+ pytest.param(["m1"], id="at the end of the turn"),
356
+ pytest.param(["m1", "m2"], id="when the next call starts"),
357
+ ],
358
+ )
359
+ def test_a_failure_never_fails_the_turn(upload, spans, monkeypatch, caplog, calls):
360
+ def refuse(record):
361
+ raise ConnectionError("logging.googleapis.com unreachable")
362
+
363
+ monkeypatch.setattr(completions.telemetry, "emit_event", refuse)
364
+ with caplog.at_level(logging.WARNING):
365
+ _log([_call(message_id, [TextBlock(text="hi")]) for message_id in calls], spans)
366
+
367
+ assert [r.getMessage() for r in caplog.records] == ["Couldn't log a model call"]
368
+ _, exporter = spans
369
+ assert [s.name for s in exporter.get_finished_spans()] == [f"chat {MODEL}", "turn"]
@@ -0,0 +1,59 @@
1
+ # Copyright 2026 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """The local server: `app/fast_api_app.py` and the `.env` it loads."""
16
+
17
+ import os
18
+ import shutil
19
+ import subprocess
20
+ import sys
21
+ from pathlib import Path
22
+
23
+ _APP_DIR = Path(__file__).resolve().parents[2] / "app"
24
+
25
+
26
+ def test_features_turned_on_only_in_dotenv_add_their_tools(tmp_path):
27
+ # A copy of the app next to its own .env, run in a fresh interpreter: the
28
+ # tool lists are fixed when app.agent is first imported.
29
+ shutil.copytree(
30
+ _APP_DIR, tmp_path / "app", ignore=shutil.ignore_patterns("__pycache__")
31
+ )
32
+ (tmp_path / ".env").write_text(
33
+ "MEMORY_BANK_ENABLED=true\nGOOGLE_CLOUD_AGENT_ENGINE_ENABLE_TELEMETRY=false\n"
34
+ )
35
+ env = {
36
+ name: value
37
+ for name, value in os.environ.items()
38
+ if name
39
+ not in ("MEMORY_BANK_ENABLED", "GOOGLE_CLOUD_AGENT_ENGINE_ENABLE_TELEMETRY")
40
+ }
41
+ env["PYTHONPATH"] = str(tmp_path)
42
+
43
+ result = subprocess.run(
44
+ [
45
+ sys.executable,
46
+ "-c",
47
+ "import app.fast_api_app\n"
48
+ "from app.agent import root_agent\n"
49
+ "print(app.__file__, root_agent.allowed_tools)",
50
+ ],
51
+ cwd=tmp_path,
52
+ env=env,
53
+ capture_output=True,
54
+ text=True,
55
+ check=True,
56
+ )
57
+
58
+ assert result.stdout.startswith(str(tmp_path / "app" / "__init__.py"))
59
+ assert "mcp__memory__search_memory" in result.stdout
@@ -0,0 +1,55 @@
1
+ # Copyright 2026 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """The tools `app/feature_tools.py` adds to root_agent for the features that are on."""
16
+
17
+ import importlib
18
+
19
+ import pytest
20
+
21
+ from app import feature_tools
22
+
23
+
24
+ @pytest.fixture
25
+ def reload_feature_tools(monkeypatch):
26
+ """Re-evaluates feature_tools, which reads the env at import, under the test's env.
27
+
28
+ Afterwards it is evaluated again under the original env, so no other test
29
+ sees the test's tools.
30
+ """
31
+ yield lambda: importlib.reload(feature_tools)
32
+ monkeypatch.undo()
33
+ importlib.reload(feature_tools)
34
+
35
+
36
+ @pytest.mark.parametrize(
37
+ "enabled, servers, tools",
38
+ [
39
+ ("true", ["memory"], ["mcp__memory__search_memory"]),
40
+ (None, [], []),
41
+ ],
42
+ ids=["memory_on", "memory_off"],
43
+ )
44
+ def test_memory_bank_adds_its_search_tool_only_while_on(
45
+ monkeypatch, reload_feature_tools, enabled, servers, tools
46
+ ):
47
+ if enabled is None:
48
+ monkeypatch.delenv("MEMORY_BANK_ENABLED", raising=False)
49
+ else:
50
+ monkeypatch.setenv("MEMORY_BANK_ENABLED", enabled)
51
+
52
+ module = reload_feature_tools()
53
+
54
+ assert list(module.FEATURE_MCP_SERVERS) == servers
55
+ assert module.FEATURE_TOOLS == tools