Skip to content

Add StructuredOutputRetryLimitMiddleware and default retry limit#756

Open
mateusz834 wants to merge 1 commit intodevelopfrom
dev/MP/structured-output-retry-limit
Open

Add StructuredOutputRetryLimitMiddleware and default retry limit#756
mateusz834 wants to merge 1 commit intodevelopfrom
dev/MP/structured-output-retry-limit

Conversation

@mateusz834
Copy link
Copy Markdown
Member

@mateusz834 mateusz834 commented Apr 30, 2026

Regenerated test_agent_understands_other_agents.json, since the previous recoding hit that default limit.

@mateusz834 mateusz834 force-pushed the dev/MP/structured-output-retry-limit branch 4 times, most recently from 4058eb3 to 11db930 Compare April 30, 2026 09:53
@mateusz834 mateusz834 marked this pull request as ready for review April 30, 2026 10:05
@mateusz834 mateusz834 changed the title Add StructuredOutputRetryLimitMiddleware and default retry limit Add StructuredOutputRetryLimitMiddleware and default retry limit Apr 30, 2026
@mateusz834 mateusz834 marked this pull request as draft May 4, 2026 08:12
@mateusz834 mateusz834 force-pushed the dev/MP/structured-output-retry-limit branch from 11db930 to 4f91f65 Compare May 4, 2026 08:20
@mateusz834 mateusz834 marked this pull request as ready for review May 4, 2026 08:20
@mateusz834 mateusz834 force-pushed the dev/MP/structured-output-retry-limit branch 3 times, most recently from 11b9c6d to a4b880c Compare May 4, 2026 10:14
@mateusz834 mateusz834 force-pushed the dev/MP/thread-id-middlewares branch from 29bea8d to 11d5bcb Compare May 4, 2026 10:14
@mateusz834 mateusz834 force-pushed the dev/MP/structured-output-retry-limit branch 2 times, most recently from 3bdfa63 to 41a8ba5 Compare May 5, 2026 07:04
Base automatically changed from dev/MP/thread-id-middlewares to develop May 5, 2026 08:38
@mateusz834 mateusz834 force-pushed the dev/MP/structured-output-retry-limit branch 3 times, most recently from dfecb28 to bd48ef4 Compare May 5, 2026 12:59
# NOTE: we're creating separate instances per agent - TimeoutLimitMiddleware is stateful
# and sharing one would cause agents to overwrite each other's deadline.
predefined: list[AgentMiddleware] = [
predefined_before: list[AgentMiddleware] = [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you dive it?

Copy link
Copy Markdown
Member Author

@mateusz834 mateusz834 May 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The StructuredOutputRetryLimitMiddleware must be first in the list (L97 below) since it has to execute after all other user_middleware have been executed, otherwise, if some user_middleware raised the StructuredOutputGenerationException we would not have catched that and the agent loop would have re-tried the structured output generation, without any re-try limits.

@pytest.mark.asyncio
@ai_snapshot_test()
async def test_default_retry_limit(self) -> None:
pytest.importorskip("langchain_openai")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] can't we add module level guard instead of repeating ? I mean this whole file depends on langchain_openai

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have this skip basically in every test now, if we are going to change anything related to this i think we should just remove them.

I’m not aware of any way to apply this globally, especially in a way that plays nicely with pytest, since these skips are actually executed per test and are visible in the pytest output.

Regenreated `test_agent_understands_other_agents.json`, since the previous
recoding hit that default limit.
@mateusz834 mateusz834 force-pushed the dev/MP/structured-output-retry-limit branch from bd48ef4 to 99ff354 Compare May 6, 2026 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants