Version: 0.0.8 (stable)
agrag.agents.model.build_model_middleware
build_model_middleware(clients:list[LLMClientConfig], *, strategy:Literal['single', 'fallback', 'round_robin'] = 'single', max_retries:int | None = None) -> list[Any]
Build agent middleware composing multiple clients per strategy.
The agent calls clients[0] as its primary model. With more than
one client, the returned middleware teaches the agent loop to use
the rest: "fallback" tries the other clients in order when the
primary model call fails, and "round_robin" rotates across
every client per model call.
Parameters:
- clients (
list[LLMClientConfig]) – The configured clients, in priority order. - strategy (
Literal['single', 'fallback', 'round_robin']) – How to composeclients."single"ignores all but the first client. - max_retries (
int | None) – Passed tobuild_chat_modelfor every client.
Returns:
list[Any]– Middleware for create_deep_agent/create_agent; empty when therelist[Any]– is nothing to compose.
Raises:
UnsupportedAgentProviderError– a client's provider has no agent-side mapping.