Runs the pizza ordering agent.
()
| 27 | |
| 28 | |
| 29 | async def main(): |
| 30 | """Runs the pizza ordering agent.""" |
| 31 | app_name = 'pizza_app' |
| 32 | user_id = 'user1' |
| 33 | runner = InMemoryRunner( |
| 34 | agent=agent.root_agent, |
| 35 | app_name=app_name, |
| 36 | ) |
| 37 | session = await runner.session_service.create_session( |
| 38 | app_name=app_name, user_id=user_id |
| 39 | ) |
| 40 | |
| 41 | async def run_prompt(session: Session, new_message: str): |
| 42 | content = types.Content( |
| 43 | role='user', parts=[types.Part.from_text(text=new_message)] |
| 44 | ) |
| 45 | print(f'** User says: {new_message}') |
| 46 | async for event in runner.run_async( |
| 47 | user_id=user_id, |
| 48 | session_id=session.id, |
| 49 | new_message=content, |
| 50 | ): |
| 51 | if event.content and event.content.parts and event.content.parts[0].text: |
| 52 | print(f'** {event.author}: {event.content.parts[0].text}') |
| 53 | |
| 54 | start_time = time.time() |
| 55 | print('Start time:', time.ctime(start_time)) |
| 56 | print('------------------------------------') |
| 57 | await run_prompt( |
| 58 | session, |
| 59 | "I'd like a large pizza with pepperoni and mushrooms on a thin crust.", |
| 60 | ) |
| 61 | print('------------------------------------') |
| 62 | end_time = time.time() |
| 63 | print('End time:', time.ctime(end_time)) |
| 64 | print(f'Total time: {end_time - start_time:.2f} seconds') |
| 65 | |
| 66 | |
| 67 | if __name__ == '__main__': |
no test coverage detected