langgraph_agent_toolkit.agents.components.middlewares.sanitize_history module

Middleware that removes incomplete tool calls before model calls.

class langgraph_agent_toolkit.agents.components.middlewares.sanitize_history.SanitizeHistoryMiddleware[source][source]

Bases: AgentMiddleware

Repair tool-call and tool-result pairs before each model call.

Remove tool calls without results. Remove tool results without matching calls. The middleware changes only the messages sent to the model.

wrap_model_call(request, handler)[source][source]
Parameters:
  • request (ModelRequest)

  • handler (Callable[[ModelRequest], ModelResponse])

Return type:

ModelResponse

async awrap_model_call(request, handler)[source][source]
Parameters:
  • request (ModelRequest)

  • handler (Callable[[ModelRequest], Awaitable[ModelResponse]])

Return type:

ModelResponse