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

Function get_population

contributing/samples/tools/parallel_functions/agent.py:174–211  ·  view source on GitHub ↗

Get population information for multiple cities. Args: cities: A list of city names. Returns: A dictionary with population data for each city.

(cities: List[str], tool_context: ToolContext)

Source from the content-addressed store, hash-verified

172
173
174async def get_population(cities: List[str], tool_context: ToolContext) -> dict:
175 """Get population information for multiple cities.
176
177 Args:
178 cities: A list of city names.
179
180 Returns:
181 A dictionary with population data for each city.
182 """
183 # Simulate async processing time proportional to number of cities (non-blocking)
184 await asyncio.sleep(len(cities) * 0.5)
185
186 # Mock population data
187 populations = {
188 'New York': 8336817,
189 'London': 9648110,
190 'Tokyo': 13960000,
191 'San Francisco': 873965,
192 'Paris': 2161000,
193 'Sydney': 5312163,
194 }
195
196 results = {}
197 for city in cities:
198 results[city] = populations.get(city, 1000000) # default 1M if not found
199
200 # Store in context for testing thread safety
201 if 'population_requests' not in tool_context.state:
202 tool_context.state['population_requests'] = []
203 tool_context.state['population_requests'].append(
204 {'cities': cities, 'results': results}
205 )
206
207 return {
208 'populations': results,
209 'total_population': sum(results.values()),
210 'cities_count': len(cities),
211 }
212
213
214root_agent = Agent(

Callers

nothing calls this directly

Calls 3

getMethod · 0.45
appendMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected