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

Function main

contributing/samples/context_management/memory/main.py:31–105  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

29
30
31async def main():
32 app_name = 'my_app'
33 user_id_1 = 'user1'
34 runner = InMemoryRunner(
35 app_name=app_name,
36 agent=agent.root_agent,
37 )
38
39 async def run_prompt(session: Session, new_message: str) -> Session:
40 content = types.Content(
41 role='user', parts=[types.Part.from_text(text=new_message)]
42 )
43 print('** User says:', content.model_dump(exclude_none=True))
44 async for event in runner.run_async(
45 user_id=user_id_1,
46 session_id=session.id,
47 new_message=content,
48 ):
49 if not event.content or not event.content.parts:
50 continue
51 if event.content.parts[0].text:
52 print(f'** {event.author}: {event.content.parts[0].text}')
53 elif event.content.parts[0].function_call:
54 print(
55 f'** {event.author}: fc /'
56 f' {event.content.parts[0].function_call.name} /'
57 f' {event.content.parts[0].function_call.args}\n'
58 )
59 elif event.content.parts[0].function_response:
60 print(
61 f'** {event.author}: fr /'
62 f' {event.content.parts[0].function_response.name} /'
63 f' {event.content.parts[0].function_response.response}\n'
64 )
65
66 return cast(
67 Session,
68 await runner.session_service.get_session(
69 app_name=app_name, user_id=user_id_1, session_id=session.id
70 ),
71 )
72
73 session_1 = await runner.session_service.create_session(
74 app_name=app_name, user_id=user_id_1
75 )
76
77 print(f'----Session to create memory: {session_1.id} ----------------------')
78 session_1 = await run_prompt(session_1, 'Hi')
79 session_1 = await run_prompt(session_1, 'My name is Jack')
80 session_1 = await run_prompt(session_1, 'I like badminton.')
81 session_1 = await run_prompt(
82 session_1,
83 f'I ate a burger on {(datetime.now() - timedelta(days=1)).date()}.',
84 )
85 session_1 = await run_prompt(
86 session_1,
87 f'I ate a banana on {(datetime.now() - timedelta(days=2)).date()}.',
88 )

Callers 1

main.pyFile · 0.70

Calls 5

InMemoryRunnerClass · 0.90
dateMethod · 0.80
run_promptFunction · 0.70
create_sessionMethod · 0.45
add_session_to_memoryMethod · 0.45

Tested by

no test coverage detected