[cli] Runs agent as an async spawned task #328
Closed
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.
We have a problem with the existing cli in that if the user presses Ctrl+c it will interrupt the agents action (with a tool result error) but then leave the agent running to respond to the error.
The user is trying to interrupt the process.
This PR is a POC that shows if we run the agent as a spawned async task then when the ctrl+c is pressed it is handled by the cli code (
tokio::signal::ctrl_c
) rather than the agent. This signals the spawned agent to break via a channel which results in the underlying process being terminated without further interaction. This is obviously a pretty ungraceful shutdown for the agent but required to stop processing immediately.How do we know it actually stops any underlying tools under the hood? I had it run a shell command loop that wrote a line for every second. When interrupting I was able to assert that the shell command stopped writing rather than completing the loop.
The downside is that we spinning up the agent from scratch for each user message. This can be avoided but requires making the agent and its attributes cloneable so they can survive the async move. An alternative would be to explore if we can push this async interaction deeper into the agent. At that stage we should probably consider having the cli interact with the goose-server rather than the agent directly and just solve that interaction.