Skip to content

fix(agent): raise AgentLLMError after retry exhaustion - #1943

Open
tripathiji1312 wants to merge 1 commit into
kyegomez:masterfrom
tripathiji1312:fix/agent-raise-after-retry-exhaustion
Open

fix(agent): raise AgentLLMError after retry exhaustion#1943
tripathiji1312 wants to merge 1 commit into
kyegomez:masterfrom
tripathiji1312:fix/agent-raise-after-retry-exhaustion

Conversation

@tripathiji1312

Copy link
Copy Markdown

Summary

Agent.run previously swallowed LLM failures: the retry loop caught bare Exception, and after exhausting retries it returned the raw conversation transcript as if it were the answer. This PR makes it honest — matching the docstring contract.

Changes

  • swarms/structs/agent.py — 2 hunks, 15 lines:
    • _run retry loop: remove bare Exception from the except tuple (only BadRequestError, InternalServerError, AuthenticationError are retried; other errors propagate immediately).
    • if not success: block: raise AgentLLMError(...) with the attempt count instead of logger.error(...) + break (the transcript-return lets callers act on garbage output with no signal the model never responded).
    • run() fallback path: same except-tuple tightening (remove Exception).
  • tests/telemetry/test_telemetry_multi_agent_core.py — the FakeLLM now raises a realistic BadRequestError, and the per-architecture error tests assert the new honest behavior (AgentLLMError propagation + Agent.llm_error span, instead of the old always-swallowed completed/OK).
  • tests/structs/test_agent_run_errors.py — new: TestFailureHonesty (3 tests: raise after retries, message reports attempt count, hierarchy).

Why this PR is small

Split from #1931 (21 files → 3 PRs) per maintainer feedback. The other two are:

Verification

  • New tests: 3/3 pass; telemetry suite: 28 passed / 157 passed across tests/telemetry/.
  • Full tests/structs/ + tests/telemetry/ vs baseline: zero new failures outside the expected skips (markers are in test: skip live-LLM tests when no API key is set #1940 — this PR intentionally does NOT include them so the diff stays reviewable).

Agent.run previously swallowed LLM failures: the retry loop caught bare
Exception and, after exhausting retries, returned the raw conversation
transcript as if it were the answer. It now:

- catches only litellm errors (BadRequestError, InternalServerError,
  AuthenticationError) so non-retryable errors propagate immediately, and
- raises AgentLLMError (matching the documented contract) instead of
  returning the transcript, with the attempt count in the message.

Split from kyegomez#1931: this PR is the behavior change only (2 hunks in
agent.py, 1 telemetry file, 1 new test file). The requires_llm markers
(kyegomez#1940) should land first so the live-LLM tests stay green; the error
re-export (kyegomez#1939) is independent.
@github-actions

Copy link
Copy Markdown

Hello there, thank you for opening an PR ! 🙏🏻 The team was notified and they will get back to you asap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant