Repository navigation
feat(claude-code): type a model key refusal as model_key_budget or model_key_auth, not agent_error - #710
Draft
andrewpark-scaleai wants to merge 2 commits into
Conversation
…y_budget or model_key_auth Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…del_key_auth, not agent_error The bridge reads the CLI's api_error_type and api_error_status from its terminal result event, and the A2A server passes the type to builder.failed, so agent-env no longer blames the agent for an out-of-budget or rejected key. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 16, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #695 (base is that branch, not
main). Waits for the protocol release that contains #695. Do not mark ready before that release is on PyPI.Why
AgentEnv should say why every run failed, and heal itself where code can. Today a claude-code run whose model key is out of budget or rejected is blamed on the agent. #695 adds the
model_key_budgetandmodel_key_autherror types to the protocol. This PR makes the claude-code agent report them.When the model endpoint refuses the key, the Claude Code CLI exits 1 and its terminal
resultevent names the cause as fields:api_error_statusandapi_error_type(for example400/budget_exceededfrom LiteLLM,401/authentication_errorfrom Anthropic). The agent's A2A server ignored those fields and calledbuilder.failed("cli_error", ...)with noerror_type, so the protocol's defaultagent_errorreached the framework.What
resultevent into aTaskErrorTypewhen the CLI fails.api_error_type == "budget_exceeded"givesmodel_key_budget. A 401 or 403, or a type ofauth_error,authentication_errororpermission_error, givesmodel_key_auth. Anything else staysagent_error. The A2A server passes it tobuilder.failed.Why this is a separate PR
The claude-code image installs
agentenv-framework-protocolfrom PyPI at or above the floor in itsrequirements.txt, not from this tree. CONTRIBUTING.md and AGENTS.md say an agent's floor rises only once the protocol it names is published. This code importsTaskErrorTypeand sends values the published protocol (0.1.556 and earlier) rejects, so it cannot run in the image until a release carries #695. Shipping it with #695 broke the claude-code image build. I kept it out of #695 rather than adding a try-import or a string fallback that would exist only to straddle one release.Before marking ready: raise the floor in
src/agent_env/agents/agents/claude-code/requirements.txtto the first published release that contains #695, and updatetst/unit/agents/claude_code/test_image_contract.pyto match. Until then the floor stays at>=0.1.351, and this PR's claude-code integration tests are expected to fail on the missingTaskErrorTypeimport.Design decisions and tradeoffs
_terminal_result,_status), so the mapping lives there and the server only forwards a typed value.agent_error. Rate limits (429) and bad requests (prompt too long) keep the old type. This PR only reclassifies the two causes the endpoint states outright.failed("cli_error", ...)default. Their CLIs' output for a budget or auth refusal was not captured, so they are left for later rather than guessed.How to verify
The test events are trimmed from captures of Claude Code CLI 2.1.325 run against a local fake endpoint that answers with each error body.
Result: 286 passed. Without the bridge change,
test_model_key_errors.pyfails for the four key cases (litellm-budget,litellm-auth,anthropic-auth,anthropic-permission) witherror_type == "agent_error".