Skip to content

feat: replace litellm with openrouter adapter - #193

Merged
QueryPlanner merged 1 commit into
mainfrom
feat/remove-litellm-openrouter-adapter
Oct 22, 2026
Merged

QueryPlanner merged 1 commit into
mainfrom
feat/remove-litellm-openrouter-adapter

Conversation

@QueryPlanner

Copy link
Copy Markdown
Owner

What

Replace LiteLLM with a thin OpenRouter adapter built on the OpenAI-compatible API.

Why

Blacki only needs OpenRouter chat completions, and LiteLLM is no longer required. Removing it eliminates the dependency and its compromised 1.107.0 release path from the runtime image and development lockfile.

How

  • Add OpenRouterLlm, an ADK BaseLlm backed by AsyncOpenAI against https://openrouter.ai/api/v1.
  • Convert ADK system instructions, text, inline images, function tools, function calls/responses, reasoning settings, and sampling parameters.
  • Synthesize blacki_call_* IDs so ADK's replay-time stripping of adk-* IDs cannot orphan tool results.
  • Stream partial text/reasoning deltas and emit one final aggregate with usage and finish reason.
  • Record provider-reported token and cost usage in the existing SQLite ledger.
  • Switch mem0 to OpenRouter's OpenAI-compatible openai provider.
  • Remove google-adk[eval] from dev dependencies because its evaluation extra pulls LiteLLM transitively, and add a lockfile regression test.
  • Update docs, env samples, and dashboard text.

Tests

  • uv run ruff format
  • uv run ruff check
  • uv run mypy .
  • uv run pytest --cov=src — 2168 passed, 1 skipped, 100% coverage
  • Confirmed litellm is absent from uv.lock and from sys.modules after importing blacki.agent

Breaking Changes

  • adk eval now requires explicitly installing google-adk[eval]; that extra reintroduces LiteLLM transitively in the dev environment.
  • MEM0_LLM_PROVIDER=litellm is no longer supported. It maps to openai when OPENROUTER_API_KEY is set and fails clearly otherwise.
  • MEM0_LLM_MODEL must be an OpenRouter author/slug ID when OPENROUTER_API_KEY is set.

Related Issues

None.

- Add a thin ADK OpenRouter adapter over the OpenAI SDK
- Remove LiteLLM from runtime and dev dependencies
- Map ADK messages, tools, images, reasoning, and usage
- Record provider-reported OpenRouter costs in the ledger
- Switch mem0 to OpenRouter's OpenAI-compatible provider
- Update docs and tests for the new model boundary
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T03:45:27.101439Z e188276 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e18827614c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +138 to +140
if mapped != types.FinishReason.STOP:
response.error_code = mapped
response.error_message = _finish_error_message(mapped)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve valid text on MAX_TOKENS completions

When OpenRouter returns finish_reason="length" with a valid text prefix, this branch marks the response as an error. ADK propagates those fields to the event, and AdkRuntime._build_event_error raises before returning the collected content, so reaching a model or token limit becomes a total user-visible failure rather than a truncated answer carrying finish_reason=MAX_TOKENS. Keep the finish reason, but populate the error fields only when there is no usable content, as is already done for malformed truncated tool calls.

AGENTS.md reference: AGENTS.md:L175-L177

Useful? React with 👍 / 👎.

@QueryPlanner
QueryPlanner merged commit 8527f41 into main Oct 22, 2026
3 checks passed
@QueryPlanner
QueryPlanner deleted the feat/remove-litellm-openrouter-adapter branch October 22, 2026 04:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant