refactor(agent): unify chat loops and enrich Tool trait#24
Merged
Conversation
Collapse the four near-identical agent loops (simple, streaming, subagent, plan) into two shared drivers (chat_loop / stream_chat_loop), and give the Tool trait metadata (is_read_only, is_concurrent_safe, is_destructive, summary, validate_input) plus a ToolResult return type. - Plan mode now decides visible tools via Tool::is_read_only() instead of a hardcoded ["bash","read","ask_user"] allowlist, with an opt-in plan_tool_names override for arg-dependent cases. - QueryConfig bounds every loop (max_turns, max_result_chars) and UTF-8-safe truncation happens once in ToolSet::execute_calls. - AgentEvent::ToolCall splits into ToolStart + ToolEnd so UIs can render tool results.
Owner
Author
Test plan results
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SimpleAgent,StreamingAgent,SubagentTool,PlanAgent) into two shared drivers:chat_loop(non-streaming) andstream_chat_loop(streaming).Tooltrait with metadata —is_read_only,is_concurrent_safe,is_destructive,summary,validate_input— and changeTool::callto returnToolResult { content, is_truncated }instead ofString.Tool::is_read_only()rather than a hardcoded["bash","read","ask_user"]allowlist;plan_tool_names(...)is available when the read-only-ness depends on arguments.QueryConfig { max_turns, max_result_chars }; UTF-8-safe truncation happens once inToolSet::execute_calls.AgentEvent::ToolCallintoToolStart(summary) +ToolEnd(result preview) so UIs can render tool outputs.Test plan
cargo x solution-checkpasses (fmt + clippy + tests)cargo test -p mini-claw-code— all unit tests greencargo run -p mini-claw-code --example tui— manual smoke ofToolStart/ToolEndrenderingQueryConfig::max_turns = 10default