RubricMiddleware(
self,
*,
model: str | BaseChatModel,
system_prompt: str | | Name | Type | Description |
|---|---|---|
model* | str | BaseChatModel | Model used by the grader sub-agent. Accepts either a model
string like |
system_prompt | str | None | Default: NoneCustom grading instructions; falls back to the built-in grader prompt when not set. |
tools | Sequence[BaseTool] | None | Default: None |
max_iterations | int | Default: 3 |
on_evaluation | Callable[[RubricEvaluation], None] | None | Default: None |
| Name | Type |
|---|---|
| model | str | BaseChatModel |
| system_prompt | str | None |
| tools | Sequence[BaseTool] | None |
| max_iterations | int |
| on_evaluation | Callable[[RubricEvaluation], None] | None |
Middleware that drives self-evaluated iteration against a rubric.
The middleware activates only when a caller passes a rubric on
invocation state. With no rubric, both before_agent and after_agent
return without modifying state, so the middleware is safe to include
unconditionally in a create_deep_agent stack.
When grading ends with failed, max_iterations_reached, or
grader_error, the middleware does not mutate the response
messages. The last AIMessage in the agent's output is whatever
the model produced just before the grader gave up. Callers who
need to branch on non-satisfied termination must inspect one of:
_rubric_status on the returned state (or agent.get_state(...)
on a checkpointed thread),on_evaluation callback,rubric_evaluation_end stream event.A logger.warning is also emitted when max_iterations_reached
fires.
Tools the grader may call before producing its
GraderResponse. With none, the grader reasons from the
transcript alone.
Hard cap on grader iterations per rubric attempt;
hard-capped at 20. When the cap is reached without a
satisfied verdict, the agent terminates with status
'max_iterations_reached' (see the note above on how to
observe this).
Optional callback one can invoke with each RubricEvaluation after
grading. Exceptions raised by the callback are logged at
error level and suppressed; do not use this callback to
enforce control flow.