Programmatic Tool Calling (ADK Enhanced)
This skill provides the capability to write Python code that runs in a sandbox but can dynamically call other Agent tools.
Tool: run_programmatic_task
The primary tool exposed by this skill is run_programmatic_task.
Usage
You should use this tool when:
- •You need to perform a task that requires loops, conditionals, or complex data processing combined with tool calls.
- •You want to "batch process" something (e.g., search for 10 different terms and aggregate the results).
- •You need to feed the output of one tool into another loop.
When NOT to Use
Do not use this tool for simple, linear tasks where chain of thought is sufficient.
- •Bad Use Case: "Search for the weather in Paris." (Just call
web_searchdirectly) - •Bad Use Case: "Calculate 1+1." (Just execute code or output result directly)
- •Good Use Case: "Search for the weather in 5 different cities, compare them, and print the hottest one." (Requires
programmatic-tool-calling)
How to Write Code
The code you write will run in an async environment. You have access to a special function:
python
await call_tool(tool_name: str, **kwargs) -> Any
Example:
python
# Task: Search for 'Apple', 'Banana', 'Cherry' and count the length of results.
results = {}
queries = ['Apple', 'Banana', 'Cherry']
for q in queries:
# Notice the 'await' and the tool name string
# 'web_search' or 'google_search' depending on what tools are loaded
output = await call_tool('web_search', query=q)
results[q] = len(str(output))
print(f"Search lengths: {results}")
Supported Libraries
- •
pandas(aspd) - •
matplotlib.pyplot(asplt) - •
asyncio - •Standard Python 3.12 libraries
Important Notes
- •Always use
awaitwhen usingcall_tool. - •Check Tool Names: You can only call tools that are currently loaded on the Agent. If you are unsure, just try to use the likely name or ask (internally).
- •Output: The tool returns the
stdout(print output) of your script. Ensure youprint()the final result you want to see. - •No
asyncio.run(): The code is executed in an already running event loop. Do NOT useasyncio.run(),loop.run_until_complete(), ortime.sleep(). Instead, simplyawaityour functions or useawait asyncio.sleep(). - •Entry Point: Ensure your main logic is called at the top level, e.g.,
await main(). - •Prevent UI Lag: Since generating code takes time, YOU MUST output a brief "Thinking" or plan before calling this tool.
- •Bad: (Silent) -> Calls tool -> User waits 10s -> Result.
- •Good: "Thinking: I will write a script to fetch data..." -> Calls tool -> User sees text immediately.