Agent Model Layered Configuration and Troubleshooting

    Saving a model name is not the same as using it at runtime. This guide covers YAML versus environment variables, a five-layer call model, why default-model changes often fail, a repeatable troubleshooting sequence, and how to keep upgrades and multi-environment setups from drifting.

    Saving a default in a UI or CLI does not guarantee the agent uses that stack at runtime. Common failures include still hitting an old base URL or protocol, or silently falling back to built-in behavior when a key is empty. For agents, model configuration is more than a name: it also sets routing, auth, request shape, and fallback after failure. The layers below are meant for engineering checks, not guesswork.

    Two files, two jobs

    Data-centric config (often YAML) describes structure: default model id, provider name, base URL, call mode, and whether fallback is allowed. Hierarchy is clearer than a flat key-value map for “one primary model plus per-task overrides.” YAML can express the same shapes as JSON and is easier to maintain by hand, but indent errors can invalidate a whole block. After edits, validate syntax; an editor that is not red is not enough.

    Environment files hold secrets and values that change by environment: keys, tenant ids, regions. The process reads the environment at start; the structure file only keeps reference names. The same structure can then be reused across development, test, and production without putting secrets in version control. Keys written into structure config may work briefly, then leak when configs are copied, screenshots are taken, or files are synced to another machine.

    A practical boundary: structure answers “whom to call, with which protocol, and what to do on failure.” Environment answers “which key, which environment.” Missing either side, or mismatched names, looks like “I changed it but runtime did not.”

    Five layers of a complete call

    These layers are a generic decomposition for troubleshooting order, not a product-specific API.

    Layer 1: primary model. The identifier bound to default chat when the user does not pick a model. Ids are defined by the provider and may include a series name and version suffix. After an agent or service upgrade, old ids may be retired or renamed: the file still parses, but requests are rejected or mapped elsewhere. The id should also match the task: a completion-oriented model is not automatically a long-form Q&A model. HTTP 200 is not the same as capability fit.

    Layer 2: provider and base URL. The provider is a logical name for logs and multi-backend switching; the base URL is the HTTP entry point. They must stay paired. Changing only the model name while keeping an old URL, or only the URL while keeping an old model name, is a frequent fault. Whether the URL includes a version path must follow the provider’s documentation, not habits from another project. With a gateway or proxy in front, the host in logs may differ from the configured base URL; check both agent logs and gateway access logs.

    Layer 3: credentials. Keys and tokens should come from environment variables or local secret stores, least privilege, rotated on a schedule. Plaintext in config is a temporary state and should be moved out. Empty keys, extra spaces, quotes treated as part of the value, and export in a terminal that a GUI-launched process does not inherit, can make the same command behave differently by launch method. When checking, print whether the variable is set and whether length looks reasonable—not the secret itself.

    Layer 4: call mode. The protocol shape of the request body. Chat completions, legacy text completions, and tool-calling extensions do not share paths or field names. A mismatch may error immediately or drop tool fields so the agent can chat but not act. After a client upgrade, the default mode may change while an old server does not. Pair this layer with model capability: a model without function calling should not be forced into a tool-heavy protocol.

    Layer 5: scenario routing and fallback. Summarization, embeddings, reranking, and vision often need different ids or even different base URLs. List allowed models explicitly and reject misses instead of swapping in an unknown model. On primary failure, fall back only to predeclared, protocol-compatible alternatives, and log both planned and actual model. Without this layer you cannot tell a bad write from a runtime override.

    What the primary-model block should look like

    Keep the structure flat and each field single-purpose. Placeholders must be your own service details—do not copy domains or keys from third-party samples:

    1. model:
    2. default: "<model-id>"
    3. provider: "<logical-provider-name>"
    4. base_url: "<inference-base-url>"
    5. api_mode: chat_completions
    6. credential_env: MODEL_API_KEY

    Put only the key in the environment, for example MODEL_API_KEY. default is the chat default id; provider distinguishes backends in logs; base_url must belong to that id’s service; api_mode declares request shape; credential_env names the variable so the structure file stays free of secrets.

    If the platform supports per-task overrides, use a separate section rather than stuffing conditions into defaults—for example a dedicated embedding id and dimension so it is not mixed with chat. Field names follow your software’s docs; the keys above illustrate roles, not a universal schema.

    Cloud inference and self-hosted services can coexist. For example, after enabling general LLM inference on Baidu AI Cloud, write model id, base URL, and key with the same split, and use a distinct logical provider name so it is not mixed with local or other environments. Do not mix incompatible protocols under one logical name.

    Why changing the default model still does nothing

    Suspect load path first, not the model. Agents may read user-level, project-level, or container-mounted files. You may edit the copy in a file manager while the process reads another. Confirm with the product’s “print effective config” or the config path in startup logs. If needed, add a harmless marker in the suspect file, restart, and see whether it appears.

    Next, process environment. Services started as scheduled tasks, system services, or desktop shortcuts may not load the env file you edited in an interactive shell. Check variables in that launch method’s working directory and user context. In containers, confirm injection into the container, not only the host.

    Then cache and session. An open session may stay bound to the old model; a new session may be required. Some implementations persist “last successful model” locally with higher priority than the config file. Back up before clearing state, and confirm where the docs put state files.

    Finally, compatibility. A client upgrade may stop accepting a plan, path, or field; a server upgrade may retire an id. Record both versions. With only one inference service you cannot A/B “client no longer supports this integration” versus “server rejected this client.” Keep request ids, HTTP status, and error bodies (keys stripped) and compare to current docs instead of only renaming the model.

    A repeatable troubleshooting order

    1. Confirm the config and env paths the process actually loads; rule out editing the wrong files.
    2. Validate structure-file syntax: indent, space after colons, quotes.
    3. Check that the primary model id is still on the provider’s current list, matching case and version suffix.
    4. Check base URL, path prefix, and call mode against that model’s docs. Send a minimal request to the inference API, bypassing the agent, to separate network/auth from request assembly.
    5. Confirm the key variable exists in that process with no extra whitespace; restart after rotation so old processes do not keep old values.
    6. Read one full call log: planned model, actual model, provider, mode, status, latency. If actual ≠ planned, go back to layer 5 for overrides and fallback.
    7. Retest in a new session. If it still fails, pin client and server versions, use a minimal config (primary-model essentials only), then add scenario routing one item at a time to find the regression.

    Do not paste full keys, tokens, or request bodies with personal data. When asking for help, replace account-specific parts of the base URL with placeholders.

    Upgrades and multiple environments

    Treat “model id + call mode + required request fields” as a compatibility contract in the changelog. After either client or server upgrades, smoke-test the contract in non-production: ordinary chat, long context, tool calling if enabled, and failure fallback. Only then change production defaults.

    Share one structure template across environments; keep differences in env vars and a small overlay. Do not hand-edit production “just to get it running” without writing back to the template, or the next deploy will overwrite the fix.

    Separate inference keys from console/admin keys; the agent should hold only call permissions. Logs and metrics should at least include provider, model id, mode, status, and error class so silent fallback to an old model is visible as config drift.

    Summary

    Stable agent model config comes from splitting structure and environment, and from keeping primary model, URL, credentials, protocol, and routing/fallback consistent. Changing a default on the command line only touches the first-layer entry. If path, process env, session state, or protocol disagree, it still looks unchanged. Check effective config path, id, base URL, mode, key, and actual hit model in that order, and regress with a minimal config, so opaque failures become repeatable engineering issues.