You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python: Add context_mode to control what gets sent to agents in workflows #3688
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:
classLastOutputOnlyExecutor(Executor):
@handlerasyncdeftransform(
self,
messages: list[ChatMessage],
ctx: WorkflowContext[list[ChatMessage]]
) ->None:
# Extract only the last assistant messagelast_assistant= [mforminmessagesifm.role=="assistant"][-1:]
awaitctx.send_message(last_assistant)
changed the title [-]Add context_mode to control what gets sent to agents in workflows[/-][+]Python: Add context_mode to control what gets sent to agents in workflows[/+]on Feb 5, 2026
Thanks for covering these ideas - really appreciate the thorough exploration of context_mode options. One thing I'd like to highlight again: once this feature is implemented, it will also need to be supported in declarative workflows (e.g., YAML-based definitions). The goal is to allow users to configure context passing behavior — such as full, last_output, or last_n — directly in the workflow definition, without requiring any code changes. This is especially important for scenarios where non-developer users or ops teams need to adjust workflow behavior through configuration alone.
Perhaps a mode on the receiving agent executor that says:
@dataclassclassContextMode:
# Default to the full contextincoming_messages_filter: Callable[[list[Mesage]], list[Message]] =lambdamessages: messages# Default to retaining cacheretain_cache: bool=True
Note that if not handled carefully, retaining cache and supplying full context from the previous agent may cause unexpected behavior.
Activity
[-]Add context_mode to control what gets sent to agents in workflows[/-][+]Python: Add context_mode to control what gets sent to agents in workflows[/+]moonbox3 commentedon Mar 5, 2026
See #4038 for further ideas, if not represented here.
droideronline commentedon Mar 6, 2026
Thanks for covering these ideas - really appreciate the thorough exploration of
context_modeoptions. One thing I'd like to highlight again: once this feature is implemented, it will also need to be supported in declarative workflows (e.g., YAML-based definitions). The goal is to allow users to configure context passing behavior — such asfull,last_output, orlast_n— directly in the workflow definition, without requiring any code changes. This is especially important for scenarios where non-developer users or ops teams need to adjust workflow behavior through configuration alone.TaoChenOSU commentedon Mar 6, 2026
When Agent A invokes Agent B, we also need to consider the messages that are already in Agent B's cache. Currently, we are replacing the cache of Agent B with Agent A's context, either the full conversation or the response: https://github.com/microsoft/agent-framework/blob/main/python/packages/core/agent_framework/_workflows/_agent_executor.py#L150
I think we should also have a mode to control if an agent should retain its own context when receiving a request from another agent.
TaoChenOSU commentedon Mar 6, 2026
Perhaps a mode on the receiving agent executor that says:
Note that if not handled carefully, retaining cache and supplying full context from the previous agent may cause unexpected behavior.