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,309 @@
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 turn parser, fed SDK messages as the CLI sends them."""
16
+
17
+ from __future__ import annotations
18
+
19
+ from collections import Counter
20
+
21
+ import pytest
22
+ from claude_agent_sdk import (
23
+ AssistantMessage,
24
+ ResultMessage,
25
+ StreamEvent,
26
+ SystemMessage,
27
+ TextBlock,
28
+ ToolResultBlock,
29
+ ToolUseBlock,
30
+ UserMessage,
31
+ )
32
+
33
+ from app.app_utils.turn_events import (
34
+ ModelCallEnded,
35
+ ModelCallStarted,
36
+ SubagentEnded,
37
+ SubagentPrompt,
38
+ SubagentStarted,
39
+ ToolCallEnded,
40
+ ToolCallStarted,
41
+ TurnEnded,
42
+ TurnParser,
43
+ TurnResult,
44
+ )
45
+
46
+
47
+ def _stream(kind: str, **fields) -> StreamEvent:
48
+ return StreamEvent(uuid="u", session_id="s", event={"type": kind, **fields})
49
+
50
+
51
+ def _say(message_id: str | None, *blocks, parent: str | None = None, **fields):
52
+ return AssistantMessage(
53
+ content=list(blocks),
54
+ model="claude-haiku-4-5",
55
+ message_id=message_id,
56
+ parent_tool_use_id=parent,
57
+ **fields,
58
+ )
59
+
60
+
61
+ def _results(*blocks: ToolResultBlock, parent: str | None = None) -> UserMessage:
62
+ return UserMessage(content=list(blocks), parent_tool_use_id=parent)
63
+
64
+
65
+ def _result(is_error: bool = False) -> ResultMessage:
66
+ return ResultMessage(
67
+ subtype="success",
68
+ duration_ms=1,
69
+ duration_api_ms=1,
70
+ is_error=is_error,
71
+ num_turns=1,
72
+ session_id="s",
73
+ )
74
+
75
+
76
+ def _parse(messages: list, error: BaseException | None = None):
77
+ parser = TurnParser("weather_agent")
78
+ events = [event for message in messages for event in parser.feed(message)]
79
+ *events, ended = events + parser.finish(error)
80
+ assert isinstance(ended, TurnEnded)
81
+ return parser, events
82
+
83
+
84
+ def _kinds(events: list) -> list[str]:
85
+ return [type(event).__name__ for event in events]
86
+
87
+
88
+ def _calls_per_agent(events: list, kind: type) -> Counter:
89
+ return Counter(event.agent for event in events if isinstance(event, kind))
90
+
91
+
92
+ _DELEGATE = ToolUseBlock(
93
+ id="agent-1",
94
+ name="Agent",
95
+ input={"subagent_type": "researcher", "prompt": "Paris?"},
96
+ )
97
+
98
+
99
+ def test_a_streamed_call_in_several_messages_is_one_call_with_the_final_usage():
100
+ _, events = _parse(
101
+ [
102
+ _stream("message_start", message={"usage": {"input_tokens": 100}}),
103
+ _stream("content_block_delta", delta={"type": "text_delta"}),
104
+ _say("m1", TextBlock(text="Checking."), usage={"output_tokens": 1}),
105
+ _say("m1", ToolUseBlock(id="t1", name="lookup", input={})),
106
+ _stream(
107
+ "message_delta",
108
+ usage={"output_tokens": 20},
109
+ delta={"stop_reason": "tool_use"},
110
+ ),
111
+ _stream("message_stop"),
112
+ ]
113
+ )
114
+
115
+ started, call, tool = events
116
+ assert started == ModelCallStarted(None)
117
+ assert isinstance(call, ModelCallEnded)
118
+ assert len(call.blocks) == 2
119
+ assert call.usage == {"input_tokens": 100, "output_tokens": 20}
120
+ assert call.stop_reason == "tool_use"
121
+ assert call.first_token_at is not None
122
+ assert tool == ToolCallStarted(None, "t1", "lookup", {})
123
+
124
+
125
+ def test_tool_results_before_message_stop_wait_for_the_call_to_end():
126
+ _, events = _parse(
127
+ [
128
+ _stream("message_start", message={}),
129
+ _say("m1", ToolUseBlock(id="t1", name="lookup", input={})),
130
+ _results(ToolResultBlock(tool_use_id="t1", content="60F")),
131
+ _stream("message_stop"),
132
+ ]
133
+ )
134
+
135
+ assert _kinds(events) == [
136
+ "ModelCallStarted",
137
+ "ModelCallEnded",
138
+ "ToolCallStarted",
139
+ "ToolCallEnded",
140
+ ]
141
+ assert events[-1].content == "60F"
142
+
143
+
144
+ def test_an_unstreamed_call_ends_at_the_next_user_or_result_message():
145
+ _, events = _parse(
146
+ [
147
+ _say(None, ToolUseBlock(id="t1", name="lookup", input={})),
148
+ _say(None, TextBlock(text="and")),
149
+ _results(ToolResultBlock(tool_use_id="t1", content="60F")),
150
+ _say("m2", TextBlock(text="It's 60F.")),
151
+ _result(),
152
+ ]
153
+ )
154
+
155
+ calls = [e for e in events if isinstance(e, ModelCallEnded)]
156
+ assert [len(c.blocks) for c in calls] == [2, 1]
157
+ assert _calls_per_agent(events, ModelCallEnded) == {None: 2}
158
+ assert _calls_per_agent(events, ToolCallStarted) == {None: 1}
159
+ assert isinstance(events[-1], TurnResult)
160
+
161
+
162
+ def test_a_failed_model_call_carries_its_error():
163
+ _, events = _parse(
164
+ [
165
+ _say("m1", TextBlock(text="API Error: 429"), error="rate_limit"),
166
+ _result(is_error=True),
167
+ ]
168
+ )
169
+
170
+ [call] = [e for e in events if isinstance(e, ModelCallEnded)]
171
+ assert call.error == "rate_limit"
172
+
173
+
174
+ @pytest.mark.parametrize("task_started_first", [False, True])
175
+ def test_a_subagent_runs_between_its_tool_call_and_result(task_started_first):
176
+ task_started = SystemMessage(
177
+ subtype="task_started", data={"tool_use_id": "agent-1"}
178
+ )
179
+ parser, events = _parse(
180
+ [
181
+ *([task_started] if task_started_first else []),
182
+ _stream("message_start", message={}),
183
+ _say("m1", _DELEGATE),
184
+ _stream("message_stop"),
185
+ UserMessage(content="Paris?", parent_tool_use_id="agent-1"),
186
+ _say(
187
+ "s1", ToolUseBlock(id="t1", name="lookup", input={}), parent="agent-1"
188
+ ),
189
+ _results(
190
+ ToolResultBlock(tool_use_id="t1", content="Sunny"), parent="agent-1"
191
+ ),
192
+ _say("s2", TextBlock(text="Sunny."), parent="agent-1"),
193
+ # Not a task: the result ends the subagent.
194
+ *(
195
+ []
196
+ if task_started_first
197
+ else [
198
+ _results(ToolResultBlock(tool_use_id="agent-1", content="Sunny."))
199
+ ]
200
+ ),
201
+ *(
202
+ [
203
+ SystemMessage(
204
+ subtype="task_notification",
205
+ data={"tool_use_id": "agent-1", "status": "completed"},
206
+ )
207
+ ]
208
+ if task_started_first
209
+ else []
210
+ ),
211
+ ]
212
+ )
213
+
214
+ assert SubagentStarted("agent-1", "Paris?") in events
215
+ assert SubagentPrompt("agent-1", "Paris?") in events
216
+ assert SubagentEnded("agent-1", False) in events
217
+ subagent_calls = [e for e in events if isinstance(e, ModelCallEnded) and e.agent]
218
+ assert len(subagent_calls) == 2
219
+ assert parser.agent_name("agent-1") == "researcher"
220
+ assert parser.agent_name(None) == "weather_agent"
221
+ assert _calls_per_agent(events, ModelCallEnded) == {None: 1, "agent-1": 2}
222
+ assert _calls_per_agent(events, ToolCallStarted) == {None: 1, "agent-1": 1}
223
+ # The subagent's last call ends before the subagent does.
224
+ assert events.index(subagent_calls[-1]) < events.index(
225
+ SubagentEnded("agent-1", False)
226
+ )
227
+
228
+
229
+ def test_a_subagent_still_running_in_the_background_ends_with_the_turn():
230
+ _, events = _parse(
231
+ [
232
+ _stream("message_start", message={}),
233
+ _say("m1", _DELEGATE),
234
+ _stream("message_stop"),
235
+ # Returned before the subagent sent anything: it runs in the background.
236
+ _results(ToolResultBlock(tool_use_id="agent-1", content="Started.")),
237
+ _say("s1", TextBlock(text="Sunny."), parent="agent-1"),
238
+ _result(is_error=True),
239
+ ]
240
+ )
241
+
242
+ assert [e for e in events if isinstance(e, ModelCallEnded) and e.agent]
243
+ assert events[-1] == SubagentEnded("agent-1", True)
244
+
245
+
246
+ def test_a_call_cut_off_mid_stream_is_closed_by_finish():
247
+ _, events = _parse(
248
+ [
249
+ _stream("message_start", message={}),
250
+ _say("m1", ToolUseBlock(id="t1", name="lookup", input={})),
251
+ _results(ToolResultBlock(tool_use_id="t1", content="60F")),
252
+ ],
253
+ error=RuntimeError("stream ended"),
254
+ )
255
+
256
+ assert _kinds(events)[-2:] == ["ToolCallStarted", "ToolCallEnded"]
257
+
258
+
259
+ def test_a_malformed_subagent_call_falls_back_to_defaults():
260
+ odd = ToolUseBlock(id="agent-1", name="Agent", input=["not", "a", "dict"])
261
+ parser, events = _parse([_say("m1", odd), _result()])
262
+
263
+ assert SubagentStarted("agent-1", None) in events
264
+ assert parser.agent_name("agent-1") == "subagent"
265
+ assert isinstance(events[-1], SubagentEnded)
266
+
267
+
268
+ def test_tool_results_carry_the_message_they_came_in():
269
+ _, events = _parse(
270
+ [
271
+ _say("m1", *(ToolUseBlock(id=i, name="lookup", input={}) for i in "ab")),
272
+ _results(
273
+ ToolResultBlock(tool_use_id="a", content="1"),
274
+ ToolResultBlock(tool_use_id="b", content="2"),
275
+ ),
276
+ ]
277
+ )
278
+
279
+ ended = [e for e in events if isinstance(e, ToolCallEnded)]
280
+ assert len({e.message_index for e in ended}) == 1
281
+
282
+
283
+ @pytest.mark.parametrize(
284
+ ("messages", "error", "failed", "error_kept"),
285
+ [
286
+ pytest.param([_result()], None, False, False, id="completed"),
287
+ pytest.param([_result(is_error=True)], None, True, False, id="error result"),
288
+ pytest.param([], RuntimeError("boom"), True, True, id="exception"),
289
+ pytest.param(
290
+ [_result()], GeneratorExit(), False, False, id="stopped at the result"
291
+ ),
292
+ pytest.param([], GeneratorExit(), True, True, id="stopped before a result"),
293
+ ],
294
+ )
295
+ def test_every_turn_ends_with_turn_ended(messages, error, failed, error_kept):
296
+ parser = TurnParser("weather_agent")
297
+ for message in messages:
298
+ parser.feed(message)
299
+ *_, ended = parser.finish(error)
300
+ assert ended == TurnEnded(failed, error if error_kept else None)
301
+
302
+
303
+ def test_a_turn_the_parser_stopped_reading_still_ends():
304
+ parser = TurnParser("weather_agent")
305
+ malformed = SystemMessage(
306
+ subtype="compact_boundary", data={"compact_metadata": "x"}
307
+ )
308
+ assert parser.feed(malformed) == []
309
+ assert parser.finish() == [TurnEnded(False, None)]