forked from google-antigravity/antigravity-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreaming.py
More file actions
63 lines (49 loc) · 2.21 KB
/
Copy pathstreaming.py
File metadata and controls
63 lines (49 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Example demonstrating streaming responses and thoughts in Google Antigravity SDK.
To run:
python streaming.py
Criteria for correct script performance:
1. The script exits cleanly with return code 0 (no unhandled exceptions).
2. The agent produces non-empty streamed thought/reasoning content.
3. The agent produces a non-empty streamed final answer.
4. The response correctly identifies the answer to the riddle (an echo).
"""
import asyncio
from google.antigravity import Agent, LocalAgentConfig
async def main() -> None:
config = LocalAgentConfig()
async with Agent(config) as my_agent:
prompt = (
"Solve this riddle: I speak without a mouth and hear without ears. I"
" have no body, but I come alive with wind. What am I? Explain your"
" reasoning."
)
print(f" User: {prompt}\n")
response = await my_agent.chat(prompt)
print(" Agent (Streaming thoughts):")
print(" -------------------------------------------------------")
async for thought in response.thoughts:
print(thought, end="", flush=True)
print("\n -------------------------------------------------------\n")
print(" Agent (Streaming final answer):")
print(" -------------------------------------------------------")
async for token in response:
print(token, end="", flush=True)
print("\n -------------------------------------------------------\n")
# Note: Advanced users can also use `response.tool_calls` to stream tool
# calls as they arrive, or `response.chunks` to get a unified raw stream
# of all content types (Text, ToolCall, etc.).
if __name__ == "__main__":
asyncio.run(main())