openclaw - 💡(How to fix) Fix feat: expose resolved backend model in session_status and agent runtime [2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#51441Fetched 2026-04-08 01:11:11
View on GitHub
Comments
2
Participants
3
Timeline
2
Reactions
0
Author
Timeline (top)
commented ×2

Fix Action

Fix / Workaround

Workaround in use

Code Example

model: litellm/complex (requested)
   resolvedModel: openai/gpt-5.4 (actual)
   fallbackUsed: true
RAW_BUFFERClick to expand / collapse

Problem

When using LiteLLM (or any routing proxy) as the LLM provider, agents only see the requested model alias (e.g. litellm/complex) — not the actual backend model that was used (e.g. openai/gpt-5.4 or anthropic/claude-sonnet-4-6).

This creates a blind spot: agents can't answer "did a fallback happen?" or "what model actually served this response?" without log-diving.

Current behavior

session_status returns the configured/requested model. The agentMeta.model in runResult.meta is populated from CLI runners (claude-cli, codex, etc.) but not from the OpenAI-compatible path — so when LiteLLM routing is used, agentMeta.model falls through to fallbackModel ?? defaultModel (the configured alias, not the resolved backend).

persistSessionUsageUpdate stores modelUsed and providerUsed from agentMeta, so this gap flows through to the session store.

Requested feature

  1. Capture response.model from OpenAI-compatible responses in the provider transport layer and expose it as agentMeta.resolvedModel / agentMeta.resolvedProvider

  2. Add resolvedModel, resolvedProvider, fallbackUsed fields to GatewaySessionRow and persist them via persistSessionUsageUpdate

  3. Expose in session_status tool output:

    model: litellm/complex (requested)
    resolvedModel: openai/gpt-5.4 (actual)
    fallbackUsed: true
  4. Include in agent runtime text injection so agents can introspect routing decisions without tool calls

  5. Optional: pass session/agent metadata as LiteLLM request tags so /spend/logs entries can be correlated to specific agent sessions

Workaround in use

We currently query http://localhost:4000/spend/logs directly (LiteLLM's spend log API) to surface resolved model info. The fields model_group (= requested tier) and model (= actual backend) are both present there. This works but requires a separate API call and is not surfaced to the agent in-band.

Files involved

  • dist/agents/steerable-provider-transport.js — capture response.model from API responses
  • dist/auto-reply/reply/session-usage.js + .d.ts — add new fields to persistSessionUsageUpdate
  • dist/auto-reply/reply/agent-runner.js + followup-runner.js — pass resolved fields to usage update
  • dist/gateway/session-utils.types.d.ts + session store — add resolvedModel, resolvedProvider, fallbackUsed to GatewaySessionRow
  • dist/agents/tools/session-status-tool.js — expose in tool output
  • dist/commands/status.summary.js — expose in CLI status output

Impact

High — any deployment using LiteLLM, OpenRouter, or any routing proxy is blind to actual model routing. Debugging fallbacks requires log access rather than in-band observability.

extent analysis

Fix Plan

To address the issue, we need to capture the response.model from OpenAI-compatible responses and expose it as agentMeta.resolvedModel / agentMeta.resolvedProvider. Here are the concrete steps:

  • In dist/agents/steerable-provider-transport.js, capture response.model from API responses:
const response = await fetch(url, options);
const responseBody = await response.json();
const resolvedModel = responseBody.model;
// Expose resolvedModel as agentMeta.resolvedModel
  • In dist/auto-reply/reply/session-usage.js, add new fields to persistSessionUsageUpdate:
interface GatewaySessionRow {
  // ...
  resolvedModel: string;
  resolvedProvider: string;
  fallbackUsed: boolean;
}

function persistSessionUsageUpdate(sessionRow: GatewaySessionRow) {
  // ...
  sessionRow.resolvedModel = agentMeta.resolvedModel;
  sessionRow.resolvedProvider = agentMeta.resolvedProvider;
  sessionRow.fallbackUsed = agentMeta.fallbackUsed;
  // ...
}
  • In dist/auto-reply/reply/agent-runner.js and followup-runner.js, pass resolved fields to usage update:
function runAgent() {
  // ...
  const agentMeta = {
    // ...
    resolvedModel: resolvedModel,
    resolvedProvider: resolvedProvider,
    fallbackUsed: fallbackUsed,
  };
  // ...
  persistSessionUsageUpdate(sessionRow);
}
  • In dist/gateway/session-utils.types.d.ts, add resolvedModel, resolvedProvider, fallbackUsed to GatewaySessionRow:
interface GatewaySessionRow {
  // ...
  resolvedModel: string;
  resolvedProvider: string;
  fallbackUsed: boolean;
}
  • In dist/agents/tools/session-status-tool.js, expose in tool output:
function getSessionStatus() {
  // ...
  console.log(`model: ${agentMeta.model} (requested)`);
  console.log(`resolvedModel: ${agentMeta.resolvedModel} (actual)`);
  console.log(`fallbackUsed: ${agentMeta.fallbackUsed}`);
}

Verification

To verify that the fix worked, you can:

  • Check the session_status tool output to see if the resolvedModel and fallbackUsed fields are populated correctly.
  • Query the http://localhost:4000/spend/logs API to see if the model_group and model fields match the resolvedModel and fallbackUsed fields in the session_status tool output.
  • Test the agent runtime text injection to see if the agents can introspect routing decisions without tool calls.

Extra Tips

  • Make sure to update the documentation to reflect the new fields and behavior.
  • Consider adding logging or monitoring to track the usage of the new fields and detect any potential issues

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix feat: expose resolved backend model in session_status and agent runtime [2 comments, 3 participants]