Add interactive mode support for agents with --chat flag

- Remove chat from conflicts_with_all for --agent flag
- Add chat parameter to run_agent_mode()
- Run interactive loop instead of single task when --chat is passed

Usage: g3 --agent <name> --chat
This commit is contained in:
Dhanji R. Prasanna
2026-01-16 12:01:56 +05:30
parent 6bd9c51e8e
commit 94544c8f6a
3 changed files with 20 additions and 2 deletions

View File

@@ -12,6 +12,7 @@ use crate::language_prompts::{get_language_prompts_for_workspace, get_agent_lang
use crate::simple_output::SimpleOutput;
use crate::embedded_agents::load_agent_prompt;
use crate::ui_writer_impl::ConsoleUiWriter;
use crate::interactive::run_interactive;
/// Run agent mode - loads a specialized agent prompt and executes a single task.
pub async fn run_agent_mode(
@@ -23,6 +24,7 @@ pub async fn run_agent_mode(
task: Option<String>,
chrome_headless: bool,
safari: bool,
chat: bool,
) -> Result<()> {
use g3_core::find_incomplete_agent_session;
use g3_core::get_agent_system_prompt;
@@ -178,7 +180,7 @@ pub async fn run_agent_mode(
// Set agent mode on UI writer for visual differentiation (light gray tool names)
ui_writer.set_agent_mode(true);
let mut agent =
Agent::new_with_custom_prompt(config, ui_writer, system_prompt, combined_content).await?;
Agent::new_with_custom_prompt(config, ui_writer, system_prompt, combined_content.clone()).await?;
// Set agent mode for session tracking
agent.set_agent_mode(agent_name);
@@ -240,6 +242,21 @@ pub async fn run_agent_mode(
// Use provided task if available, otherwise use the default initial_task
let final_task = task.as_deref().unwrap_or(initial_task);
// If chat mode is enabled, run interactive loop instead of single task
if chat {
output.print("");
return run_interactive(
agent,
false, // show_prompt
false, // show_code
combined_content,
&workspace_dir,
new_session,
)
.await;
}
// Single-shot mode: execute the task and exit
let _result = agent.execute_task(final_task, None, true).await?;
// Send auto-memory reminder if enabled and tools were called

View File

@@ -96,7 +96,7 @@ pub struct Cli {
pub codebase_fast_start: Option<PathBuf>,
/// Run as a specialized agent (loads prompt from agents/<name>.md)
#[arg(long, value_name = "NAME", conflicts_with_all = ["autonomous", "auto", "chat", "planning"])]
#[arg(long, value_name = "NAME", conflicts_with_all = ["autonomous", "auto", "planning"])]
pub agent: Option<String>,
/// List all available agents (embedded and workspace)

View File

@@ -88,6 +88,7 @@ pub async fn run() -> Result<()> {
cli.task.clone(),
cli.chrome_headless,
cli.safari,
cli.chat,
)
.await;
}