fix: improve agent output schema, tool descriptions, and shutdown robustness

- Rename status→outputType, responded/silent→message/log for clarity
- Remove scheduled task special-casing: userMessage now sent for all contexts
- Update schema, tool, and CLAUDE.md descriptions to be clear and
  non-contradictory about communication mechanisms
- Use full tool name mcp__nanoclaw__send_message in docs
- Change schedule_task target_group to accept JID instead of folder name
- Only show target_group_jid parameter to main group agents
- Add defense-in-depth sanitization and error callback to exec() in shutdown
- Use "user or group" consistently (supports both 1:1 and group chats)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
gavrielc
2026-02-06 20:22:45 +02:00
parent ae177156ec
commit 44f0b3d99c
8 changed files with 68 additions and 63 deletions

View File

@@ -18,7 +18,7 @@ interface ContainerInput {
}
interface AgentResponse {
status: 'responded' | 'silent';
outputType: 'message' | 'log';
userMessage?: string;
internalLog?: string;
}
@@ -26,21 +26,21 @@ interface AgentResponse {
const AGENT_RESPONSE_SCHEMA = {
type: 'object',
properties: {
status: {
outputType: {
type: 'string',
enum: ['responded', 'silent'],
description: 'Use "responded" when you have a message for the user. Use "silent" when the messages don\'t require a response (e.g. the conversation is between other people and doesn\'t involve you, or no trigger/mention was directed at you).',
enum: ['message', 'log'],
description: '"message": the userMessage field contains a message to send to the user or group. "log": the output will not be sent to the user or group.',
},
userMessage: {
type: 'string',
description: 'The message to send to the user. Required when status is "responded".',
description: 'A message to send to the user or group. Include when outputType is "message".',
},
internalLog: {
type: 'string',
description: 'Optional internal note about why you chose this status (for logging, not shown to users).',
description: 'Information that will be logged internally but not sent to the user or group.',
},
},
required: ['status'],
required: ['outputType'],
} as const;
interface ContainerOutput {
@@ -254,7 +254,7 @@ async function main(): Promise<void> {
// Add context for scheduled tasks
let prompt = input.prompt;
if (input.isScheduledTask) {
prompt = `[SCHEDULED TASK - You are running automatically, not in response to a user message. Use mcp__nanoclaw__send_message if needed to communicate with the user.]\n\n${input.prompt}`;
prompt = `[SCHEDULED TASK - The following message was sent automatically and is not coming directly from the user or group.]\n\n${input.prompt}`;
}
try {
@@ -294,13 +294,13 @@ async function main(): Promise<void> {
if (message.type === 'result') {
if (message.subtype === 'success' && message.structured_output) {
result = message.structured_output as AgentResponse;
log(`Agent result: status=${result.status}${result.internalLog ? `, log=${result.internalLog}` : ''}`);
log(`Agent result: outputType=${result.outputType}${result.internalLog ? `, log=${result.internalLog}` : ''}`);
} else if (message.subtype === 'error_max_structured_output_retries') {
// Agent couldn't produce valid structured output — fall back to text result
log('Agent failed to produce structured output, falling back to text');
const textResult = 'result' in message ? (message as { result?: string }).result : null;
if (textResult) {
result = { status: 'responded', userMessage: textResult };
result = { outputType: 'message', userMessage: textResult };
}
}
}
@@ -309,7 +309,7 @@ async function main(): Promise<void> {
log('Agent completed successfully');
writeOutput({
status: 'success',
result: result ?? { status: 'silent' },
result: result ?? { outputType: 'log' },
newSessionId
});