How to make agent automatically terminate commands

When I execute a command with continuous output through agent first, agent can’t terminate the previous command before executing the next one, which will cause the new command execution to fail. For example, if I check the real-time logs of a container service with docker compose logs -f, and the next command is docker compose up -d to re-run it, the agent will be in a waiting state all the time!