Inspiration

As a data analyst with 16 years of experience, I have always sought to optimize my own performance. My journey began with a frustration shared by many: health data is currently scattered across fragmented, disconnected platforms. I wanted to move beyond generic fitness advice and build a system that respects the individual's specific biological baseline—a centralized "source of truth" for health optimization that functions as a rational, evidence-based co-pilot.

What it does

IC-habit-agentic-loop is an autonomous physiological optimization engine. It ingests historical data (sleep, exercise, and body metrics) and uses an agentic loop to identify patterns, such as the correlation between training load and recovery quality. The agent provides a "Metabolic Drift" analysis, recommending specific adjustments like the "3-2-1 Protocol" or a "Deload Phase" when physiological strain exceeds recovery capacity. All significant decisions are automatically logged into the database, creating a long-term audit trail of the user’s health optimization strategy.

How we built it

The project was constructed as an autonomous system with three core pillars:

  1. Data Integration: Used MongoDB to store persistent logs and enforced data integrity using Pydantic models (e.g., UserProfile, DietaryStrategy), ensuring the LLM always works with validated, schema-compliant JSON.
  2. Agentic Orchestration: Built using the Google Agent Development Kit (ADK), where the habit_os_control_agent (root) coordinates three specialized sub-agents: a Sleep Analyst, an Exercise Metrics Analyst, and a Weight Analyst.
  3. Deployment: Leveraged uv for package management and gcloud for deployment to Cloud Run, ensuring a scalable, production-ready environment.

Challenges we ran into

The most significant hurdle was migrating the legacy ReAct logic to the modern ADK framework (v1.15+). Early iterations encountered an AttributeError: 'NoneType' object has no attribute 'response_modalities' because I attempted to manually clone and inject the InvocationContext. I learned that manual state management is brittle, and the solution was to replace private API manipulation with the public Runner and InMemorySessionService pattern, which handles context initialization natively.

Accomplishments that we're proud of

We successfully refactored a complex multi-agent system from a brittle, internal-hack architecture to a clean, framework-compliant design using the public Runner API. We created a loop where an autonomous agent not only provides advice but also writes its own "Decision Log" back to MongoDB, enabling long-term tracking of the agent's logic. Furthermore, we successfully bridged the gap between raw, messy health data and structured, LLM-ready insights by implementing a strict Pydantic validation layer.

What we learned

I learned that utilizing stable, public framework contracts is superior to "hacking" private internals, even when those hacks seem faster in the short term. Breaking down complex health optimization into specialized sub-agents allows for expert-level insights, as each sub-agent can be tuned with specific, narrow instructions that a monolithic agent would lose in its context window. Additionally, I reinforced the understanding that LLM reasoning is most effective when it is guided by simple but powerful quantitative relationships.

What's next for ic-habit-agentic-loop

Future goals include building a front-end dashboard to visualize the "Metabolic Drift" scores over time. We also plan to implement a recurring cron-job that triggers the agent to check for anomalies in daily metrics before the user even asks, as well as integrating more external health APIs (e.g., Apple Health, Google Fit) to move beyond manual data entry and create a truly "zero-touch" monitoring system.

Built With

  • adk
  • asyncio
  • fastapi
  • googlecloudrun
  • googlesecretmanager
  • mcp
  • mongodb
  • pydantic
  • python
Share this project:

Updates

Submission history