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,295 @@
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
+ """Agent Runtime's `:query` and `:streamQuery` methods in `reasoning_engine.py`."""
16
+
17
+ from __future__ import annotations
18
+
19
+ import json
20
+ import uuid
21
+ from unittest.mock import AsyncMock, patch
22
+
23
+ import pytest
24
+ from claude_agent_sdk.types import (
25
+ AssistantMessage,
26
+ ClaudeAgentOptions,
27
+ ResultMessage,
28
+ StreamEvent,
29
+ TextBlock,
30
+ ToolResultBlock,
31
+ ToolUseBlock,
32
+ UserMessage,
33
+ )
34
+ from fastapi import FastAPI
35
+ from fastapi.testclient import TestClient
36
+
37
+ from app.app_utils import reasoning_engine
38
+
39
+ _USER = "user-1"
40
+ _AGENT = reasoning_engine.agent_name()
41
+ _QUERY = "/api/reasoning_engine"
42
+ _STREAM = "/api/stream_reasoning_engine"
43
+
44
+
45
+ @pytest.fixture
46
+ def client() -> TestClient:
47
+ app = FastAPI()
48
+ reasoning_engine.add_reasoning_engine_routes(app)
49
+ return TestClient(app)
50
+
51
+
52
+ def _stream(client: TestClient, **kwargs) -> list[dict]:
53
+ response = client.post(
54
+ _STREAM, json={"class_method": "async_stream_query", "input": kwargs}
55
+ )
56
+ assert response.status_code == 200, response.text
57
+ return [json.loads(line) for line in response.text.splitlines()]
58
+
59
+
60
+ def _result(**fields) -> ResultMessage:
61
+ defaults = {
62
+ "subtype": "success",
63
+ "duration_ms": 1,
64
+ "duration_api_ms": 1,
65
+ "is_error": False,
66
+ "num_turns": 1,
67
+ "session_id": "s",
68
+ }
69
+ return ResultMessage(**{**defaults, **fields})
70
+
71
+
72
+ class _FakeTurns:
73
+ """Stands in for `stream_turn`: replays `messages` and records each call."""
74
+
75
+ def __init__(self, messages: list) -> None:
76
+ self.messages = messages
77
+ self.calls: list[tuple[str, str, str | None]] = []
78
+
79
+ async def __call__(self, prompt, options, conversation_id, user_id=None):
80
+ self.calls.append((prompt, conversation_id, user_id))
81
+ for message in self.messages:
82
+ if isinstance(message, Exception):
83
+ raise message
84
+ yield message
85
+
86
+
87
+ def test_a_turn_streams_its_tool_calls_and_reply(client):
88
+ turns = _FakeTurns(
89
+ [
90
+ AssistantMessage(
91
+ content=[
92
+ ToolUseBlock(id="c1", name="get_weather", input={"city": "SF"})
93
+ ],
94
+ model="m",
95
+ ),
96
+ # A subagent's messages stay inside its tool call.
97
+ AssistantMessage(
98
+ content=[TextBlock(text="inner")], model="m", parent_tool_use_id="c1"
99
+ ),
100
+ UserMessage(content=[ToolResultBlock(tool_use_id="c1", content="Foggy")]),
101
+ UserMessage(
102
+ content=[
103
+ ToolResultBlock(
104
+ tool_use_id="c2", content="Not found", is_error=True
105
+ )
106
+ ]
107
+ ),
108
+ StreamEvent(uuid="u", session_id="s", event={"type": "message_start"}),
109
+ AssistantMessage(content=[TextBlock(text="It is foggy.")], model="m"),
110
+ _result(result="It is foggy."),
111
+ ]
112
+ )
113
+ with patch.object(reasoning_engine, "stream_turn", turns):
114
+ events = _stream(client, message="Weather?", user_id=_USER, session_id="s-1")
115
+
116
+ assert turns.calls == [("Weather?", "s-1", _USER)]
117
+ call = {"id": "c1", "name": "get_weather", "args": {"city": "SF"}}
118
+ found = {"id": "c1", "name": "get_weather", "response": {"result": "Foggy"}}
119
+ missing = {"id": "c2", "name": "", "response": {"error": "Not found"}}
120
+ assert [(e["content"]["role"], e["content"]["parts"]) for e in events] == [
121
+ ("model", [{"function_call": call}]),
122
+ ("user", [{"function_response": found}]),
123
+ ("user", [{"function_response": missing}]),
124
+ ("model", [{"text": "It is foggy."}]),
125
+ ]
126
+ assert len({e["invocation_id"] for e in events}) == 1
127
+ assert {e["author"] for e in events} == {_AGENT}
128
+
129
+
130
+ def test_a_turn_without_a_session_starts_a_new_conversation(client):
131
+ turns = _FakeTurns([])
132
+ message = {"role": "user", "parts": [{"text": "Hello "}, {"text": "there"}]}
133
+ with patch.object(reasoning_engine, "stream_turn", turns):
134
+ _stream(client, message=message, user_id=_USER)
135
+
136
+ [(prompt, conversation_id, user_id)] = turns.calls
137
+ assert (prompt, user_id) == ("Hello there", _USER)
138
+ assert uuid.UUID(conversation_id)
139
+
140
+
141
+ @pytest.mark.parametrize(
142
+ "messages, error",
143
+ [
144
+ pytest.param([RuntimeError("CLI crashed")], "CLI crashed", id="raised"),
145
+ pytest.param(
146
+ # The SDK raises after an error result too.
147
+ [_result(is_error=True, result="Rate limited"), RuntimeError("exit 1")],
148
+ "Rate limited",
149
+ id="error_result",
150
+ ),
151
+ ],
152
+ )
153
+ def test_a_failed_turn_ends_with_one_error_event(client, messages, error):
154
+ with patch.object(reasoning_engine, "stream_turn", _FakeTurns(messages)):
155
+ [event] = _stream(client, message="hi", user_id=_USER)
156
+
157
+ assert event["error_code"] == "AGENT_ERROR"
158
+ assert event["error_message"] == error
159
+ assert "content" not in event
160
+
161
+
162
+ def test_a_structured_output_turn_replies_with_the_json(client, monkeypatch):
163
+ weather = {"city": "SF"}
164
+ monkeypatch.setattr(
165
+ reasoning_engine,
166
+ "root_agent",
167
+ ClaudeAgentOptions(output_format={"type": "json_schema", "schema": {}}),
168
+ )
169
+ turns = _FakeTurns([_result(result="", structured_output=weather)])
170
+ with patch.object(reasoning_engine, "stream_turn", turns):
171
+ [event] = _stream(client, message="hi", user_id=_USER)
172
+
173
+ assert json.loads(event["content"]["parts"][0]["text"]) == weather
174
+
175
+
176
+ @pytest.mark.parametrize(
177
+ "session_input, session_id",
178
+ [
179
+ pytest.param({}, None, id="new"),
180
+ pytest.param({"session_id": "mine"}, "mine", id="given"),
181
+ ],
182
+ )
183
+ def test_create_session_returns_the_session_to_continue(
184
+ client, session_input, session_id
185
+ ):
186
+ response = client.post(
187
+ _QUERY,
188
+ json={
189
+ "class_method": "async_create_session",
190
+ "input": {"user_id": _USER, **session_input},
191
+ },
192
+ )
193
+
194
+ session = response.json()["output"]
195
+ assert (session["user_id"], session["events"]) == (_USER, [])
196
+ assert session["id"] == session_id or uuid.UUID(session["id"])
197
+
198
+
199
+ _BAD_CALLS = {
200
+ "unknown_query_method": (
201
+ _QUERY,
202
+ {"class_method": "async_get_session", "input": {}},
203
+ 404,
204
+ "Supported: async_create_session",
205
+ ),
206
+ "unknown_stream_method": (
207
+ _STREAM,
208
+ {"class_method": "streaming_agent_run_with_events", "input": {}},
209
+ 404,
210
+ "Supported: async_stream_query",
211
+ ),
212
+ "body_not_object": (_QUERY, ["x"], 400, "class_method"),
213
+ "input_not_object": (
214
+ _QUERY,
215
+ {"class_method": "async_create_session", "input": "u"},
216
+ 400,
217
+ "must be an object",
218
+ ),
219
+ "input_empty_list": (
220
+ _QUERY,
221
+ {"class_method": "async_create_session", "input": []},
222
+ 400,
223
+ "must be an object",
224
+ ),
225
+ "missing_user_id": (
226
+ _STREAM,
227
+ {"class_method": "async_stream_query", "input": {"message": "hi"}},
228
+ 400,
229
+ "user_id must be a non-empty string",
230
+ ),
231
+ "session_id_not_string": (
232
+ _STREAM,
233
+ {
234
+ "class_method": "async_stream_query",
235
+ "input": {"user_id": "u", "message": "hi", "session_id": 7},
236
+ },
237
+ 400,
238
+ "session_id must be a non-empty string",
239
+ ),
240
+ "empty_message": (
241
+ _STREAM,
242
+ {
243
+ "class_method": "async_stream_query",
244
+ "input": {"user_id": "u", "message": " "},
245
+ },
246
+ 400,
247
+ "no text",
248
+ ),
249
+ "bad_message": (
250
+ _STREAM,
251
+ {"class_method": "async_stream_query", "input": {"user_id": "u", "message": 3}},
252
+ 400,
253
+ "must be a string",
254
+ ),
255
+ }
256
+
257
+
258
+ @pytest.mark.parametrize(
259
+ "path, body, status, detail", _BAD_CALLS.values(), ids=_BAD_CALLS
260
+ )
261
+ def test_bad_calls_are_refused_before_a_turn_runs(client, path, body, status, detail):
262
+ turns = _FakeTurns([])
263
+ with patch.object(reasoning_engine, "stream_turn", turns):
264
+ response = client.post(path, json=body)
265
+
266
+ assert response.status_code == status
267
+ assert detail in response.json()["detail"]
268
+ assert turns.calls == []
269
+
270
+
271
+ def test_a_body_that_is_not_json_is_refused(client):
272
+ response = client.post(_QUERY, content=b"{")
273
+
274
+ assert response.status_code == 400
275
+ assert "not JSON" in response.json()["detail"]
276
+
277
+
278
+ @pytest.mark.parametrize("engine_id, waits", [("123", True), (None, False)])
279
+ def test_on_agent_runtime_a_turn_waits_for_its_memory_ingest(
280
+ client, monkeypatch, engine_id, waits
281
+ ):
282
+ """Agent Runtime throttles the CPU once the response ends."""
283
+ if engine_id:
284
+ monkeypatch.setenv("GOOGLE_CLOUD_AGENT_ENGINE_ID", engine_id)
285
+ else:
286
+ monkeypatch.delenv("GOOGLE_CLOUD_AGENT_ENGINE_ID", raising=False)
287
+ turns = _FakeTurns([_result(result="Hi.")])
288
+ flush = AsyncMock()
289
+ with (
290
+ patch.object(reasoning_engine, "stream_turn", turns),
291
+ patch.object(reasoning_engine.memory_bank, "flush", flush),
292
+ ):
293
+ _stream(client, message="hi", user_id=_USER)
294
+
295
+ assert flush.await_count == (1 if waits else 0)