5c6a9826 by Ean Schuessler

Enhance agent reliability and debug logging

- AgentServices.xml: Added authenticate='false' to OpenAiChatCompletion, added logging to AgentQueue poller
- Agent.secas.xml: Added extensive logging to trigger SECA
- AgentData.xml: Fixed SmtyAgentTask to use run#AgentTaskTurn as consumeServiceName
1 parent 39daa815
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
25 <!-- Agent Task Message Type --> 25 <!-- Agent Task Message Type -->
26 <moqui.service.message.SystemMessageType systemMessageTypeId="SmtyAgentTask" description="Agent Task" 26 <moqui.service.message.SystemMessageType systemMessageTypeId="SmtyAgentTask" description="Agent Task"
27 contentType="application/json" 27 contentType="application/json"
28 consumeServiceName="AgentServices.poll#AgentQueue"/> 28 consumeServiceName="AgentServices.run#AgentTaskTurn"/>
29 29
30 <!-- Default AI Config (Brainfood VLLM) --> 30 <!-- Default AI Config (Brainfood VLLM) -->
31 <moqui.mcp.agent.ProductStoreAiConfig 31 <moqui.mcp.agent.ProductStoreAiConfig
......
1 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
2 <secas xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/service-eca-3.xsd"> 2 <secas xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/service-eca-3.xsd">
3 <seca id="AgentTriggerOnCommunication" service="create#mantle.party.communication.CommunicationEvent" when="post-service"> 3 <seca id="AgentTriggerOnCommunication" service="create#mantle.party.communication.CommunicationEvent" when="post-service">
4 <condition>
5 <expression>toPartyId == 'AGENT_CLAUDE_PARTY'</expression>
6 </condition>
7 <actions> 4 <actions>
8 <!-- Ensure rootCommEventId is set (thread tracking) -->
9 <script><![CDATA[ 5 <script><![CDATA[
6 ec.logger.info("SECA AgentTriggerOnCommunication fired for CommEvent ${communicationEventId} to Party ${toPartyId}")
7 if (toPartyId == 'AGENT_CLAUDE_PARTY') {
10 def rootId = rootCommEventId ?: communicationEventId 8 def rootId = rootCommEventId ?: communicationEventId
11 if (!rootCommEventId) { 9 if (!rootCommEventId) {
12 ec.service.sync().name("update#mantle.party.communication.CommunicationEvent") 10 ec.service.sync().name("update#mantle.party.communication.CommunicationEvent")
...@@ -14,17 +12,20 @@ ...@@ -14,17 +12,20 @@
14 .call() 12 .call()
15 } 13 }
16 14
15 ec.logger.info("SECA AgentTriggerOnCommunication: Creating SmtyAgentTask SystemMessage for thread ${rootId}")
16
17 // Trigger Agent Turn 17 // Trigger Agent Turn
18 ec.service.sync().name("create#moqui.service.message.SystemMessage").parameters([ 18 ec.service.sync().name("create#moqui.service.message.SystemMessage").parameters([
19 systemMessageTypeId: 'SmtyAgentTask', 19 systemMessageTypeId: 'SmtyAgentTask',
20 statusId: 'SmsgReceived', 20 statusId: 'SmsgReceived',
21 requestedByPartyId: fromPartyId, 21 requestedByPartyId: fromPartyId,
22 effectiveUserId: ec.user.userId, // Use the actual human user ID for RBAC 22 effectiveUserId: ec.user.userId,
23 productStoreId: 'POPC_DEFAULT', 23 productStoreId: 'POPC_DEFAULT',
24 aiConfigId: 'DEFAULT', 24 aiConfigId: 'DEFAULT',
25 rootCommEventId: rootId, 25 rootCommEventId: rootId,
26 isOutgoing: 'N' 26 isOutgoing: 'N'
27 ]).call() 27 ]).call()
28 }
28 ]]></script> 29 ]]></script>
29 </actions> 30 </actions>
30 </seca> 31 </seca>
......
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
55 <!-- Agent Client (OpenAI-Compatible API Wrapper) --> 55 <!-- Agent Client (OpenAI-Compatible API Wrapper) -->
56 <!-- ========================================================= --> 56 <!-- ========================================================= -->
57 57
58 <service verb="call" noun="OpenAiChatCompletion"> 58 <service verb="call" noun="OpenAiChatCompletion" authenticate="false">
59 <description>Generic wrapper for OpenAI-compatible chat completions (VLLM, OpenAI, etc.)</description> 59 <description>Generic wrapper for OpenAI-compatible chat completions (VLLM, OpenAI, etc.)</description>
60 <in-parameters> 60 <in-parameters>
61 <parameter name="endpointUrl" required="true"/> 61 <parameter name="endpointUrl" required="true"/>
...@@ -267,6 +267,8 @@ ...@@ -267,6 +267,8 @@
267 <description>Scheduled service to pick up pending tasks and process them.</description> 267 <description>Scheduled service to pick up pending tasks and process them.</description>
268 <actions> 268 <actions>
269 <script><![CDATA[ 269 <script><![CDATA[
270 ec.logger.info("POLL AGENT QUEUE: Checking for SmtyAgentTask messages in SmsReceived status...")
271
270 // Find pending tasks 272 // Find pending tasks
271 def pendingTasks = ec.entity.find("moqui.service.message.SystemMessage") 273 def pendingTasks = ec.entity.find("moqui.service.message.SystemMessage")
272 .condition("statusId", "SmsgReceived") 274 .condition("statusId", "SmsgReceived")
...@@ -275,7 +277,10 @@ ...@@ -275,7 +277,10 @@
275 .disableAuthz() 277 .disableAuthz()
276 .list() 278 .list()
277 279
280 ec.logger.info("POLL AGENT QUEUE: Found ${pendingTasks.size()} tasks to process.")
281
278 pendingTasks.each { task -> 282 pendingTasks.each { task ->
283 ec.logger.info("POLL AGENT QUEUE: Processing task ${task.systemMessageId}")
279 // Run Agent Task Turn 284 // Run Agent Task Turn
280 ec.service.sync().name("AgentServices.run#AgentTaskTurn") 285 ec.service.sync().name("AgentServices.run#AgentTaskTurn")
281 .parameters([systemMessageId: task.systemMessageId]) 286 .parameters([systemMessageId: task.systemMessageId])
......