MCPcopy Index your code
hub / github.com/google/adk-python / main

Function main

contributing/samples/patterns/fields_planner/main.py:32–68  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30
31
32async def main():
33 app_name = 'my_app'
34 user_id_1 = 'user1'
35 session_service = InMemorySessionService()
36 artifact_service = InMemoryArtifactService()
37 runner = Runner(
38 app_name=app_name,
39 agent=agent.root_agent,
40 artifact_service=artifact_service,
41 session_service=session_service,
42 )
43 session_11 = await session_service.create_session(app_name, user_id_1)
44
45 async def run_prompt(session: Session, new_message: str):
46 content = types.Content(
47 role='user', parts=[types.Part.from_text(text=new_message)]
48 )
49 print('** User says:', content.model_dump(exclude_none=True))
50 async for event in runner.run_async(
51 user_id=user_id_1,
52 session_id=session.id,
53 new_message=content,
54 ):
55 if event.content.parts and event.content.parts[0].text:
56 print(f'** {event.author}: {event.content.parts[0].text}')
57
58 start_time = time.time()
59 print('Start time:', start_time)
60 print('------------------------------------')
61 await run_prompt(session_11, 'Hi')
62 await run_prompt(session_11, 'Roll a die.')
63 await run_prompt(session_11, 'Roll a die again.')
64 await run_prompt(session_11, 'What numbers did I got?')
65 end_time = time.time()
66 print('------------------------------------')
67 print('End time:', end_time)
68 print('Total time:', end_time - start_time)
69
70
71if __name__ == '__main__':

Callers 1

main.pyFile · 0.70

Calls 6

create_sessionMethod · 0.95
RunnerClass · 0.90
timeMethod · 0.80
run_promptFunction · 0.70

Tested by

no test coverage detected