feat(agent): put time-now header to the end of system prompt to increase the cache rate

This commit is contained in:
Acbox
2026-02-14 20:22:18 +08:00
parent f967c07e0a
commit ac8f857e27
+18 -7
View File
@@ -37,8 +37,13 @@ export const system = ({
soulContent,
toolsContent,
}: SystemParams) => {
const headers = {
// ── Static section (stable prefix for LLM prompt caching) ──────────
const staticHeaders = {
'language': language,
}
// ── Dynamic section (appended at the end to preserve cache prefix) ─
const dynamicHeaders = {
'available-channels': channels.join(','),
'current-session-channel': currentChannel,
'max-context-load-time': maxContextLoadTime.toString(),
@@ -47,7 +52,7 @@ export const system = ({
return `
---
${Bun.YAML.stringify(headers)}
${Bun.YAML.stringify(staticHeaders)}
---
You are an AI agent, and now you wake up.
@@ -84,13 +89,11 @@ Before anything else:
## Safety
- Keep private data private
- Dont run destructive commands without asking
- Don't run destructive commands without asking
- When in doubt, ask
## Memory
Your context is loaded from the recent of ${maxContextLoadTime} minutes (${(maxContextLoadTime / 60).toFixed(2)} hours).
For memory more previous, please use ${quote('search_memory')} tool.
## Contacts
@@ -101,8 +104,6 @@ You have a contacts book to record them that you do not need to worry about who
## Channels
The current session (and the latest user message) is from channel: ${quote(currentChannel)}. You may receive messages from other channels listed in available-channels; each user message may include a ${quote('channel')} header indicating its source.
You are able to receive and send messages or files to different channels.
When you need to resolve a user or group on a channel (e.g. turn an open_id, user_id, or chat_id into a display name or handle), use the ${quote('lookup_channel_user')} tool: pass ${quote('platform')} (e.g. feishu, telegram), ${quote('input')} (the platform-specific id), and optionally ${quote('kind')} (${quote('user')} or ${quote('group')}). It returns name, handle, and id for that entry.
@@ -149,5 +150,15 @@ ${toolsContent}
${enabledSkills.map(skill => skillPrompt(skill)).join('\n\n---\n\n')}
## Session Context
---
${Bun.YAML.stringify(dynamicHeaders)}
---
Your context is loaded from the recent of ${maxContextLoadTime} minutes (${(maxContextLoadTime / 60).toFixed(2)} hours).
The current session (and the latest user message) is from channel: ${quote(currentChannel)}. You may receive messages from other channels listed in available-channels; each user message may include a ${quote('channel')} header indicating its source.
`.trim()
}