An advanced study on AI agent architecture using Google ADK (Agent Development Kit), FastAPI, Pydantic v2, and asynchronous event-driven execution.
This project demonstrates a production-ready transition from simple scripts to a resilient, microservice-oriented agent orchestration.
- Google ADK Runner Architecture: Implements the latest
Runnerpattern for managing agentic loops, event streams, and tool calls. - RESTful Interface: Powered by FastAPI with an interactive Swagger UI for real-time testing and orchestration.
- Hexagonal Design: Clear separation between Domain, Application, and Infrastructure layers, ensuring scalability and testability.
- Asynchronous & Non-blocking: Full
asyncioimplementation to handle I/O and event streams without blocking the main event loop. - Strict Validation: Pydantic v2 ensures data integrity across all agent-tool interactions.
- Resilience: Built-in retry logic with exponential backoff for robust API communication.
src/cabamodel/domain/– Core models and Pydantic schemas.src/cabamodel/infrastructure/– API implementation, ADK Adapters, and Tools.src/cabamodel/application/– Specialized agent definitions (e.g., temporal_agent, c4b4_bot).main.py– Entry point for the FastAPI server and agent initialization.
-
Clone the repository:
git clone https://github.com/your-username/CabaModel.git
-
Setup Environment: Create a
.envfile based on.env.exampleand add yourGOOGLE_API_KEY. -
Install Dependencies:
python -m venv venv .\venv\Scripts\activate pip install -e .
-
Run the API:
python main.py
-
Interact: Open your browser at http://127.0.0.1:8000/docs to access the interactive Swagger documentation.
from src.cabamodel.application.temporal_agent import root_agent
from src.cabamodel.infrastructure.agent_service import run_agent_async
async def main():
# Execute the agent using the ADK Runner-based service
response = await run_agent_async(root_agent, "What time is it now?")
print(f"Agent Response: {response}")
# This pattern handles tool-calling loops and event streams automaticallyDistributed under the Apache 2.0 License. See LICENSE for more information.