You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's consolidate these frequently copy-pasted codes into an ADK-util class to avoid repetition.
asyncdefrun_agent(query, agent):
"""Sends a query to the agent and prints the final response."""print(f"\n>>> User Query: {query}")
# Create a Runnerrunner=Runner(
agent=agent,
app_name=APP_NAME,
session_service=session_service
)
# Prepare the user's message in ADK formatcontent=types.Content(role='user', parts=[types.Part(text=query)])
final_response_text=None# We iterate through events from run_async to find the final answer.asyncforeventinrunner.run_async(user_id=USER_ID, session_id=SESSION_ID, new_message=content):
ifevent.is_final_response():
ifevent.contentandevent.content.parts:
final_response_text=event.content.parts[0].textbreakprint(f"<<< Agent Response: {final_response_text}")
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Let's consolidate these frequently copy-pasted codes into an ADK-util class to avoid repetition.
Beta Was this translation helpful? Give feedback.
All reactions