pub struct Agent { /* private fields */ }Expand description
MAX_ITERATIONS Documentation:
Why 200 iterations?
- Sufficient for most common tasks (file edits, code review, simple builds)
- Prevents infinite loops and runaway operations
- Balances task completion with resource efficiency
What happens when limit is reached?
- Agent stops execution gracefully
- User receives detailed warning message explaining:
- Task status (may not be complete)
- Reason for stopping (iteration limit)
- Next steps (continue, break down task, or resume)
Future improvements:
- Dynamic adjustment based on task complexity
- User-configurable limits in config file
- Auto-resume with state preservation
- Progress indicators showing iteration count
Examples:
- Simple task (edit file): ~5-10 iterations
- Medium task (refactor module): ~15-30 iterations
- Complex task (build system): ~40-50 iterations (may hit limit)
Full Agent with event output
Implementations§
Source§impl Agent
impl Agent
Sourcepub fn event_sender(&self) -> Sender<AgentEvent>
pub fn event_sender(&self) -> Sender<AgentEvent>
Get event sender for streaming
Sourcepub fn set_ask_channel(&mut self, rx: Receiver<String>)
pub fn set_ask_channel(&mut self, rx: Receiver<String>)
Set ask response channel (for TUI mode)
Sourcepub fn set_proxy_executor(
&mut self,
executor: Arc<dyn ProxyToolExecutor>,
tool_defs: Vec<ProxyToolDef>,
)
pub fn set_proxy_executor( &mut self, executor: Arc<dyn ProxyToolExecutor>, tool_defs: Vec<ProxyToolDef>, )
设置代理工具执行器
Sourcepub fn set_cancel_token(&mut self, token: CancellationToken)
pub fn set_cancel_token(&mut self, token: CancellationToken)
Set cancellation token
Sourcepub fn set_approve_mode(&mut self, mode: ApproveMode)
pub fn set_approve_mode(&mut self, mode: ApproveMode)
Set approve mode at runtime
Get a shared reference to the approve mode atomic.
Replace the internal approve mode with an externally-created shared atomic.
Sourcepub fn update_memory_summary(&mut self, summary: Option<String>)
pub fn update_memory_summary(&mut self, summary: Option<String>)
Update memory summary and rebuild system prompt. Note: Uses build_system_prompt (without project_path) to preserve cache.
Sourcepub fn refresh_codegraph_tools(&mut self)
pub fn refresh_codegraph_tools(&mut self)
Refresh CodeGraph tools after /init or codegraph init. This rebuilds both tools and system prompt with project_path. Call this only when CodeGraph state changes (not every request) to preserve cache.
Sourcepub async fn run(&mut self, user_input: String) -> Result<Vec<AgentEvent>>
pub async fn run(&mut self, user_input: String) -> Result<Vec<AgentEvent>>
Run chat loop with tool execution (streaming version).
Sourcepub fn set_messages(&mut self, messages: Vec<Message>)
pub fn set_messages(&mut self, messages: Vec<Message>)
Restore message history (for session continue/resume)
Sourcepub fn get_messages(&self) -> &[Message]
pub fn get_messages(&self) -> &[Message]
Get current messages (for session saving)
Sourcepub fn get_system_prompt(&self) -> &str
pub fn get_system_prompt(&self) -> &str
Get system prompt
Sourcepub fn get_token_counts(&self) -> (u64, u64)
pub fn get_token_counts(&self) -> (u64, u64)
Get current token counts
Sourcepub fn clear_history(&mut self)
pub fn clear_history(&mut self)
Clear message history
Sourcepub fn message_count(&self) -> usize
pub fn message_count(&self) -> usize
Get message count
Sourcepub async fn add_mcp_server(
&mut self,
name: &str,
config: McpServerConfig,
) -> Result<()>
pub async fn add_mcp_server( &mut self, name: &str, config: McpServerConfig, ) -> Result<()>
Sourcepub async fn remove_mcp_server(&mut self, name: &str) -> Result<()>
pub async fn remove_mcp_server(&mut self, name: &str) -> Result<()>
移除 MCP 服务器
Sourcepub async fn mcp_server_status(&self) -> Vec<ServerStatus>
pub async fn mcp_server_status(&self) -> Vec<ServerStatus>
获取 MCP 服务器状态列表
Sourcepub async fn start_mcp_server(
&self,
name: &str,
) -> Result<Vec<Arc<McpToolWrapper>>>
pub async fn start_mcp_server( &self, name: &str, ) -> Result<Vec<Arc<McpToolWrapper>>>
启动指定的 MCP 服务器
Source§impl Agent
impl Agent
Sourcepub fn has_pending_inputs(&self) -> bool
pub fn has_pending_inputs(&self) -> bool
Check if there are pending inputs waiting to be processed.
Sourcepub fn take_pending_inputs(&mut self) -> Vec<String>
pub fn take_pending_inputs(&mut self) -> Vec<String>
Get and clear all pending inputs.