-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
50 lines (42 loc) · 1.82 KB
/
main.py
File metadata and controls
50 lines (42 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from agents.orchestrator_agent import get_orchestrator_agent
from google.adk.runners import InMemoryRunner
from google.genai import types
import asyncio
async def main():
orchestrator_agent = await get_orchestrator_agent()
runner = InMemoryRunner(orchestrator_agent, app_name="research_report")
session = await runner.session_service.create_session(
app_name="research_report",
user_id="user"
)
query = input("Enter your search query: ")
try:
async for event in runner.run_async(
user_id="user",
session_id=session.id,
new_message=types.Content(
role="user",
parts=[types.Part(text=query)]
),
):
print(f"Event from: {event.author}")
if event.content and event.content.parts:
if event.get_function_calls():
for call in event.get_function_calls():
print(f" Type: Tool Call Request -> {call.name}")
print(f" Params: {call.args}")
elif event.get_function_responses():
for response in event.get_function_responses():
print(f" Type: Tool Result from -> {response.name}")
elif event.is_final_response():
print(f" Type: Final Response")
for part in event.content.parts:
if part.text:
print(f" MESSAGE: {part.text}")
if event.actions:
if event.actions.transfer_to_agent:
print(f" Signal: Transfer to {event.actions.transfer_to_agent}")
finally:
await runner.close()
if __name__ == "__main__":
asyncio.run(main())