-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Description
Problem
In declarative workflows, when using multiple agents and iterating over a list of inputs (e.g., creating summaries for each item), there's currently no way to reset the agent's context/thread state between iterations.
Use Case Example:
actions:
- kind: Foreach
items: =workflow.input.documents
actions:
- kind: InvokeAzureAgent
agent: summarizer
input:
messages:
- =loop.item.content
output:
path: turn.summaries
append: trueIn this scenario, when the summarizer agent processes each document, the conversation history from previous iterations accumulates. This causes:
- Context pollution between unrelated documents
- Increased token usage as history grows
- Potential confusion for the agent model
Expected Behavior
The ability to reset an agent's thread/context state within declarative workflows:
-
Per-invocation option - A
resetThreadflag onInvokeAzureAgent:- kind: InvokeAzureAgent agent: summarizer resetThread: true
-
Explicit action - A new
ResetAgentContextaction kind:- kind: ResetAgentContext agent: summarizer
-
Via BaseAgent - Expose thread reset methods that declarative workflows can invoke (similar to how
MagenticAgentExecutorhandlesMagenticResetSignal)
Alternatives Considered
- Creating new agent instances per iteration (inefficient)
- Manual thread management in code (not available in declarative/YAML workflows)
Related Code
The framework already has reset patterns:
MagenticAgentExecutor.handle_magentic_reset()→self._agent_thread = self._agent.get_new_thread()AgentExecutor.reset()clears internal cacheBaseGroupChatOrchestrator._clear_conversation()AgentEntity.reset()in durable task entities
Code Sample
# Option 1: Per-invocation reset
- kind: Foreach
items: =workflow.input.documents
actions:
- kind: InvokeAzureAgent
agent: summarizer
resetThread: true
input:
messages:
- =loop.item.content
# Option 2: Explicit reset action
- kind: Foreach
items: =workflow.input.documents
actions:
- kind: ResetAgentContext
agent: summarizer
- kind: InvokeAzureAgent
agent: summarizer
input:
messages:
- =loop.item.contentLanguage/SDK
Python