11use std:: fmt:: Display ;
22
33// Copyright © 2025 Huly Labs. Use of this source code is governed by the MIT license.
4- use rig:: message:: Message ;
4+ use rig:: message:: { Message , ToolCall } ;
55
66#[ derive( Clone , Debug , Default , PartialEq ) ]
77pub enum AgentState {
@@ -11,21 +11,30 @@ pub enum AgentState {
1111 Thinking ,
1212 WaitingUserPrompt ,
1313 Error ( String ) ,
14- Completed ( bool ) ,
15- ToolCall ( String , serde_json :: Value ) ,
14+ Completed ,
15+ ToolCall ( ToolCall , bool ) ,
1616}
1717
1818impl AgentState {
1919 pub fn is_paused ( & self ) -> bool {
2020 matches ! (
2121 self ,
22- Self :: Paused | Self :: Completed ( true ) | Self :: Error ( _) | Self :: WaitingUserPrompt
22+ Self :: Paused
23+ | Self :: Completed
24+ | Self :: Error ( _)
25+ | Self :: WaitingUserPrompt
26+ | Self :: ToolCall ( _, true )
2327 )
2428 }
2529
2630 #[ inline]
2731 pub fn is_completed ( & self ) -> bool {
28- matches ! ( self , Self :: Completed ( is_finished) if * is_finished)
32+ matches ! ( self , Self :: Completed )
33+ }
34+
35+ #[ inline]
36+ pub fn is_tool_call ( & self ) -> bool {
37+ matches ! ( self , Self :: ToolCall ( _, false ) )
2938 }
3039}
3140
@@ -37,8 +46,14 @@ impl Display for AgentState {
3746 Self :: Thinking => write ! ( f, "Thinking" ) ,
3847 Self :: WaitingUserPrompt => write ! ( f, "WaitingUserPrompt" ) ,
3948 Self :: Error ( _) => write ! ( f, "Error" ) ,
40- Self :: Completed ( is_finished) => write ! ( f, "Completed({})" , is_finished) ,
41- Self :: ToolCall ( name, _) => write ! ( f, "ToolCall[{}]" , name) ,
49+ Self :: Completed => write ! ( f, "Completed" ) ,
50+ Self :: ToolCall ( tool_call, need_confirm) => {
51+ write ! (
52+ f,
53+ "ToolCall[{}] need_confirm={}" ,
54+ tool_call. function. name, need_confirm
55+ )
56+ }
4257 }
4358 }
4459}
@@ -63,12 +78,20 @@ pub enum AgentOutputEvent {
6378 HighlightFile ( String , bool ) ,
6479}
6580
81+ #[ derive( Clone , Debug ) ]
82+ pub enum ConfirmToolResponse {
83+ Approve ,
84+ Deny ,
85+ AlwaysApprove ,
86+ }
87+
6688/// Controls events that are sent to the agent
6789#[ derive( Clone , Debug ) ]
6890pub enum AgentControlEvent {
6991 SendMessage ( String ) ,
7092 /// Sends data to stdin of running terminal by idx
7193 TerminalData ( usize , Vec < u8 > ) ,
94+ ConfirmTool ( ConfirmToolResponse ) ,
7295 CancelTask ,
7396 NewTask ,
7497}
0 commit comments