Skip to content

Commit bf68132

Browse files
authored
Merge pull request google-cloud-japan#55 from google-cloud-japan/update_query_script_to_agent_engine
Update query.py to print responses correctly
2 parents 8db00b5 + 44cc346 commit bf68132

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

2025/adk-agentengine-basic/query.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
import argparse
88

99
from vertexai import agent_engines
10-
from vertexai.generative_models._generative_models import Content
1110

1211
# --- 定数定義 ---
1312
USER_ID = "test_user01"
14-
TARGET_AUTHOR = "podcast_creator"
13+
TARGET_AUTHORS = ["podcast_creator", "learning_assistant",]
1514

1615
# --- カスタム例外定義 ---
1716
class AgentEngineError(Exception):
@@ -72,11 +71,13 @@ def stream_agent_query(agent: agent_engines.AgentEngine, message: str) -> None:
7271
print("\n--- エージェントからのレスポンス ---\n")
7372
for event in response_stream:
7473
try:
75-
if event.get("author") != TARGET_AUTHOR:
74+
if event.get("author") not in TARGET_AUTHORS:
75+
continue
76+
77+
text = event["content"]["parts"][0]["text"]
78+
if not text:
7679
continue
7780

78-
content: Content = event["content"]
79-
text = content.parts[0].text
8081
print(text, end="", flush=True)
8182

8283
except (KeyError, IndexError, TypeError, AttributeError):

0 commit comments

Comments
 (0)