microsoft / microsoft/agent-framework

Python: Access Workflow Context Inside Condition Callable in `SingleEdgeGroup`

Open
#2,134 5 comments 0 reactions 1 assignee Assigned to @TaoChenOSU View on GitHub
python question workflows
Dominant language
Python
Stars
13.6k
Forks
2.3k
Avg merge
2d 45m
Merged PRs (30d)
358

Description

Currently, the condition callable that we pass while adding an edge in a `SingleEdgeGroup` does not have access to the workflow context. This limits our ability to make condition decisions based on contextual or shared workflow state.

I’m proposing adding support for accessing the workflow context inside the condition callable.

---

#### Use Case

In my scenario, I want to track how many times an edge group has been activated (i.e., how many times the condition has been evaluated).
If the number of activations exceeds a certain threshold, I want to force the workflow to choose a different edge group.

Right now, the only way to track this is by maintaining an iteration count — possibly using a `contextvar` for thread safety.
However, if the condition callable could access the **workflow context**, we could:

* Maintain iteration counts directly in the **workflow’s shared state**
* Make the count **persist across checkpoints**
* Avoid the need for separate `contextvar`-based state management
* Keep the logic self-contained within the workflow’s context

This would make the workflow more robust and stateful across replays or recoveries.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.