What this prompt does
This prompt implements Gemini function calling end to end, focusing on the hard parts: the calling loop, parallel calls, retries, and safety guardrails rather than the happy path. It runs through six steps: defining function declarations, implementing the calling loop, building multi-turn conversation handling, adding error handling, applying validation and safety guardrails, and writing integration tests. It scaffolds the validation, rate limiting, and audit logging you would otherwise hand-write every time you build an agent.
The variables tailor it to your agent. [sdk_language] sets the implementation language, [function_count] and [use_cases] define the tool declarations, and [parallel_calls] controls concurrency. [max_turns] and [max_tokens] shape conversation context management, [max_retries] bounds retries, [user_roles] and [rate_limit] enforce access and loop limits, and [test_count] sizes the integration test suite. The allow-list keyed on [user_roles] is the guardrail that keeps an agent from doing something it shouldn't, and it sits alongside argument validation and audit logging so every call is checked before it runs. These are the parts of agent development that are tedious to write by hand yet essential to get right.
When to use it
- You are building an AI agent where function calling is the core mechanism.
- You need a robust calling loop that executes tools and feeds results back to Gemini.
- You want concurrent execution when Gemini requests parallel function calls.
- You need multi-turn context management that summarizes older turns under a token cap.
- You want validation, role-based allow-lists, rate limiting, and audit logging built in.
- You need integration tests covering ambiguous prompts and function-failure handling.
Example output
Expect [function_count] function declarations with JSON Schema parameters, enum constraints, and required/optional markers covering your [use_cases]. The implementation steps produce a [sdk_language] calling loop that parses function calls and returns results, concurrent execution for up to [parallel_calls] calls, multi-turn history management with summarization beyond [max_tokens], and structured error responses with retries up to [max_retries]. Guardrails enforcing [user_roles] and [rate_limit] plus [test_count] integration tests with mocked Gemini responses round it out. It is mostly working code, with the loop, error handling, and safety checks treated as the core of the agent rather than optional extras.
Pro tips
- Write tight function descriptions; Gemini decides when to call each one, so vague descriptions on your
[function_count]tools cause wrong selections. - Use enum constraints and clear required-vs-optional markers in the schemas so arguments stay well-formed.
- Cap
[parallel_calls]to what your backend can actually run concurrently to avoid overload. - Implement the allow-list and injection checks yourself with care; the
[user_roles]guardrail is where real agents get dangerous. - Set
[rate_limit]to prevent runaway loops, and pair it with[max_retries]so failures don't spin forever. - Mock Gemini responses for the
[test_count]scenarios so tests stay deterministic across runs instead of depending on live API behavior.