Helper function to call the agent and return response.
(runner, user_id, session_id, prompt)
| 31 | |
| 32 | |
| 33 | async def call_agent_async(runner, user_id, session_id, prompt): |
| 34 | """Helper function to call the agent and return response.""" |
| 35 | content = types.Content( |
| 36 | role="user", parts=[types.Part.from_text(text=prompt)] |
| 37 | ) |
| 38 | |
| 39 | final_response_text = "" |
| 40 | async for event in runner.run_async( |
| 41 | user_id=user_id, |
| 42 | session_id=session_id, |
| 43 | new_message=content, |
| 44 | run_config=RunConfig(save_input_blobs_as_artifacts=False), |
| 45 | ): |
| 46 | if hasattr(event, "content") and event.content: |
| 47 | final_response_text += event.content |
| 48 | |
| 49 | return final_response_text |
| 50 | |
| 51 | |
| 52 | async def main(): |