Add Ability to Multi-Select Threads (and Delete them) #127
Replies: 1 comment
-
Hi @jsedlak, thread sprawl is concern, especially when you're iterating fast or testing multiple agents. Currently, the Azure AI Agent Service only supports deleting threads one at a time via the REST API using the Thanks for raising this [feature request](https://github.com/orgs/azure-ai-foundry/discussions/127) Workaround Options You Might Consider Here’s a modular workaround you could script for now: Batch Delete via REST API
Example in Python: import requests
headers = {
"Authorization": "Bearer <your_token>",
"Content-Type": "application/json"
}
base_url = "https://<your-endpoint>/threads"
thread_ids = ["thread1", "thread2", "thread3"] # Replace with actual IDs
for thread_id in thread_ids:
response = requests.delete(f"{base_url}/{thread_id}?api-version=v1", headers=headers)
print(f"Deleted {thread_id}: {response.status_code}") You could even wrap this in a CLI tool or VS Code task to streamline cleanup across agents. Here's a modular Python script that batch-deletes threads from Azure AI Agent Service using the REST API. It supports filtering by agent ID and creation date, and includes a confirmation step before deletion. Bulk Thread Deletion Script for Azure AI Agent Service import requests
import datetime
# === CONFIGURATION ===
API_BASE = "https://<your-endpoint>" # e.g., https://your-resource-name.openai.azure.com
API_VERSION = "2024-05-01-preview"
AGENT_ID = "<your-agent-id>" # Optional: filter by agent
BEARER_TOKEN = "<your-access-token>" # Use a valid Azure AD token
# === FILTERING OPTIONS ===
FILTER_BY_DATE = True
DATE_THRESHOLD = datetime.datetime(2024, 8, 1) # Only delete threads created before this date
# === HEADERS ===
HEADERS = {
"Authorization": f"Bearer {BEARER_TOKEN}",
"Content-Type": "application/json"
}
def list_threads():
url = f"{API_BASE}/threads?api-version={API_VERSION}"
response = requests.get(url, headers=HEADERS)
response.raise_for_status()
return response.json().get("threads", [])
def filter_threads(threads):
filtered = []
for thread in threads:
if AGENT_ID and thread.get("agentId") != AGENT_ID:
continue
if FILTER_BY_DATE:
created = datetime.datetime.fromisoformat(thread["createdAt"].replace("Z", "+00:00"))
if created >= DATE_THRESHOLD:
continue
filtered.append(thread["id"])
return filtered
def delete_threads(thread_ids):
for thread_id in thread_ids:
url = f"{API_BASE}/threads/{thread_id}?api-version={API_VERSION}"
response = requests.delete(url, headers=HEADERS)
status = "✅" if response.status_code == 204 else f"❌ {response.status_code}"
print(f"Deleted {thread_id}: {status}")
if __name__ == "__main__":
print("🔍 Fetching threads...")
all_threads = list_threads()
to_delete = filter_threads(all_threads)
print(f"\n🧮 Threads eligible for deletion: {len(to_delete)}")
if not to_delete:
print("No threads matched the criteria.")
exit()
confirm = input("⚠️ Confirm deletion of these threads? (yes/no): ")
if confirm.lower() == "yes":
delete_threads(to_delete)
else:
print("Deletion aborted.") Notes
Hope this helps unblock you. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Technical Feedback
When developing an agent, you inevitably end up with several threads. Deleting these one-by-one is tedious. It would be nice to be able to select several or all and delete them (with confirmation).
Desired Outcome
Be able to multi-select or select all threads for a particular agent or all agents. Have the option to delete them in mass.
Current Workaround
Select each thread individually and delete it.
Beta Was this translation helpful? Give feedback.
All reactions