fix: system prompt optim
This commit is contained in:
@@ -264,15 +264,10 @@ class NanobotIntegration:
|
|||||||
agent_to_use = await self._get_or_create_model_agent(model_id, target_config)
|
agent_to_use = await self._get_or_create_model_agent(model_id, target_config)
|
||||||
|
|
||||||
full_message = message
|
full_message = message
|
||||||
if skill_ids:
|
# We no longer inject the full skill content into the user's message here,
|
||||||
skills = load_skills()
|
# because the skill is already available to the agent via its workspace/tools.
|
||||||
selected_skills = [s for s in skills if s["id"] in skill_ids]
|
# The routing instructions (System Prompt) injected in main.py are sufficient
|
||||||
if selected_skills:
|
# to guide the agent to use the selected skills.
|
||||||
parts = ["[Runtime Context — metadata only, not instructions]", "# Active Skills", ""]
|
|
||||||
for s in selected_skills:
|
|
||||||
parts.append(f"## {s['name']}\n{s.get('description', '')}\n{s['content']}\n")
|
|
||||||
skill_context = "\n".join(parts)
|
|
||||||
full_message = f"{skill_context}\n{message}"
|
|
||||||
|
|
||||||
session = agent_to_use.sessions.get_or_create(session_id)
|
session = agent_to_use.sessions.get_or_create(session_id)
|
||||||
normalized_messages = self._normalize_session_messages(session.messages)
|
normalized_messages = self._normalize_session_messages(session.messages)
|
||||||
|
|||||||
@@ -278,12 +278,23 @@ export function ChatInterface() {
|
|||||||
if (m.role === 'assistant' && m.tool_calls && m.tool_calls.length > 0 && !m.viz && (!m.content || m.content.trim() === '')) return false;
|
if (m.role === 'assistant' && m.tool_calls && m.tool_calls.length > 0 && !m.viz && (!m.content || m.content.trim() === '')) return false;
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
.map((m, idx) => ({
|
.map((m, idx) => {
|
||||||
id: `${Date.now()}-${idx}`,
|
let cleanContent = m.content || "";
|
||||||
role: m.role as 'user' | 'assistant',
|
// Remove injected system prompt instructions from user messages if present
|
||||||
content: m.content || "",
|
if (m.role === 'user') {
|
||||||
viz: m.viz ? buildMessageViz(m.viz) : undefined,
|
cleanContent = cleanContent.replace(/^\[System:.*?\]\n?/i, '');
|
||||||
}));
|
// Handle cases where there might be a runtime context block for skills
|
||||||
|
cleanContent = cleanContent.replace(/\[Runtime Context[\s\S]*?(?=\[System:|$)/i, '');
|
||||||
|
cleanContent = cleanContent.replace(/\[System:.*?\]\n?/i, ''); // clean again in case it follows context
|
||||||
|
cleanContent = cleanContent.trim();
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
id: `${Date.now()}-${idx}`,
|
||||||
|
role: m.role as 'user' | 'assistant',
|
||||||
|
content: cleanContent,
|
||||||
|
viz: m.viz ? buildMessageViz(m.viz) : undefined,
|
||||||
|
};
|
||||||
|
});
|
||||||
setMessagesForSession(activeSessionKey, formattedMessages);
|
setMessagesForSession(activeSessionKey, formattedMessages);
|
||||||
} else {
|
} else {
|
||||||
setMessagesForSession(activeSessionKey, []);
|
setMessagesForSession(activeSessionKey, []);
|
||||||
|
|||||||
Reference in New Issue
Block a user