Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: settings action #4085

Merged
merged 8 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions packages/core/src/actions/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,36 @@ async function extractSettingValues(
);

// Validate the extracted settings
if (!result || !Array.isArray(result)) {
if (!result) {
return [];
}

// Filter out any invalid settings
return result.filter(({ key, value }) => {
return Boolean(key && value && worldSettings[key]);
});
function extractValidSettings(obj: unknown, worldSettings: WorldSettings) {
const extracted = [];

function traverse(node: unknown): void {
if (Array.isArray(node)) {
for (const item of node) {
traverse(item);
}
} else if (typeof node === 'object' && node !== null) {
for (const [key, value] of Object.entries(node)) {
if (worldSettings[key] && typeof value !== 'object') {
extracted.push({ key, value });
} else {
traverse(value);
}
}
}
}

traverse(obj);
return extracted;
}

const extractedSettings = extractValidSettings(result, worldSettings);

return extractedSettings;
} catch (error) {
console.error('Error extracting settings:', error);
return [];
Expand Down Expand Up @@ -737,14 +759,6 @@ const updateSettingsAction: Action = {
return;
}

// Check if all required settings are already configured
const { requiredUnconfigured } = categorizeSettings(worldSettings);
if (requiredUnconfigured.length === 0) {
logger.info('All required settings configured, completing settings');
await handleOnboardingComplete(runtime, worldSettings, state, callback);
return;
}

// Extract setting values from message
logger.info(`Extracting settings from message: ${message.content.text}`);
const extractedSettings = await extractSettingValues(runtime, message, state, worldSettings);
Expand Down
50 changes: 35 additions & 15 deletions packages/core/src/providers/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,44 @@ function generateStatusMessage(

// Generate appropriate message
if (isOnboarding) {
const settingsList = formattedSettings
.map((s) => {
const label = s.required ? '(Required)' : '(Optional)';
return `${s.key}: ${s.value} ${label}\n(${s.name}) ${s.usageDescription}`;
})
.join('\n\n');

const validKeys = `Valid setting keys: ${Object.keys(worldSettings).join(', ')}`;

const commonInstructions = `Instructions for ${runtime.character.name}:
- Only update settings if the user is clearly responding to a setting you are currently asking about.
- If the user's reply clearly maps to a setting and a valid value, you **must** call the UPDATE_SETTINGS action with the correct key and value. Do not just respond with a message saying it's updated — it must be an action.
- Never hallucinate settings or respond with values not listed above.
- Answer setting-related questions using only the name, description, and value from the list.`;

if (requiredUnconfigured > 0) {
return `# PRIORITY TASK: Onboarding with ${state.senderName}\n${
runtime.character.name
} still needs to configure ${requiredUnconfigured} required settings:\n\n${formattedSettings
.filter((s) => s.required && !s.configured)
.map((s) => `${s.key}: ${s.value}\n(${s.name}) ${s.usageDescription}`)
.join('\n\n')}\n\nValid settings keys: ${Object.keys(worldSettings).join(
', '
)}\n\nIf the user gives any information related to the settings, ${
runtime.character.name
} should use the UPDATE_SETTINGS action to update the settings with this new information. ${
runtime.character.name
} can update any, some or all settings.`;
return `# PRIORITY TASK: Onboarding with ${state.senderName}

${runtime.character.name} needs to help the user configure ${requiredUnconfigured} required settings:

${settingsList}

${validKeys}

${commonInstructions}

- Prioritize configuring required settings before optional ones.`;
}
return `All required settings have been configured! Here's the current configuration:\n\n${formattedSettings
.map((s) => `${s.name}: ${s.description}\nValue: ${s.value}`)
.join('\n')}`;

return `All required settings have been configured. Here's the current configuration:

${settingsList}

${validKeys}

${commonInstructions}`;
}

// Non-onboarding context - list all public settings with values and descriptions
return `## Current Configuration\n\n${
requiredUnconfigured > 0
Expand Down
Loading