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 @@
<!-- Agent Task Message Type -->
<moqui.service.message.SystemMessageType systemMessageTypeId="SmtyAgentTask" description="Agent Task"
contentType="application/json"
consumeServiceName="AgentServices.poll#AgentQueue"/>
consumeServiceName="AgentServices.run#AgentTaskTurn"/>
<!-- Default AI Config (Brainfood VLLM) -->
<moqui.mcp.agent.ProductStoreAiConfig
......
<?xml version="1.0" encoding="UTF-8"?>
<secas xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/service-eca-3.xsd">
<seca id="AgentTriggerOnCommunication" service="create#mantle.party.communication.CommunicationEvent" when="post-service">
<condition>
<expression>toPartyId == 'AGENT_CLAUDE_PARTY'</expression>
</condition>
<actions>
<!-- Ensure rootCommEventId is set (thread tracking) -->
<script><![CDATA[
ec.logger.info("SECA AgentTriggerOnCommunication fired for CommEvent ${communicationEventId} to Party ${toPartyId}")
if (toPartyId == 'AGENT_CLAUDE_PARTY') {
def rootId = rootCommEventId ?: communicationEventId
if (!rootCommEventId) {
ec.service.sync().name("update#mantle.party.communication.CommunicationEvent")
......@@ -14,17 +12,20 @@
.call()
}
ec.logger.info("SECA AgentTriggerOnCommunication: Creating SmtyAgentTask SystemMessage for thread ${rootId}")
// Trigger Agent Turn
ec.service.sync().name("create#moqui.service.message.SystemMessage").parameters([
systemMessageTypeId: 'SmtyAgentTask',
statusId: 'SmsgReceived',
requestedByPartyId: fromPartyId,
effectiveUserId: ec.user.userId, // Use the actual human user ID for RBAC
effectiveUserId: ec.user.userId,
productStoreId: 'POPC_DEFAULT',
aiConfigId: 'DEFAULT',
rootCommEventId: rootId,
isOutgoing: 'N'
]).call()
}
]]></script>
</actions>
</seca>
......
......@@ -55,7 +55,7 @@
<!-- Agent Client (OpenAI-Compatible API Wrapper) -->
<!-- ========================================================= -->
<service verb="call" noun="OpenAiChatCompletion">
<service verb="call" noun="OpenAiChatCompletion" authenticate="false">
<description>Generic wrapper for OpenAI-compatible chat completions (VLLM, OpenAI, etc.)</description>
<in-parameters>
<parameter name="endpointUrl" required="true"/>
......@@ -267,6 +267,8 @@
<description>Scheduled service to pick up pending tasks and process them.</description>
<actions>
<script><![CDATA[
ec.logger.info("POLL AGENT QUEUE: Checking for SmtyAgentTask messages in SmsReceived status...")
// Find pending tasks
def pendingTasks = ec.entity.find("moqui.service.message.SystemMessage")
.condition("statusId", "SmsgReceived")
......@@ -275,7 +277,10 @@
.disableAuthz()
.list()
ec.logger.info("POLL AGENT QUEUE: Found ${pendingTasks.size()} tasks to process.")
pendingTasks.each { task ->
ec.logger.info("POLL AGENT QUEUE: Processing task ${task.systemMessageId}")
// Run Agent Task Turn
ec.service.sync().name("AgentServices.run#AgentTaskTurn")
.parameters([systemMessageId: task.systemMessageId])
......