ashishja commited on
Commit
33412d0
Β·
verified Β·
1 Parent(s): d9109f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -41
app.py CHANGED
@@ -7,10 +7,7 @@ import pandas as pd
7
  # Try to import Google ADK components, fallback to simple agent if not available
8
  try:
9
  from google.genai import types
10
- from agent import session_service, APP_NAME, USER_ID, SESSION_ID, code_agent, search_agent, image_agent, youtube_agent
11
- from google.adk.runners import Runner
12
- from google.adk.agents import LlmAgent
13
- from google.adk.tools import agent_tool
14
  GOOGLE_ADK_AVAILABLE = True
15
  print("βœ… Google ADK components loaded successfully")
16
  except ImportError as e:
@@ -128,48 +125,14 @@ class GoogleADKAgent:
128
  print("GoogleADKAgent initialized with Google ADK runner and agents.")
129
 
130
  try:
131
- # Create a specialized GAIA agent for complex multi-step questions
132
- self.question_agent = LlmAgent(
133
- name='gaiaAgent',
134
- model="gemini-2.5-pro-preview-05-06",
135
- description="You are an expert agent specialized in solving complex GAIA benchmark questions that require multi-step reasoning, research, and analysis",
136
- instruction=(
137
- "You are an expert agent designed to solve complex GAIA benchmark questions. "
138
- "These questions often require multiple steps, research, and different types of analysis. "
139
- "\n\nFor each question, follow this approach:"
140
- "\n1. ANALYZE the question carefully to identify what information is needed"
141
- "\n2. BREAK DOWN the question into logical steps if it involves multiple parts"
142
- "\n3. USE APPROPRIATE TOOLS:"
143
- "\n - For images/visual content: use the image agent"
144
- "\n - For web research/factual information: use the search agent"
145
- "\n - For data analysis/calculations/file processing: use the code agent"
146
- "\n - For YouTube videos: use the youtube agent"
147
- "\n4. CHAIN your reasoning across multiple steps when needed"
148
- "\n5. PROVIDE EXACT ANSWERS in the format requested"
149
- "\n\nIMPORTANT: Your final answer must be precise and match exactly what is asked. "
150
- "Pay attention to formatting requirements (lists, ordering, plural/singular forms, etc.). "
151
- "Do not include phrases like 'FINAL ANSWER:' - just provide the direct answer."
152
- ),
153
- tools=[
154
- agent_tool.AgentTool(agent=code_agent),
155
- agent_tool.AgentTool(agent=search_agent),
156
- agent_tool.AgentTool(agent=image_agent),
157
- agent_tool.AgentTool(agent=youtube_agent)
158
- ]
159
- )
160
-
161
- # Create runner with the question agent
162
- self.runner = Runner(
163
- agent=self.question_agent,
164
- app_name=APP_NAME,
165
- session_service=session_service
166
- )
167
  self.session_service = session_service
168
  self.app_name = APP_NAME
169
  self.user_id = USER_ID
170
  self.question_counter = 0 # To create unique session IDs for each question
171
  self.initialized = True
172
- print("βœ… Google ADK Agent successfully initialized")
173
 
174
  except Exception as e:
175
  print(f"❌ Failed to initialize Google ADK Agent: {e}")
@@ -187,6 +150,19 @@ class GoogleADKAgent:
187
  self.question_counter += 1
188
  unique_session_id = f"{SESSION_ID}_q{self.question_counter}"
189
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  # Create the query content
191
  query_content = types.Content(
192
  role='user',
@@ -194,12 +170,23 @@ class GoogleADKAgent:
194
  )
195
 
196
  # Run the agent synchronously using the runner with correct parameters
 
197
  events = list(self.runner.run(
198
  user_id=self.user_id,
199
  session_id=unique_session_id,
200
  new_message=query_content
201
  ))
202
 
 
 
 
 
 
 
 
 
 
 
203
  # Extract the final answer from the events
204
  final_answer = "No response generated."
205
 
 
7
  # Try to import Google ADK components, fallback to simple agent if not available
8
  try:
9
  from google.genai import types
10
+ from agent import session_service, APP_NAME, USER_ID, SESSION_ID, runner
 
 
 
11
  GOOGLE_ADK_AVAILABLE = True
12
  print("βœ… Google ADK components loaded successfully")
13
  except ImportError as e:
 
125
  print("GoogleADKAgent initialized with Google ADK runner and agents.")
126
 
127
  try:
128
+ # Use the pre-configured runner and root_agent from agent.py
129
+ self.runner = runner
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  self.session_service = session_service
131
  self.app_name = APP_NAME
132
  self.user_id = USER_ID
133
  self.question_counter = 0 # To create unique session IDs for each question
134
  self.initialized = True
135
+ print("βœ… Google ADK Agent successfully initialized using pre-configured runner")
136
 
137
  except Exception as e:
138
  print(f"❌ Failed to initialize Google ADK Agent: {e}")
 
150
  self.question_counter += 1
151
  unique_session_id = f"{SESSION_ID}_q{self.question_counter}"
152
 
153
+ # Create the session before using it
154
+ try:
155
+ self.session_service.create_session(
156
+ app_name=self.app_name,
157
+ user_id=self.user_id,
158
+ session_id=unique_session_id
159
+ )
160
+ print(f"βœ… Created session: {unique_session_id}")
161
+ except Exception as session_error:
162
+ print(f"⚠️ Session creation error: {session_error}")
163
+ # Fallback to the default session
164
+ unique_session_id = SESSION_ID
165
+
166
  # Create the query content
167
  query_content = types.Content(
168
  role='user',
 
170
  )
171
 
172
  # Run the agent synchronously using the runner with correct parameters
173
+ print(f"πŸš€ Running agent with session: {unique_session_id}")
174
  events = list(self.runner.run(
175
  user_id=self.user_id,
176
  session_id=unique_session_id,
177
  new_message=query_content
178
  ))
179
 
180
+ print(f"πŸ“Š Generated {len(events)} events")
181
+
182
+ # Debug: Print event details
183
+ for i, event in enumerate(events):
184
+ print(f"Event {i}: author={getattr(event, 'author', 'unknown')}, content_type={type(getattr(event, 'content', None))}")
185
+ if hasattr(event, 'content') and event.content and hasattr(event.content, 'parts'):
186
+ for j, part in enumerate(event.content.parts):
187
+ if hasattr(part, 'text') and part.text:
188
+ print(f" Part {j}: {part.text[:100]}...")
189
+
190
  # Extract the final answer from the events
191
  final_answer = "No response generated."
192