Hi Allan,
so i was playing around with agents recently and found some slightly confusing behavior, maybe you can tell me what is happening.
I created a dotnetagent with assistant on my local machine. It shows up fine and works as expected.
Now i set up a Queue to trigger my agent with my package.
This works fine also, now to the confusion:
Expected behavior:
My agent triggers
Inside my agent i do a pop workitem and get the newly created workitem
I update it inside my agent and it shows up updated in OpenCore.
Actual Behavior:
My agent triggers
Inside my agent he says the queue is empty.
The Item for some reason is marked as successful, without me doing it.
If i generate multiple items fast my agent pops the second item fine and works as expected, i have no idea what happens with the first one so. Just a random guess might be, that the item gets into process state when the agent starts and cant be popped anymore?
This keeps happening to me too.
I would bet you, on some agent somewhere (agent code, Node-RED, or a robot), something is popping the items and updating them as successful.
Also, there is a slight problem in what I think you are doing:
Agent triggers (using a timer, or setting up schedules, or something else)
Agent calls pop work item, if something is there, it gets it
Process the item, then call update work item
Repeat from step 2 until no item is received
When configuring the queue to use a queue, or using the queue name as “queue”:
Agent calls register_queue and waits for a message
Agent calls pop work item when it receives a message
Process the item, then call update work item
Repeat from step 2 until no item is received
This part is confusing, I know
Every Workitem Queue is also a Message Queue, and by default, every queue will send a notification to anyone consuming that queue, so you only need to set the AMQP queue field if you want to use something else than the name of the work item queue.
Yea i am not using register queue i just have a straight forward code of:
Connect
Sign In
Pop
Update
and its triggered by a workitem that is added to a queue configured directly in open core by selecting the agent and package.
I assume that’s my problem? Is there a tutorial for how to properly write a dotnet package? All the tutorials don’t really go into the formalities of registering a queue etc.
I can’t find anything that would set this item to successful, and it stops doing anything when i remove the queue trigger.
I guess there are too many options… But I will try to explain why:
Pulling:
This is how most systems work; you can do that here too. At a certain interval, you call pop_workitem and check if there is something to do. This is fine to begin with, but it’s not scalable.
Pushing to an agent:
If you “just need something that works” without writing more complicated code, you can configure a queue to send a message to an agent and tell the agent to run a package when there are new items in the queue. The agent pops the item for you and gives you a unique filename with the payload inside, that you can then read/process/update. Based on the exit code, it will mark the work item as successful or retry. This is also not scalable since you can only use one agent in this setup, but it’s less complicated and takes care of all error handling for you.
Pushing, using a shared queue:
This is what all “getting started” projects in Opencore show you how to do. You create a queue for your package, you call register_queue in your code, and start processing work item when you get a message. You can then run one or more packages that all use the same queue, and you configure the work item queue to send notifications to this queue when there are new items to be processed. Here you need to call pop_workitem yourself, you also need to wrap your code in some kind of error handling to catch any potential errors and mark the work item as retry when that happens. You also need to ensure your code can handle running multiple jobs or reject packages if you are already doing something, but this also gives you complete control over the entire process and can scale to insane amounts of workloads.
Hi,
i think Nr. 2 is what i am doing correct?
You say there is a unique fileName maybe that’s what i am experiencing, that the item gets popped automatically so my manual pop cant get anything anymore? If so how would i access the item?
you will get the filename in an environment variable called payloadfile.
If you update the file, the payload in the workitem will also get update, once your code completes.