microsoft / microsoft/agent-framework

Python: [Feature]: Cancellation request for agent generation loop

Open
#5,814 0 comments 0 reactions 1 assignee Claimed by @eavanvalkenburg View on GitHub
agents python
Dominant language
Python
Stars
13.6k
Forks
2.3k
Avg merge
2d 45m
Merged PRs (30d)
358

Description

### Description

# Scope
We are looking for a simple way to stop the generation loop mid-execution. A lot of agentic applications support this behavior (e.g., Microsoft Copilot), but there is no simple way of actually doing this with Microsoft Agent Framework.

# Why is this useful
- Stopping long lasting/expensive/... generations (User might have sent the wrong query)

# Our current custom implementation
Currently we iterate over a ResponseStream and check whether a variable `is_canceled` was set. If that is the case, we break from the ResponseStream loop.

**Why this is not as easy as it sounds**
When working with (custom) HistoryProvider instances, we are required to implement a before_run method that "repairs" the conversation history/context in some cases -> E.g. when the last element is a function_call element, we need to delete it, as continuing without any result is not possible right now

### Code Sample

```markdown

```

### Language/SDK

Python

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.