DEV Community

Uma Baleboyina
Uma Baleboyina

Posted on

Middleware in DeepAgents

Middleware is a component that sits between different parts of an agent system and can observe, manage, modify, or track the flow of information during execution.

In Deep Agents, middleware is part of the framework architecture. It operates between components such as the user request, the model, and tool execution. Middleware can perform different responsibilities depending on its purpose.

There are different types of middleware. For example:

  • TodoListMiddleware – Creates and manages a task list (todos) for complex requests and tracks task completion.
  • PatchToolCallsMiddleware – Helps manage and validate tool-calling behavior.
  • Logging Middleware – Records execution details and events.
  • Summarization Middleware – Can summarize conversation history or intermediate results.

It is important to note that not every middleware performs verification. Different middleware have different responsibilities. Some middleware may validate requests, some may track progress, some may summarize information, and some may simply log activity.

In Deep Agents, certain middleware are added automatically by the framework. For example, when I created an agent using create_deep_agent(), I observed middleware such as TodoListMiddleware and PatchToolCallsMiddleware appearing in the execution trace even though I did not explicitly add them.

The TodoListMiddleware creates and maintains todos internally. These todos are typically based on the user's goal and the tools available to the agent. The middleware tracks which tasks are pending and which have been completed during execution.

For example, if the user asks:

"Get me the weather of the most popular city in India."

The internal todo list might conceptually look like:

  • Find the most popular city.
  • Get the weather for that city.

As the agent completes each step, the middleware can update the status of the corresponding task.

The actual tool outputs are stored in the agent's state and used by the model for reasoning, while the TodoListMiddleware primarily focuses on planning and tracking task progress.

Some middleware are automatically included by the framework, while other middleware may need to be explicitly added by the developer depending on the application's requirements.

Top comments (0)