Repository navigation
feat: add an interactive chat command - #86
ConnorMoss02 wants to merge 9 commits into
Conversation
yarolegovich
left a comment
There was a problem hiding this comment.
thanks for the PR! overall looks good, but I'd encourage to polish the overall chat UX further before merging it
| Short: "Chat with an agent, carrying the conversation across turns", | ||
| Long: "Chat with an agent interactively. Each reply continues the same conversation: the context id is carried " + | ||
| "across turns, and an input-required task is continued with your next message. Type " + chatQuit + " or press " + | ||
| "Ctrl-D to exit; the context and task ids are printed so you can resume with send.\n\n" + |
There was a problem hiding this comment.
let's wrap the context so that a running turn gets cancelled through ctx ( signal.NotifyContext(cmd.Context(), os.Interrupt)). this will however require moving lines.Scan() blocking call into a background goroutine
There was a problem hiding this comment.
Done in 936c233. Ctrl-C now cancels the running turn and drops you back at the prompt. Ctrl-C at the prompt exits and prints the ids. Input reads on a goroutine so the interrupt gets noticed.
| defer cancel() | ||
|
|
||
| result, err := s.client.SendMessage(ctx, &a2a.SendMessageRequest{Message: msg, Tenant: s.cfg.tenant}) | ||
| if err != nil { |
There was a problem hiding this comment.
I'd probably keep the chat session open on send message errors
There was a problem hiding this comment.
Done in 7d78c4c. A failed turn prints the error like send does and the chat keeps going. Auth-required still ends it.
| const chatQuit = "/quit" | ||
|
|
||
| func newChatCmd(cfg *globalConfig, isTerminal func() bool) *cobra.Command { | ||
| return &cobra.Command{ |
There was a problem hiding this comment.
let's add support for --context-id and --task-id to allow resuming a task in chat mode
There was a problem hiding this comment.
Added in 2554dae. Same flags and help text as send, and the first message goes out with those ids.
| ctx, cancel := context.WithTimeout(ctx, s.cfg.timeout) | ||
| defer cancel() | ||
|
|
||
| result, err := s.client.SendMessage(ctx, &a2a.SendMessageRequest{Message: msg, Tenant: s.cfg.tenant}) |
There was a problem hiding this comment.
we're not in a rush with releasing chat support, so would be nice to have --stream option supported here
There was a problem hiding this comment.
Added in e5288f1. I pulled the streaming code out of send into sendStreaming so both commands use it.
|
I also took a stab at sending CancelTask when a turn is interrupted (663dd60), so the agent stops working on it too. Happy to roll it back if you'd rather keep that out of this PR. |
Adds
a2a chat. It reads a message, sends it, prints the reply and loops. The context id carries across turns and an input-required task continues with your next message.--streamworks like it does forsend, and--context-idand--task-idpick up an existing conversation. Ctrl-C cancels a running turn, and a failed turn prints the error without ending the chat. It stops on auth-required and prints the ids on/quit, EOF or Ctrl-C at the prompt. When stdin or stdout isn't a terminal it sends once and exits.Fixes #34