Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
feat(agents): add per-agent AI provider/model configuration
Adam Eivyda4d40fbf1c7
diff --git a/.changelog/v0.12.x.md b/.changelog/v0.12.x.mdindex 378d1006e0..62dbe680a4 100644--- a/.changelog/v0.12.x.md+++ b/.changelog/v0.12.x.md@@ -257,3 +257,23 @@ This release adds branch management and automated release workflow capabilities- `client/src/components/cos/index.js` — Exported ActionableInsightsBanner component- `client/src/services/api.js` — Added `getCosActionableInsights()` API function- `client/src/pages/ChiefOfStaff.jsx` — Renders ActionableInsightsBanner above QuickSummary on the Tasks tab++### Agents — Per-Agent AI Provider/Model Configuration+- **Agent-level AI config**: Each agent can now have its own default AI provider and model for content generation, instead of always using the globally active provider+- **Overview tab selector**: New "Default AI Provider" section on the agent Overview tab with provider and model dropdowns, plus a dedicated Save button+- **System Default fallback**: When no provider is configured (or cleared), the agent falls back to the globally active provider+- **Automated flows**: Scheduled actions (post, comment, engage, monitor) all use the agent's configured provider when available+- **Manual generation**: "Generate Post" and "Generate Comment" in the Tools tab use the agent's AI config+- **Challenge solver**: Moltbook verification challenges can use the agent's preferred provider for solving++**Server changes**:+- `server/lib/validation.js` — Added `agentAiConfigSchema` and `aiConfig` field to `agentSchema`+- `server/services/agentPersonalities.js` — `createAgent()` preserves `aiConfig` field+- `server/services/agentActionExecutor.js` — `executePost`, `executeComment`, `executeEngage`, `executeMonitor` pass `agent.aiConfig` to content generators+- `server/routes/agentTools.js` — `check-posts` and `engage` endpoints pass `agent.aiConfig` to `generateReply`/`generateComment`+- `server/integrations/moltbook/challengeSolver.js` — `solveChallenge()` and `solveWithAI()` accept optional AI config for agent-specific provider++**Client changes**:+- `client/src/components/agents/tabs/OverviewTab.jsx` — Added "Default AI Provider" card with provider/model selectors and save button+- `client/src/components/agents/tabs/ToolsTab.jsx` — Generate Post and Generate Comment pass agent's `aiConfig` to API calls+- `client/src/components/agents/AgentDetail.jsx` — Passes `agent` prop to ToolsTabdiff --git a/client/src/components/agents/AgentDetail.jsx b/client/src/components/agents/AgentDetail.jsxindex 20c60650f0..1abdc38301 100644--- a/client/src/components/agents/AgentDetail.jsx+++ b/client/src/components/agents/AgentDetail.jsx@@ -65,7 +65,7 @@ export default function AgentDetail() {case 'overview':return <OverviewTab agentId={agentId} agent={agent} onAgentUpdate={fetchAgent} />;case 'tools':- return <ToolsTab agentId={agentId} />;+ return <ToolsTab agentId={agentId} agent={agent} />;case 'published':return <PublishedTab agentId={agentId} />;case 'schedules':diff --git a/client/src/components/agents/tabs/OverviewTab.jsx b/client/src/components/agents/tabs/OverviewTab.jsxindex b57b3dd447..06bfa0b862 100644--- a/client/src/components/agents/tabs/OverviewTab.jsx+++ b/client/src/components/agents/tabs/OverviewTab.jsx@@ -1,5 +1,5 @@import { useState, useEffect, useCallback } from 'react';-import { Sparkles } from 'lucide-react';+import { Sparkles, Cpu } from 'lucide-react';import toast from 'react-hot-toast';import * as api from '../../../services/api';import { PERSONALITY_STYLES, DEFAULT_PERSONALITY, DEFAULT_AVATAR, PLATFORM_TYPES, ACCOUNT_STATUSES } from '../constants';@@ -40,7 +40,8 @@ export default function OverviewTab({ agentId, agent, onAgentUpdate }) {userId: agent.userId,personality: { ...DEFAULT_PERSONALITY, ...agent.personality },avatar: { ...DEFAULT_AVATAR, ...agent.avatar },- enabled: agent.enabled+ enabled: agent.enabled,+ aiConfig: agent.aiConfig || {}});}, [agent]);@@ -75,6 +76,8 @@ export default function OverviewTab({ agentId, agent, onAgentUpdate }) {const selectedProvider = providers.find(p => p.id === selectedProviderId);const availableModels = selectedProvider?.models || [];+ const aiConfigProvider = providers.find(p => p.id === formData?.aiConfig?.providerId);+ const aiConfigModels = aiConfigProvider?.models || [];const handleGenerate = async () => {setGenerating(true);@@ -118,13 +121,15 @@ export default function OverviewTab({ agentId, agent, onAgentUpdate }) {const handleSave = async (e) => {e.preventDefault();+ const aiConfig = formData.aiConfig?.providerId ? formData.aiConfig : undefined;const submitData = {...formData,personality: {...formData.personality,topics: topicsText.split(',').map(t => t.trim()).filter(Boolean),quirks: quirksText.split(',').map(t => t.trim()).filter(Boolean)- }+ },+ aiConfig};await api.updateAgentPersonality(agentId, submitData);toast.success('Agent updated');@@ -367,6 +372,70 @@ export default function OverviewTab({ agentId, agent, onAgentUpdate }) {</form></div>+ {/* Default AI Provider Section */}+ <div className="bg-port-card border border-port-border rounded-lg p-4">+ <div className="flex items-center gap-2 mb-3">+ <Cpu size={16} className="text-port-accent" />+ <h3 className="text-md font-semibold text-white">Default AI Provider</h3>+ </div>+ <p className="text-xs text-gray-500 mb-3">+ Choose which AI provider and model this agent uses for content generation (posts, comments, replies). Leave as "System Default" to use the globally active provider.+ </p>+ <div className="flex items-end gap-3">+ <div className="flex-1">+ <label className="block text-xs text-gray-400 mb-1">Provider</label>+ <select+ value={formData.aiConfig?.providerId || ''}+ onChange={(e) => setFormData(prev => ({+ ...prev,+ aiConfig: { ...prev.aiConfig, providerId: e.target.value || undefined, model: undefined }+ }))}+ className="w-full px-2 py-1.5 bg-port-bg border border-port-border rounded text-white text-sm"+ >+ <option value="">System Default</option>+ {providers.map(p => (+ <option key={p.id} value={p.id}>{p.name}</option>+ ))}+ </select>+ </div>+ <div className="flex-1">+ <label className="block text-xs text-gray-400 mb-1">Model</label>+ <select+ value={formData.aiConfig?.model || ''}+ onChange={(e) => setFormData(prev => ({+ ...prev,+ aiConfig: { ...prev.aiConfig, model: e.target.value || undefined }+ }))}+ disabled={!formData.aiConfig?.providerId}+ className="w-full px-2 py-1.5 bg-port-bg border border-port-border rounded text-white text-sm disabled:opacity-50"+ >+ <option value="">Default</option>+ {aiConfigModels.map(m => (+ <option key={m} value={m}>{m}</option>+ ))}+ </select>+ </div>+ <button+ type="button"+ onClick={async () => {+ const aiConfig = formData.aiConfig?.providerId ? formData.aiConfig : undefined;+ await api.updateAgentPersonality(agentId, { aiConfig });+ toast.success(aiConfig ? 'AI provider saved' : 'Reset to system default');+ onAgentUpdate?.();+ }}+ className="px-4 py-1.5 bg-port-success text-white rounded hover:bg-port-success/80 text-sm whitespace-nowrap"+ >+ Save+ </button>+ </div>+ {formData.aiConfig?.providerId && (+ <p className="text-xs text-port-accent mt-2">+ Using: {aiConfigProvider?.name || formData.aiConfig.providerId}+ {formData.aiConfig.model && ` / ${formData.aiConfig.model}`}+ </p>+ )}+ </div>+{/* Accounts Section */}<div className="bg-port-card border border-port-border rounded-lg p-4"><div className="flex justify-between items-center mb-4">diff --git a/client/src/components/agents/tabs/ToolsTab.jsx b/client/src/components/agents/tabs/ToolsTab.jsxindex bc82c98332..eb38d27be6 100644--- a/client/src/components/agents/tabs/ToolsTab.jsx+++ b/client/src/components/agents/tabs/ToolsTab.jsx@@ -2,7 +2,7 @@ import { useState, useEffect, useCallback } from 'react';import toast from 'react-hot-toast';import * as api from '../../../services/api';-export default function ToolsTab({ agentId }) {+export default function ToolsTab({ agentId, agent }) {const [accounts, setAccounts] = useState([]);const [selectedAccountId, setSelectedAccountId] = useState('');const [rateLimits, setRateLimits] = useState(null);@@ -111,7 +111,7 @@ export default function ToolsTab({ agentId }) {const handleGeneratePost = async () => {if (!agentId || !selectedAccountId) return;setGenerating(true);- const generated = await api.generateAgentPost(agentId, selectedAccountId, selectedSubmolt);+ const generated = await api.generateAgentPost(agentId, selectedAccountId, selectedSubmolt, agent?.aiConfig?.providerId, agent?.aiConfig?.model);setPostTitle(generated.title);setPostContent(generated.content);setGenerating(false);@@ -152,7 +152,8 @@ export default function ToolsTab({ agentId }) {if (!selectedPost) return;setGeneratingComment(true);const generated = await api.generateAgentComment(- agentId, selectedAccountId, selectedPost.id, replyToId || undefined+ agentId, selectedAccountId, selectedPost.id, replyToId || undefined,+ agent?.aiConfig?.providerId, agent?.aiConfig?.model);setCommentContent(generated.content);setGeneratingComment(false);diff --git a/server/integrations/moltbook/api.js b/server/integrations/moltbook/api.jsindex ddeb84a3f2..e9b10ab66c 100644--- a/server/integrations/moltbook/api.js+++ b/server/integrations/moltbook/api.js@@ -16,14 +16,14 @@ const API_BASE = 'https://www.moltbook.com/api/v1';* Handle a Moltbook verification challenge embedded in a response* Challenges are obfuscated math word problems that must be solved within 5 minutes.*/-async function handleVerification(data, apiKey) {+async function handleVerification(data, apiKey, aiConfig) {if (!data?.verification_required || !data?.verification) return data;const { code, challenge, expires_at } = data.verification;console.log(`🔐 Moltbook verification required: code=${code}, expires=${expires_at}`);console.log(`🔐 Challenge: "${challenge.substring(0, 100)}..."`);- const answer = await solveChallenge(challenge);+ const answer = await solveChallenge(challenge, aiConfig);if (!answer) {console.error(`❌ Could not solve Moltbook challenge — post will remain pending`);return data;diff --git a/server/integrations/moltbook/challengeSolver.js b/server/integrations/moltbook/challengeSolver.jsindex 688e634c84..c3aaf1d8c4 100644--- a/server/integrations/moltbook/challengeSolver.js+++ b/server/integrations/moltbook/challengeSolver.js@@ -13,7 +13,7 @@*/import { executeApiRun, createRun } from '../../services/runner.js';-import { getActiveProvider } from '../../services/providers.js';+import { getActiveProvider, getProviderById } from '../../services/providers.js';/*** Strip obfuscation noise from Moltbook challenge text@@ -130,14 +130,20 @@ export function solveWithRegex(challengeText) {/*** Solve using AI interpretation*/-async function solveWithAI(challengeText) {- const provider = await getActiveProvider();+async function solveWithAI(challengeText, aiConfig) {+ let provider;+ if (aiConfig?.providerId) {+ provider = await getProviderById(aiConfig.providerId).catch(() => null);+ }+ if (!provider) {+ provider = await getActiveProvider();+ }if (!provider) {console.log(`🔐 No AI provider available for challenge solving`);return null;}- const model = provider.lightModel || provider.defaultModel || provider.models?.[0];+ const model = aiConfig?.model || provider.lightModel || provider.defaultModel || provider.models?.[0];const prompt = `You are solving a verification challenge. The text below is obfuscated with random brackets, symbols, and doubled letters. Decode it, solve the math problem, and respond with ONLY the numeric answer with 2 decimal places (e.g., "47.00"). No explanation.Challenge text:@@ -182,13 +188,15 @@ Answer:`;/*** Solve a Moltbook verification challenge* Prefers AI (handles obfuscation reliably), falls back to regex if no AI provider+ * @param {string} challengeText - The obfuscated challenge text+ * @param {{ providerId?: string, model?: string }} [aiConfig] - Optional AI provider config* @returns {string|null} Answer formatted with 2 decimal places, or null if unsolvable*/-export async function solveChallenge(challengeText) {+export async function solveChallenge(challengeText, aiConfig) {console.log(`🔐 Solving challenge: "${challengeText.substring(0, 80)}..."`);// Try AI first — handles obfuscation much better than regex- const aiAnswer = await solveWithAI(challengeText).catch(err => {+ const aiAnswer = await solveWithAI(challengeText, aiConfig).catch(err => {console.log(`🔐 AI solver error: ${err.message}`);return null;});diff --git a/server/lib/validation.js b/server/lib/validation.jsindex 8f1e734912..1fe6134324 100644--- a/server/lib/validation.js+++ b/server/lib/validation.js@@ -29,6 +29,12 @@ export const agentAvatarSchema = z.object({color: z.string().regex(/^#[0-9A-Fa-f]{6}$/).optional()}).optional();+// Agent AI config (preferred provider/model for content generation)+export const agentAiConfigSchema = z.object({+ providerId: z.string().min(1).optional(),+ model: z.string().min(1).optional()+}).optional();+// Full agent schemaexport const agentSchema = z.object({userId: z.string().min(1).max(100),@@ -36,7 +42,8 @@ export const agentSchema = z.object({description: z.string().max(1000).optional().default(''),personality: agentPersonalitySchema,avatar: agentAvatarSchema,- enabled: z.boolean().default(true)+ enabled: z.boolean().default(true),+ aiConfig: agentAiConfigSchema});export const agentUpdateSchema = agentSchema.partial();diff --git a/server/routes/agentTools.js b/server/routes/agentTools.jsindex 56b2b69a8a..3b786f598c 100644--- a/server/routes/agentTools.js+++ b/server/routes/agentTools.js@@ -204,7 +204,7 @@ router.post('/engage', asyncHandler(async (req, res) => {const rateCheck = checkRateLimit(client.apiKey, 'comment');if (!rateCheck.allowed) break;- const generated = await generateComment(agent, opportunity.post, opportunity.comments);+ const generated = await generateComment(agent, opportunity.post, opportunity.comments, null, agent.aiConfig?.providerId, agent.aiConfig?.model);const result = await client.createComment(opportunity.post.id, generated.content);comments.push({@@ -478,7 +478,7 @@ router.post('/check-posts', asyncHandler(async (req, res) => {if (!suspended && replied.length < data.maxReplies) {const rateCheck = checkRateLimit(client.apiKey, 'comment');if (rateCheck.allowed) {- const generated = await generateReply(agent, post, comment);+ const generated = await generateReply(agent, post, comment, null, agent.aiConfig?.providerId, agent.aiConfig?.model);const replyResult = await client.replyToComment(postId, comment.id, generated.content).catch(e => {if (isAccountSuspended(e)) suspended = true;else console.log(`👀 Reply failed on post ${postId}: ${e.message}`);diff --git a/server/services/agentActionExecutor.js b/server/services/agentActionExecutor.jsindex 008927efd6..06a8d32371 100644--- a/server/services/agentActionExecutor.js+++ b/server/services/agentActionExecutor.js@@ -74,7 +74,7 @@ async function executePost(client, agent, params) {// AI generate if content not providedif ((!title || !content) && aiGenerate !== false) {console.log(`🤖 AI generating post content for "${agent.name}"`);- const generated = await generatePost(agent, { submolt });+ const generated = await generatePost(agent, { submolt }, agent.aiConfig?.providerId, agent.aiConfig?.model);title = generated.title;content = generated.content;}@@ -116,7 +116,7 @@ async function executeComment(client, agent, params) {// AI generate comment if no contentif (!content) {console.log(`🤖 AI generating comment for "${agent.name}" on post ${postId}`);- const generated = await generateComment(agent, pick.post, pick.comments);+ const generated = await generateComment(agent, pick.post, pick.comments, null, agent.aiConfig?.providerId, agent.aiConfig?.model);content = generated.content;}} else if (!content) {@@ -129,14 +129,14 @@ async function executeComment(client, agent, params) {if (parentId) {const parent = comments.find(c => c.id === parentId);if (parent) {- const generated = await generateReply(agent, post, parent);+ const generated = await generateReply(agent, post, parent, null, agent.aiConfig?.providerId, agent.aiConfig?.model);content = generated.content;} else {- const generated = await generateComment(agent, post, comments);+ const generated = await generateComment(agent, post, comments, null, agent.aiConfig?.providerId, agent.aiConfig?.model);content = generated.content;}} else {- const generated = await generateComment(agent, post, comments);+ const generated = await generateComment(agent, post, comments, null, agent.aiConfig?.providerId, agent.aiConfig?.model);content = generated.content;}}@@ -250,7 +250,7 @@ async function executeEngage(client, agent, params) {const rateCheck = checkRateLimit(client.apiKey, 'comment');if (!rateCheck.allowed) break;- const generated = await generateComment(agent, opportunity.post, opportunity.comments);+ const generated = await generateComment(agent, opportunity.post, opportunity.comments, null, agent.aiConfig?.providerId, agent.aiConfig?.model);await client.createComment(opportunity.post.id, generated.content).catch(e => {if (isAccountSuspended(e)) suspended = true;});@@ -342,7 +342,7 @@ async function executeMonitor(client, agent, schedule, params) {if (!suspended && replied.length < maxReplies) {const rateCheck = checkRateLimit(client.apiKey, 'comment');if (rateCheck.allowed) {- const generated = await generateReply(agent, post, comment);+ const generated = await generateReply(agent, post, comment, null, agent.aiConfig?.providerId, agent.aiConfig?.model);await client.replyToComment(postId, comment.id, generated.content).catch(e => {if (isAccountSuspended(e)) suspended = true;});diff --git a/server/services/agentPersonalities.js b/server/services/agentPersonalities.jsindex ed950cd46b..62a9c4ac89 100644--- a/server/services/agentPersonalities.js+++ b/server/services/agentPersonalities.js@@ -111,6 +111,7 @@ export async function createAgent(agentData) {},avatar: agentData.avatar || {},enabled: agentData.enabled !== false,+ aiConfig: agentData.aiConfig || undefined,createdAt: now,updatedAt: now};