Runs on our own model server: smaller requests and earlier summarising

Local models (Ollama on a laptop GPU) break on requests over ~19k tokens.
Model-server runs now send only the tools and skill the job needs and
summarise the conversation at ~16k tokens. Publish, schedule, reply and
DM tools are removed from every run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
metatroncubeswdev 2026-10-26 09:46:29 -04:00
parent 32563e87f9
commit 8170133a79

View File

@ -46,7 +46,25 @@ const READ_TOOLS = [
"mcp__social-manager__plan_add", "mcp__social-manager__plan_update", "mcp__social-manager__plan_add", "mcp__social-manager__plan_update",
"mcp__odoo-mcp__search_records", "mcp__odoo-mcp__read_records", "mcp__odoo-mcp__read_record_by_id", "mcp__odoo-mcp__count_records", "mcp__odoo-mcp__search_records", "mcp__odoo-mcp__read_records", "mcp__odoo-mcp__read_record_by_id", "mcp__odoo-mcp__count_records",
]; ];
const BLOCKED_TOOLS = ["mcp__social-manager__instagram_publish", "mcp__social-manager__facebook_publish"]; // Write tools a run must never touch. Blocking also drops them from the request, so the model never sees them.
const BLOCKED_TOOLS = [
"instagram_publish", "facebook_publish", "reply_comment", "hide_comment", "send_direct_message", "schedule_post",
"approve_scheduled", "cancel_scheduled", "schedule_from_library", "competitor_add", "comment_inbox", "direct_messages", "list_scheduled",
].map((t) => `mcp__social-manager__${t}`);
// Our own model servers (Ollama on a laptop) break on very long requests, so those runs send only what the job needs:
// the built-in tools runs use, the job's own skill and the social-manager server (≈13k tokens instead of ≈25k).
const LEAN_TOOLS = ["Read", "Glob", "Grep", "Edit", "Write", "Bash", "Skill", "TodoWrite"];
function leanOptions(prompt) {
if (!process.env.ANTHROPIC_BASE_URL) return { skills: "all" };
const skill = prompt.match(/^\/([a-z0-9-]+)/)?.[1];
return {
skills: skill ? [skill] : "all",
tools: LEAN_TOOLS,
strictMcpConfig: true,
mcpServers: { "social-manager": { command: "node", args: [path.join(PROJECT_ROOT, "connector", "src", "server.js")] } },
};
}
const jobs = new Map(); const jobs = new Map();
const queue = []; const queue = [];
@ -134,7 +152,13 @@ function docStamp(slug) {
/** Runs on our own model server (Ollama etc.): every model slot points at the chosen model, and the Anthropic key stays home. */ /** Runs on our own model server (Ollama etc.): every model slot points at the chosen model, and the Anthropic key stays home. */
function runEnv() { function runEnv() {
if (!process.env.ANTHROPIC_BASE_URL) return undefined; if (!process.env.ANTHROPIC_BASE_URL) return undefined;
const env = { ...process.env, ANTHROPIC_AUTH_TOKEN: process.env.ANTHROPIC_AUTH_TOKEN || "ollama", CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1" }; // Summarise the conversation at ~16k tokens (half of a 32k window): local models get unreliable on longer requests.
const env = {
...process.env, ANTHROPIC_AUTH_TOKEN: process.env.ANTHROPIC_AUTH_TOKEN || "ollama", CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1",
CLAUDE_CODE_AUTO_COMPACT_WINDOW: process.env.CLAUDE_CODE_AUTO_COMPACT_WINDOW || "32768",
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE: process.env.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE || "50",
CLAUDE_CODE_MAX_OUTPUT_TOKENS: process.env.CLAUDE_CODE_MAX_OUTPUT_TOKENS || "8000",
};
delete env.ANTHROPIC_API_KEY; delete env.ANTHROPIC_API_KEY;
for (const k of ["ANTHROPIC_DEFAULT_OPUS_MODEL", "ANTHROPIC_DEFAULT_SONNET_MODEL", "ANTHROPIC_DEFAULT_HAIKU_MODEL", "CLAUDE_CODE_SUBAGENT_MODEL"]) env[k] = AI.model; for (const k of ["ANTHROPIC_DEFAULT_OPUS_MODEL", "ANTHROPIC_DEFAULT_SONNET_MODEL", "ANTHROPIC_DEFAULT_HAIKU_MODEL", "CLAUDE_CODE_SUBAGENT_MODEL"]) env[k] = AI.model;
return env; return env;
@ -152,7 +176,7 @@ async function run(job) {
options: { options: {
cwd: PROJECT_ROOT, cwd: PROJECT_ROOT,
settingSources: ["project"], settingSources: ["project"],
skills: "all", ...leanOptions(job.prompt),
model: AI.model, model: AI.model,
maxTurns: AI.maxTurns, maxTurns: AI.maxTurns,
env: runEnv(), env: runEnv(),