Skip to content
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
1 change: 1 addition & 0 deletions libs/context/include/merak/context_serializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace merak {
struct SerializedPayload {
nlohmann::json openai_json;
nlohmann::json anthropic_json;
std::string system_text;
std::vector<Message> messages;
std::vector<ToolSpec> tool_schemas;
bool is_anthropic = false;
Expand Down
1 change: 1 addition & 0 deletions libs/context/src/context_serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ SerializedPayload ContextSerializer::serialize(
if (!system_prompt_full.empty()) {
system_text = system_prompt_full + "\n\n" + system_text;
}
payload.system_text = system_text;

payload.messages = ctx.provider_messages;
payload.tool_schemas = ctx.tool_schemas;
Expand Down
11 changes: 9 additions & 2 deletions libs/loop/src/agent_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,16 @@ std::vector<Message> AgentLoop::build_context() {
effective_system_prompt, config_.default_model,
config_.model_max_tokens, session_history_, sources);

// Prepend compaction summaries before returning (they are NOT part
// of session_history_ to avoid index conflicts)
// Prepend system prompt before conversation messages.
// The pipeline serializes it but does not inject it into payload.messages,
// so we must do it here for it to reach the LLM.
auto messages = payload.messages;
if (!payload.system_text.empty()) {
Message sys_msg;
sys_msg.role = "system";
sys_msg.content = payload.system_text;
messages.insert(messages.begin(), sys_msg);
}
if (!compaction_summaries_.empty()) {
messages.insert(messages.begin(),
compaction_summaries_.begin(), compaction_summaries_.end());
Expand Down
Loading