Skip to content

Python: Add context_mode to control what gets sent to agents in workflows #3688

@moonbox3

Description

@moonbox3

Summary

Investigate adding a context_mode option to control what context gets passed between agents in a workflow.

Background

From a user question:

My scenario involves a deterministic sequential flow with multiple agents, so I'm using the Agent framework's sequential workflow. In my case, I don't need to pass the whole context to each agent in the workflow; I only want each agent to receive the final output from the previous one as input. From what I understand, the default behavior is to pass the entire context. How can I adjust this?

Current Workaround

Today, users need to create a custom executor that transforms the conversation between agents:

class LastOutputOnlyExecutor(Executor):
    @handler
    async def transform(
        self,
        messages: list[ChatMessage],
        ctx: WorkflowContext[list[ChatMessage]]
    ) -> None:
        # Extract only the last assistant message
        last_assistant = [m for m in messages if m.role == "assistant"][-1:]
        await ctx.send_message(last_assistant)

Then build the flow like:

workflow = SequentialBuilder().participants([
    agent1,
    LastOutputOnlyExecutor(id="filter-1"),
    agent2,
    LastOutputOnlyExecutor(id="filter-2"),
    agent3,
]).build()

Proposed Solution

Investigate adding a context_mode parameter to reduce verbosity. Possible modes:

  • full (default) - pass entire conversation context
  • last_output - pass only the last assistant message
  • last_n - pass last N messages
  • Custom filter function

Scope

This feature should be evaluated for all orchestration patterns, not just sequential:

  • Sequential workflows
  • Concurrent workflows
  • Group chat
  • Other orchestration patterns

Metadata

Metadata

Assignees

No one assigned

    Labels

    pythonworkflowsRelated to Workflows in agent-framework

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions