QueueForAgent method, is used to queue the workitems, such that specified agent, picks it up and works on it,i.e It stores the request for processing a persistent object(entry) in the system queue.
As far as my understanding
1)There may be some logical error , in the agent activity, which is making the queue entry to move to broken process when AQM is checked.
If AQM is unchecked, the agent , picks up the queue item,runs the specified activity. In case it faces the error, it just discards the entry, where as if AQM is checked, if agent runs into any error during execution of agent activity, it moves it into broken-queue, which can be requeued later, by correcting the logic defined in the activity
2)Advanced Agent, just wakes up ,in the specified intervals, and runs the activity configured. There is no concept of pushing an item into queue, and picking up it from the queue, to run the activity.
First of all, we should be hard coding pyWorkPage in an agent activity as it may not get the right context while processing. Instead of doing so, we can copy the page to some temp page and call the Queue-For-Agent method on that page. In my scenario, I had a standard agent for which I followed the same approach and it is working fine.
One more point I would like to add here is that make sure that the item which has been scheduled for action by agent is not accessed by any other requestor/process.
You can also debug the reason for the item being sent to broken queue by opening the instance of System-Queue-X of the respective item and checking for errors field in that.