
- Build two tiny in-memory services:
- a fake user directory
- a fake service-status registry
- Implement two strongly-typed tools that return structured dictionaries so the LLM knows what to expect:
- lookup_user(email: str) -> Dict[str, Any]
- check_service_status(service_name: str) -> Dict[str, Any]
- Register these functions with an ADK Agent so the LLM can call them.
Comments and docstrings are visible to the LLM and can affect tool usage. Keep them accurate, concise, and machine-friendly.
| Tool | Signature | Success fields | Error fields |
|---|---|---|---|
| lookup_user | lookup_user(email: str) -> Dict[str, Any] | status: “success”, user: | status: “error”, error_message |
| check_service_status | check_service_status(service_name: str) -> Dict[str, Any] | status: “success”, service, status_text | status: “error”, error_message |
- Make lookups case-insensitive and tolerant of leading/trailing whitespace by lower-casing and stripping inputs.
- Returning a clear structure (status + payload or error_message) prevents the LLM from guessing shapes and reduces hallucinations.
- Explicitly list each tool in Agent.tools (e.g., tools=[lookup_user, check_service_status]) — this keeps tool availability explicit and discoverable by the agent.
- Keep docstrings short, factual, and up-to-date: the LLM relies on these to decide when and how to call a tool.
- ADK can auto-wrap plain Python functions as callable tools with structured I/O.
- The agent coordinates between the LLM and your functions: the LLM decides which tool to call and prepares inputs; the function returns structured data; the LLM then translates that structured data into natural language for the user.
- Explicit, structured tool outputs help avoid hallucination and allow concrete, checkable responses.
Common pitfalls and debugging:
- NameError or import errors often indicate a missing import or incorrectly registered tool. Verify your imports and that you included tools in Agent.tools.
- If the agent returns unexpected output, confirm your tool’s return schema matches its docstring and the LLM’s expectations.
- Implement stateful troubleshooting flows so the agent can remember context across multiple turns.
- Add authentication and access controls when you move from fake in-memory stores to real data sources.
- Split tools into modules for larger projects and add unit tests for each tool’s structured outputs.
- ADK and agent patterns: https://developers.google.com/ai
- Python typing docs: https://docs.python.org/3/library/typing.html