fix: load AGENTS.md and memory in agent mode

Agent mode was only loading README.md but not AGENTS.md or project
memory (.g3/memory.md). This meant agents were missing important
context that normal mode had access to.

Now agent mode uses the same read_agents_config(), read_project_readme(),
and read_project_memory() functions as normal mode, combining all three
into the agent context.
This commit is contained in:
Dhanji R. Prasanna
2026-01-11 16:15:58 +05:30
parent 1d884251cb
commit 74a18794a0

View File

@@ -797,11 +797,29 @@ async fn run_agent_mode(
// Note: allow_multiple_tool_calls parameter is deprecated but kept for API compatibility // Note: allow_multiple_tool_calls parameter is deprecated but kept for API compatibility
let system_prompt = get_agent_system_prompt(&agent_prompt, true); let system_prompt = get_agent_system_prompt(&agent_prompt, true);
// Read README if present // Load AGENTS.md, README, and memory - same as normal mode
let readme_content = std::fs::read_to_string(workspace_dir.join("README.md")).ok(); let agents_content = read_agents_config(&workspace_dir);
let readme_for_prompt = readme_content.map(|content| { let readme_content = read_project_readme(&workspace_dir);
format!("📚 Project README (from README.md):\n\n{}", content) let memory_content = read_project_memory(&workspace_dir);
});
// Combine all content for the agent's context
let combined_content = {
let mut parts = Vec::new();
if let Some(agents) = agents_content {
parts.push(agents);
}
if let Some(readme) = readme_content {
parts.push(readme);
}
if let Some(memory) = memory_content {
parts.push(memory);
}
if parts.is_empty() {
None
} else {
Some(parts.join("\n\n"))
}
};
// Create agent with custom system prompt // Create agent with custom system prompt
let ui_writer = ConsoleUiWriter::new(); let ui_writer = ConsoleUiWriter::new();
@@ -811,7 +829,7 @@ async fn run_agent_mode(
config, config,
ui_writer, ui_writer,
system_prompt, system_prompt,
readme_for_prompt, combined_content,
).await?; ).await?;
// Set agent mode for session tracking // Set agent mode for session tracking