Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Principle:Microsoft Autogen Message Filtering

From Leeroopedia
Knowledge Sources
Domains Multi-Agent Systems, Message Filtering, Context Management, Information Scoping
Last Updated 2026-02-11 00:00 GMT

Overview

Message filtering is the technique of selectively restricting which messages from a shared conversation history an agent receives, based on the source, position, and count of those messages.

Description

In multi-agent workflows, all participating agents typically share a common message thread. As the conversation grows, this full history can become noisy, irrelevant, or even counterproductive for individual agents. Message filtering addresses this by allowing each agent to receive only the messages that are relevant to its specific role.

The core motivations for message filtering include:

  • Context relevance: An agent performing translation only needs the latest output from its predecessor, not the entire review history.
  • Token efficiency: Reducing the message context sent to language model-backed agents lowers token consumption and improves response quality.
  • Loop management: In cyclic graph workflows where agents are revisited multiple times, an agent may need only the most recent feedback rather than the accumulated history of all iterations.
  • Role isolation: In complex graphs, an agent may need messages from specific sources (e.g., only from the "user" and one particular upstream agent) while ignoring messages from parallel branches.

Message filtering operates along three dimensions:

  1. Source: Which agent (or user) produced the message. Only messages from specified sources are included.
  2. Position: Whether to select from the beginning ("first") or end ("last") of the filtered sequence.
  3. Count: How many messages to include from the selected position.

When no position or count is specified for a source, all messages from that source are included. Multiple source filters can be combined, and the results are concatenated in the order the filters are defined.

Usage

Use message filtering when:

  • You are building graph-based workflows where agents are invoked multiple times in loops, and each invocation should see only the most recent context rather than the full accumulated history.
  • Downstream agents only need the output of their immediate predecessor, not the entire conversation.
  • You want to control token usage by limiting the context window sent to language model-backed agents.
  • Parallel branches exist in the graph, and agents should not see messages from unrelated branches.
  • An agent needs to see its own prior responses for self-reflection but should only see a bounded window of them.

Theoretical Basis

Message filtering draws from concepts in information scoping and context windowing in distributed systems.

Source-Based Partitioning

The message history is logically partitioned by the source field of each message. For a set of source filters S = {s_1, s_2, ..., s_n}, the filtered output is the ordered concatenation of messages matching each filter.

Sliding Window Selection

Within each source partition, messages can be selected using a positional window:

  • First N: Takes the first N messages from the partition (earliest messages).
  • Last N: Takes the last N messages from the partition (most recent messages).
  • All: When no position is specified, all messages from the source are included.

Pseudocode: Message Filter Application

function apply_filter(messages, filter_config):
    result = []
    for each source_filter in filter_config.per_source:
        partition = [m for m in messages if m.source == source_filter.source]

        if source_filter.position == "first" and source_filter.count:
            partition = partition[:source_filter.count]
        elif source_filter.position == "last" and source_filter.count:
            partition = partition[-source_filter.count:]

        result.extend(partition)
    return result

Design Considerations

  • Order preservation: Filters are applied per-source, and results are concatenated in the order the source filters are defined. This means the agent receives a coherent subset that respects temporal ordering within each source.
  • Wrapper pattern: Message filtering is best implemented as a transparent wrapper around an existing agent. The wrapper intercepts incoming messages, applies the filter, and delegates to the inner agent. The inner agent is unaware that filtering occurred.
  • Composability: Filters can be defined independently per agent in a graph, allowing fine-grained control without modifying the agents themselves or the graph topology.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment