Skip to content

[Epic] Hybrid ADK + AI SDK Migration #19

@aWN4Y25pa2EK

Description

@aWN4Y25pa2EK

Summary

Migrate the HCA-I2P MVP from the current multi-SDK approach to a hybrid architecture:

  • Keep: Google ADK for agent orchestration (LlmAgent, Runner, SessionService, FunctionTool)
  • Add: Vercel AI SDK with @openrouter/ai-sdk-provider for LLM calls
  • Remove: Direct openai SDK usage, @opencode-ai/sdk dependency

Motivation

Current architecture uses 3 different approaches for LLM calls:

  1. Custom OpenRouterLlm adapter with raw fetch (fragile format conversion)
  2. openai SDK in llm-invoke.ts
  3. @opencode-ai/sdk for extended thinking

Issues with current approach:

  • Tool call ID instability (Date.now() collisions)
  • No streaming support in ADK adapter
  • Format conversion bugs (Gemini vs OpenAI message formats)
  • Multiple codepaths for same functionality

Benefits of AI SDK

  • Native OpenRouter provider with extended thinking support
  • Unified API across providers
  • Built-in streaming with proper backpressure
  • Provider registry for multi-model routing
  • Proper reasoning token tracking

Migration Phases

Phase 1: Add AI SDK Dependencies

Phase 2: Create AI SDK LLM Tool

Phase 3: Update OpenRouterLlm Internals

Phase 4: Migrate Analysis Stages

Phase 5: Remove OpenCode Dependency

Phase 6: Validation & Cleanup

Architecture After Migration

┌─────────────────────────────────────────────────┐
│                  Google ADK                      │
│  (Agent orchestration, Session, FunctionTool)   │
└─────────────────────┬───────────────────────────┘
                      │
┌─────────────────────▼───────────────────────────┐
│              AI SDK Provider Registry            │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────┐  │
│  │  boundary   │  │    gap      │  │decomp:  │  │
│  │  (flash)    │  │  (opus)     │  │thinking │  │
│  └─────────────┘  └─────────────┘  └─────────┘  │
└─────────────────────┬───────────────────────────┘
                      │
┌─────────────────────▼───────────────────────────┐
│         @openrouter/ai-sdk-provider              │
│            (OpenRouter API)                      │
└─────────────────────────────────────────────────┘

Related Files

  • src/holons/adk/openrouter-llm.ts - Custom LLM adapter
  • src/holons/adk/agents.ts - Agent definitions
  • src/tools/llm-invoke.ts - OpenAI SDK wrapper
  • src/tools/opencode-client.ts - Extended thinking
  • src/config.ts - Configuration

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions