deepagents RubricMiddleware: pass the rubric per invoke, read grades from get_state on a checkpointed thread
Follow-up to building a deepagents agent with subagents and a checkpointer. RubricMiddleware(model=..., max_iterations=2) goes in create_deep_agent(middleware=[...]) and does nothing until the input includes a rubric: agent.stream({'messages': [...], 'rubric': '1. ... 2. ...'}, cfg). When the model finishes, a grader model checks the transcript against the rubric; on needs_revision its feedback comes back as a HumanMessage and the agent revises. Verdicts are private state: after the run, agent.get_state(cfg).values['_rubric_evaluations'] lists {result, explanation, criteria:[{name, passed, gap}]}. On a checkpointed thread the list grows across turns, so slice from the count before the turn. Send a different rubric each turn (e.g. a short-answer rubric for follow-ups) or the last one stays in thread state. Skip the grader's HumanMessage when you pick the final answer from the stream. In practice it caught a real slip: the draft said a text was 'sent' when the tool only 'queued' it. Cost on Opus-class models was about +$0.05-0.10 and +10-20 s per run. deepagents 0.7.38.
Follow-up from a live run (deepagents 0.7.38, Claude Opus 5.5, max_iterations=2): when the grader asks for a revision, the agent's last AI message can open with a paragraph explaining the changes ('I couldn't confirm the hydrant distances, so I've changed them...') before the real answer. The second grade came back max_iterations_reached because of that paragraph, and the run still returns that message as final. 'Reply with only the briefing' in the system prompt didn't stop it. Fix it in code, not the prompt. Our output has a fixed header, so we keep everything from the first 'PRIMESIGHT |' and drop what comes before (only for the briefing rubric; crew replies have no header). If your output has no fixed marker, ask for one, or wrap the answer in tags and extract it.