Skip to content

test: react_using_mellea.py example fails intermittently — ReACT loop exceeds 10 iteration budget #684

Closed
1 of 1 issue completed

Description

@planetf1

docs/examples/agents/react/react_using_mellea.py fails when the model does not converge on a final_answer within the default loop budget:

RuntimeError: could not complete react loop in 10 iterations

To reproduce:

uv sync --all-extras --all-groups
uv run pytest --durations=0 --ignore=test/formatters/granite/test_intrinsics_formatters.py -v

Environment:

  • MacBook M1 (Apple Silicon, macOS)
  • Python 3.12.8
  • Backend: ollama, model: granite4:micro

Observed behaviour: The model repeatedly calls duckduckgo_results_json but never calls final_answer, exhausting all 10 iterations. This is non-deterministic — it depends on model output.

Current markers: # pytest: ollama, llm

Suggested fix: Add qualitative and slow markers so the example is skipped by default locally and in CI, consistent with other non-deterministic examples:

# pytest: ollama, llm, qualitative, slow

Sub-issues

Sub-issues

1 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. changed the title [-]react_using_mellea.py example fails intermittently — ReACT loop exceeds 10 iteration budget[/-] [+]test: react_using_mellea.py example fails intermittently — ReACT loop exceeds 10 iteration budget[/+] on Mar 18, 2026
  2. planetf1 commented on Mar 18, 2026

    @planetf1
    ContributorAuthor

    We may also be able to improve the test code so it's more likely to converge

  3. planetf1 commented on Mar 18, 2026

    @planetf1
    ContributorAuthor

    Analysis of the root cause

    The issue is a combination of test design and a prompt weakness — 10 iterations is plenty for a working ReACT agent; the problem is the model never converging.

    Prompt weakness

    The "if you catch yourself repeating the same thing, call final_answer" hint is only in ReactInitiator.jinja2 (the setup message). ReactThought.jinja2, which is rendered on every turn, only says:

    "If you are done and have a final answer, call the final_answer tool."

    There's no per-turn signal that the model is looping or any urgency as iterations tick up. A model may not retain the initiator instruction after several tool-call results fill its context, so reinforcing this each turn would help.

    Adding something like the following to ReactThought.jinja2 would help small and large models alike:

    "If you already have enough information from previous observations, do not search again — call final_answer now."

    Test design problems

    1. Live DuckDuckGo — non-deterministic, rate-limited, returns variable result formats. A model may not parse them reliably or recognise when it has "enough".
    2. Open-ended goal — "What is the Mellea python library?" has no clear stopping point. The model doesn't know when it has gathered sufficient information. A closed-domain question (e.g. one whose answer is deterministically in the first search result) would converge more reliably.

    Suggested path forward

    • Short term: add the qualitative and slow markers as suggested — this is the right pragmatic fix for CI/local runs.
    • Medium term: improve ReactThought.jinja2 to reinforce the stopping condition on every turn.
    • Longer term: consider a version of the example (or a separate unit test) that uses a mock/stub tool so the ReACT loop logic can be tested deterministically without a live network dependency.
  4. markstur commented on Mar 27, 2026

    @markstur
    Contributor

    I can work on this. I was reproducing it and I think I have a couple possible bug fixes related to it (investigating).

  5. markstur commented on Mar 27, 2026

    @markstur
    Contributor

    I tried tweaking the jinja and wasn't getting better results

    I'd close this after those 2 are merged, but since I punted on jinja and query re-write I'm not sure

  6. self-assigned this
    on Apr 10, 2026
  7. markstur commented on May 6, 2026

    @markstur
    Contributor

    This might be fixed by #896

    My script that looped until it reproduced the problem is not hitting it anymore. At least not today.

  8. removed their assignment
    on May 7, 2026
  9. added
    area/backends
    area/adapter-functions
    area/stdlib
    on May 20, 2026
  10. planetf1 commented on May 27, 2026

    @planetf1
    ContributorAuthor

    will take a look & verify I too don't see an issue

  11. planetf1 commented on May 27, 2026

    @planetf1
    ContributorAuthor

    Verified fixed. The root cause — tool call argument handling when the model returned a response without tool calls — was addressed in #896. The marker fix (qualitative + slow) landed in #764. The per-turn prompt improvement in ReactThought.jinja2 was attempted but did not produce measurably better convergence, so was not pursued. Closing as resolved.

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

Metadata

Metadata

Assignees

Labels

area/adapter-functionsarea/backendsarea/stdlibtesting

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions