Dirk Gently’s Holistic Detective Agency is a novel by Douglas Adams, published in 1987. Adams uses a combination of noir detective and science fiction tropes to tell a complex, humorous story involving historical figures, aliens, and time travel.
The novel begins with a scene describing a lonely tower in the midst of a rain storm; lights within the tower wax and wane, go out, and then the tower is filled with a bright light. In the next scene, an electric monk—a labor-saving device invented to believe in things its owner is too busy to believe in—sits and views the valley below. The monk is revealed to have developed a fault, and has begun to believe a great number of things simultaneously; for example, it currently believes everything it sees is a shade of pink.
Richard MacDuff goes to his alma mater St. Cedd’s to attend the Coleridge dinner. He witnesses his former teacher, Professor Urban ‛Reg’ Chronotis, perform a magic trick for the guests: he makes a salt shaker disappear apparently by sleight-of-hand, then produces an ancient clay pot brought by one of the guests and smashes it open, revealing the salt shaker. After this impossible trick, dinner ends with a reading of the famous (and famously unfinished) poem by Coleridge ‛Kubla Khan,’ except with a heretofore unknown second section.
The electric monk discovers a mysterious doorway and passes through it, emerging on Earth. MacDuff and Reg discover the monk’s horse in the professor’s bathroom. The monk encounters MacDuff’s boss, Gordon Way, and in a moment of misunderstanding shoots him. Gordon initially doesn’t realize that he is dead, attempting to use his car phone to call for help.
MacDuff returns to his home in London and has a strange experience, behaving in ways that make no sense to him. He leaves a message on the answering machine of Susan Way, his girlfriend, and then attempts to climb up a drainpipe to break into her apartment in order to erase it, but begins to resist the odd urges that he has. When Susan returns to her apartment, she is accompanied by a man named Michael Wenton-Weakes. Once inside the apartment, Wenton-Weakes begins acting strangely as well, talking about Coleridge and revenge.
MacDuff visits an old friend of his, Dirk Gently, who claims to be a ‛holistic detective’ who uses the ‛fundamental interconnectedness of things’ to solve mysteries. Gently famously got booted from school after running a scam claiming to use psychic powers to divine the questions on an exam, only to be amazed when his predictions actually came true. Gently is currently searching for a lost cat. Gently is concerned about MacDuff’s recent behavior, and informs him that he is a person of interest in the murder of Gordon Way. Gently suggests that he hypnotize MacDuff to learn what he can.
Gently discovers that MacDuff was possessed by a ghost, a very ancient ghost that has been wandering the Earth for many centuries. Based on MacDuff’s recollections, Gently also realizes that Reg has in his possession a time machine of some sort, and that Reg has been acting under the influence of the ghost as well. Gently visits Reg, and discovers that the time machine is actually Reg’s rooms on the campus. Reg reveals that he is actually much older than he appears—he has lived for a very long time and has actually forgotten who he was originally. He is aware of the ghost’s influence; the ghost has attempted to trick him into undoing a past mistake where he caused the extinction of the Dodo.
The ghost has taken possession of Wenton-Weakes, whose feelings of resentment due to a setback in his career have left him vulnerable to the ghost’s desire for revenge. Inhabiting Wenton-Weakes, the ghost seeks out Gently, MacDuff, and Reg and begs to use the time machine to go back and change history so he can save himself and his friends. The ghost reveals that it is actually an alien called a Salaxalan, part of a crew of a damaged ship that crashed on Earth millennia ago. They attempted repairs, but the engineer—now the ghost—used an electric monk to believe that the repairs would work. When they tried to take off, the engines exploded, killing them all, and the guilt-ridden engineer began to roam as a ghost, seeking a life to possess that could help.
At one point, it possessed Coleridge, and influenced the composition of ‛Kubla Khan’ and ‛The Rime of the Ancient Mariner,’ but Coleridge’s use of drugs made him unsuitable. The ghost reveals that when Reg performed his magic trick (using the time machine) the ghost tagged along and managed to bring the electric monk to Earth, intending to use the monk but finding it malfunctioning and thus useless. It then tried to possess MacDuff.
Gently is hesitant, but agrees to help. They travel into the past and Wenton-Weakes approaches the damaged Salaxalan ship to make proper repairs. MacDuff receives a phone call from Susan, whose father, Gordon, has contacted her as a ghost and revealed that Wenton-Weakes has murdered his professional rival while possessed by the ghost. Gently realizes that this murderous impulse was what allowed the ghost to possess him, and Gently puts the pieces together and realizes that the explosion that killed the aliens was also the triggering event that caused life to begin on Earth. Instead, Gently, MacDuff, and Reg travel back in time to interrupt Coleridge as he’s working on ‛Kubla Khan,’ becoming the famous visitors who caused the poem to never be completed. This changes history sufficiently to ensure that the ghost can never inhabit Wenton-Weakes, thus saving humanity.