Agents not cleaned up Ai foundry – Duplicate agent instances created on each run in Multi-Agent Accelerator #18
-
Technical Feedback There appears to be no built-in mechanism to clean up agents after they are no longer in use. Even though the code uses an in-memory cache during execution, it does not prevent new agents from being created on every run, and it does not remove the old ones from the Foundry portal. Desired Outcome Automatically delete all agents when the application shuts down or finishes its run, Preserve only one instance of each agent type per user (reusing them across sessions if applicable). This would ensure that the Agents tab (accessible from the Foundry project > Foundry Portal > Agents in the left-hand sidebar) remains clean and manageable. The critical goal is to prevent agents from being recreated repeatedly without cleanup, which currently leads to potential quota issues and operational confusion. Current WorkaroundDescribe the current workaround. Please help with this issue!!! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @UtkarshMishra-Microsoft, this behavior is by design, as the agents are designed to be persistent. If you want to clean-up after the agent is used, then you can simply use the delete_agent() method, as described in the documentation
An alternative approach is to check for the existence of the agent each time, and only create a new one if it doesn't already exist. There's a good example of how to do this in @nicholasdbrady's demo here. I've found this method works well for interactive chat apps, where the user may terminate the app unexpectedly.
|
Beta Was this translation helpful? Give feedback.
-
I'd like to confirm how thread handling is implemented, especially in cases where threads are no longer needed—such as when we're deleting agents from Foundry. It seems that thread creation is an automatic feature of Semantic Kernel when an agent is created. However, we're unsure how to delete the associated threads, and we haven't been able to figure it out so far. Do you have any insights on this? |
Beta Was this translation helpful? Give feedback.
Hi @UtkarshMishra-Microsoft, this behavior is by design, as the agents are designed to be persistent.
If you want to clean-up after the agent is used, then you can simply use the delete_agent() method, as described in the documentation
An alternative approach is to check for the existence of the agent each time, and only create a new one if it doesn't already exist. There's a good example of how to do this in @nicholasdbrady's demo here. I've found this method works well for interactive chat apps, where the user may terminate the app unexpectedly.