When, in 2007, Channel 4 screened six sitcom pilots in their 25th-anniversary Comedy Show-case series, one of the hopefuls, Free Agents, stood out head and shoulders above the rest. Mind you, given the pedigree of the cast (Stephen Mangan from Green Wing, Sharon Horgan from Pulling and Anthony Head from Buffy the Vampire Slayer) and the producer (Nira Park, who oversaw the sitcoms Spaced and Black Books as well as the films Hot Fuzz and Shaun of the Dead), you might feel surprised that Channel 4 didn't skip the pilot stage.
But then these are constrained and cautious times in television commissioning, despite it being perfectly obvious from visiting the set in a Kafka-esque Sixties office block near London's Euston station that Free Agents is going to be comedy gold. It's an acerbic, rude and very funny "will they/ won't they?" romance set within a showbiz talent agency, and in the scene I'm watching, Stephen Mangan's character, Alex, who is in the midst of a painful divorce, is preparing to leave work for the weekend.
Sharon Horgan's character, a work colleague called Helen, whose fiancé has recently died, isn't in this scene, and Horgan is tending to her baby daughter, hopefully out of earshot of Anthony Head's Stephen. Stephen is Alex and Helen's boss, and he is describing with great relish how the emptiness of Alex's life will "creep up and grab his ball sack before slipping round and entering his arsehole". Family viewing this isn't.
One review of the 2007 pilot episode described Head's character – a sex obsessive whose idea of warming up morning conference is to discuss in lurid detail who shagged whom the night before – as a "human erection".
"When I first read it, I thought, 'Can I say that? Can you get away with that on TV?'" he tells me between takes. "This is extremely good writing, and I hope people see it as that and not just, 'Oh, they're trying to be rude and get away with stuff.'" And it is clever writing, an adult romcom whose author, Chris Niel, describes it as "Richard Curtis on poppers. I wanted to write something about a grown-up relationship where people come to it with a lot of baggage... where it's not a simple boy-meets-girl. This is a boy-who-just-got-divorced-meets-girl-who's-just-getting-over-the-death-of-her-boyfriend kind of thing."
Stephen Mangan's Alex is experiencing marriage meltdown while having to cope with his hectic life as a showbiz agent, a deeply autobiographical situation for Niel, a former actors' agent at ICM – now called the Independent Talent Group – whose clients included Robert Carlyle, Matt Lucas and David Walliams.
"I got divorced at the time that I was an agent," he says. "And there was a sort of comedy in the fact that you would be on the phone giving one of your clients details of an audition for a commercial and then you'd nip to the loo and have a quick cry over the fact that you miss your kids."
For Mangan, playing a needy divorcee allowed him to show a more sensitive side after being rather typecast as selfish, arrogant rotters since his Green Wing anaesthetist Guy Secretan. "It's nice not to be the biggest bastard in the show, or the filthiest," he says. "It's nice to pass that accolade to Anthony Head..."
Getting into the role of someone emotionally and physically fatigued by divorce and having to sleep in his car was probably helped by the fact that, while shooting Free Agents, Mangan was also appearing nightly in Alan Ayckbourn's The Norman Conquests at the Old Vic. "We had to do the whole trilogy on Saturdays," he says. "And Sharon has just had her baby, so we were both dog-tired. But then a show like this depends on chemistry, and we have it."
Chris Niel describes their on-screen chemistry as a "tennis-match thing going on... they're very evenly matched, and you feel very lucky when you're writing stuff for them."
"I think the whole chemistry thing is weird," says Horgan. "It's like a kind of science. On a plane recently, I watched the film PS I Love You with Hilary Swank and Gerard Butler. They're amazing actors, but you didn't believe they even liked each other."
Horgan, whom journalists have so often dubbed "the funniest woman you have never heard of" that it has become a cliché, was the creator and star of one of the darkest and funniest sitcoms of recent years, BBC3's Pulling. Despite a few "control-freak moments", she was happy to leave the writing to someone else this time and luxuriate in the role of Helen, the bereaved agent who, unusually for a "will they/won't they?" romcom, begins the opening episode in bed with the man she might or might not end up in a relationship with.
"It's that modern thing where you shag and then backtrack," she says. "You do that drunk-shag thing, and then you've got to have a second shag to pretend everything's OK. And then after that, you decide whether you have a relationship or not."
"There's as much comedy about them being together as there is about them being apart," reckons Chris Niel. "I think we can get a few series out of it." Rather like Sex and the City, perhaps – or at least that is the rather misleading comparison that has been made with Free Agents, according to Stephen Mangan. "I'm obviously Sarah Jessica Parker," he laughs. "A lot of those American series deal with quieter, more adult stuff, and they deal with them with a mixture of comedy and drama, so in that way it's similar. But, frankly, I can't think of another show it's immediately like."
And what about agents? Do they have their own horror stories?
"My first agent was a fishmonger on the side," says Horgan, with her fabulous foghorn laugh. "I wanted an agent and I didn't care if he sold fish or not. When I started out, it was just nice to have someone looking out for you."
Stephen Mangan, who is returning to America this year with his Green Wing (and Barclaycard advert) co-star Julian Rhind-Tutt to make a series about British actors in Hollywood, recalls his first brush with a US agent. "He said to me, 'I'm your biggest fan. I've seen everything you've done. You're going to be massive, Simon...'"
Anthony Head recalls having to get rid of his agent and leave Britain for the States after being typecast as the "Gold Blend man" in those classic late-1980s adverts. "A casting director at the time did say, 'This is a serious drama; we don't people reaching for their coffee jars.'" You dread to think what they will be reaching for after his lurid turn as Stephen in Free Agents. Don't miss him or it.
Free Agents begins on Channel 4, tonight, 10pm
SIX OF THE BEST: AGENTS ON SCREEN
Tony Curtis - 'Sweet Smell of Success'
Even today, Broadway theatrical agents talk of going into "Sidney Falco mode", in honour of Tony Curtis's poisonous agent, who is in thrall to Burt Lancaster's gossip columnist J J Hunsecker. "I'd hate to take a bite out of you," J J tells Falco in Alexander Mackendrick's 1957 classic. "You're a cookie full of arsenic."
Sydney Pollack - 'Tootsie'
Dustin Hoffman plays Michael Dorsey, the actor who dresses as a woman in Sydney Pollack's 1982 comedy. Pollack himself plays Michael's agent, George Fields. Michael: "Are you saying nobody in New York will work with me?" George: "No, no, that's too limited. Nobody in Hollywood will work with you either."
Woody Allen - 'Broadway Danny Rose'
Woody Allen plays the unsuccessful but big-hearted artistes' agent who falls foul of a mobster in his 1984 comedy. His clients include wine-glass players, bird trainers and washed-up lounge crooners. Sample dialogue: "If you take my advice, you'll become one of the great balloon-folding acts of all time!"
Vanessa Redgrave - 'Prick Up Your Ears'
Vanessa Redgrave portrays Peggy Ramsay in Stephen Frears's 1987 adaptation of John Lahr's Joe Orton biography. Redgrave says, when Orton's mother is fussing over mixing her son's ashes with those of her son's lover: "It's a gesture, dear, not a recipe."
Jeremy Piven - 'Entourage'
The stars of HBO's saga about a young Hollywood A-lister and his buddies are regularly upstaged by Jeremy Piven's agent, Ari Gold. He has won an Emmy three years on the trot with such lines as: "You deal with talent the same way that you deal with women. You have to make them believe that they need you more than you need them."
Stephen Merchant - 'Extras'
Ricky Gervais's writing partner on 'The Office' won a British Comedy Award playing Andy Millman's useless agent, Darren Lamb, in their follow-up sitcom. Darren is so rubbish at being an agent he works part-time at Carphone Warehouse. Andy: "What's happening with my script?" Darren: "What script?"