The mattress, stuffed with lumpy cotton and resting on a plain metal frame, fills most of her room, just one metre by two. The walls are made of mud, the roof of scraps of tin. The air has a tang from the raw sewage and rotting food scraps in the alley outside, and Agnes tries to keep the clouds of flies at bay with a crisp white muslin curtain in the doorway. Remnants of linoleum, pieced together like a quilt, cover most of the dirt floor. She has a kerosene burner for making tea and a gas lantern. Two mouldy calendars, giveaways from insurance companies many years back, are tacked to the walls, the only decoration. A collection of worn facecloths hangs drying on a small clothesline. Beside the bed she keeps a large white box, containing the best part of a gross of condoms.

Agnes rents this room for 900 Kenyan shillings (£6) a month, bed included. She doesn't live here - she also rents another room, a bit bigger than this one, on the other side of Majengo, a slum neighbourhood on the edge of Nairobi. She shares that room with the three youngest of her five children. They have never seen this one. This room is just for work.

Agnes arrives here around six o'clock each morning, when the sun is climbing in the sky, and she makes sure she is on the way home before the sun sinks again 12 hours later - she is a lady of the evening who works only in the daylight hours. There is plenty of rape and theft and murder in Majengo in the daytime, but at night the streets are completely lawless. When Agnes arrives in the morning, she sweeps the patch of floor and the narrow alley outside. She makes a cup of tea, sips it from a battered tin mug, stacks the cloths by the bed. Then she takes a low three-legged wooden stool into the alley, sits down and waits for business. 'Karibu,' she says as men pass - Kiswahili for welcome. She gives them a wink and her slow smile that unfurls like honey off a spoon. 'We all try our luck each time a person passes,' she explained. 'If he stops to look at me maybe he is interested, but if not, maybe he is used to someone else.' In front of every third or fourth shack in the streets a woman sits on a stool, modestly dressed like Agnes, who wore a bright wrap printed with blue and yellow chickens on the day she introduced me to a working woman's life in Majengo.

Most days a man stops before she has been in the alley for half an hour. 'They are people on their way to work. Or men on the road who spent the night away from their wives - they pass here for breakfast.' When a man stops at Agnes's soft 'Karibu', she invites him to step into her room. 'Most men are discreet - the ones with wives want to get in the door very quickly.' Inside, they negotiate. The price is set at between 50 and 100 shillings - 37p to 75p. She slides the door closed, but the scratchy sounds of a neighbour's transistor radio drift through the screened window; her customer knows he must be silent. 'We even tell them not to make a lot of noise,' Agnes said, sounding very prim, 'because there could be a family in the next house.' She removes her wrap, lies back on the bed, her arms above her head. She does not embrace the client, whispers no encouragement. This is a brisk transaction. 'If your five minutes are over and you are still there,' she pointed at her chest, 'you have to pay another 50 shillings,' she said firmly. Business concluded, her client steps over the curious chickens in the doorway and back out into the alley, and Agnes cleans up with the cloths and a pitcher of water from the standpipe at the end of the alley. Then she returns to the stool.

This interaction is repeated a dozen times each day. A fair portion of the men who stop have spent time with Agnes before. 'The service must have been good, so they come back,' she told me with a giggle. At the end of the day, she padlocks the door and takes home perhaps 500 shillings, enough for some food bought at the market stalls on the way, and a bit put aside for the next instalment of the children's school fees, or some kerosene or soap.

Agnes came to Nairobi from Machakos, two hours to the east by bus, in 1971. She was 20 years old. There was only the exhausting work of farming at home, and she hoped to find a job in the city. Before long she was hired as a maid in a middle-class house. That lasted a year, and then she found more work mending clothes, and then casual labour in the industrial area on the edge of the booming city. That led to a job making paper bags in a factory - but she injured a finger in the machinery after a couple of years and was fired. By then she had had three small children, fathered by a couple of boyfriends who hadn't stuck around. Her mother had died back home, her father was unwell, and she felt there was no one in Machakos to whom she could turn.

Agnes had only one room, then, in Majengo, the sort of chaotic community at the edge of the city where so many of Africa's rural poor end up. Majengo is built around a vast market for mitumba - second-hand clothes given by North Americans and Europeans to charity shops that end up shipped to Africa in giant bales. Traders from all over east Africa come to hunt for bargains in First World cast-offs. The market also sells everything from plastic washbasins to jerry-rigged, scrap-metal satellite dishes. There are food stalls and tearooms and hostels for the travellers.

Thousands of people move through here every day, many with a little disposable income suddenly in their pocket: like similar communities the world over, it is a natural centre for sex work. In addition to the travellers from out of town, men from all over Nairobi - police officers, civil servants, welders, street sweepers, teachers and taxi drivers - seek out the anonymity of the vast market for their occasional sexual encounters.

When Agnes was despairing about how to make money, how she would survive in the city, her neighbours suggested she try umalaya, sex for money. 'In the neighbourhood there were other women who were doing it, and they encouraged me to try it. I had children who needed food.' And so, with great reluctance, she began to sit on a wooden stool outside her home and try to catch the eye of men who passed by. She never imagined, in those first few weeks, that she would be earning a living this way 30 years later.

Today, thousands of women work in the alleys of Majengo and the other sprawling slums of Nairobi, but only one or two of Agnes's friends from her first days in the business are still around. 'The ones I started with are no longer here - they have died,' she said simply. 'Most of the people I have worked with have died.' Beginning in the early Eighties, women started to get thin, with sharp coughs and white fur that coated their mouths and throats; back then they called the illness Plastic, Agnes said, because city workers hastily wrapped up the bodies of people who died that way in plastic sheeting. Some of the women died there in Majengo, and others went back to the village when they grew too sick to work. But Agnes remained healthy, year after year.

What happened to her - or, more accurately, what didn't happen to her - would prove to be one of the greatest discoveries in the 25-year battle with Aids. She would acquire, over the next two decades, a certain fame, in the world of virology and infectious disease, as one of those Nairobi prostitutes. But Agnes's body would be slower to give up its secrets than anyone imagined.

This story starts with chancroid, a venereal disease that causes suppurating ulcers on the genitals. On the other side of the world from Nairobi, in the Canadian prairie city of Winnipeg, there was an outbreak of chancroid in the late Seventies, and infectious-disease experts at the University of Manitoba began to investigate. Before long they had figured out how to grow the bacteria in the lab, but the outbreak had quickly been brought under control by public health officials, and the researchers were left without patients. That might have been the end of it, had a Winnipeg microbiologist not got talking to a colleague from the University of Nairobi at a conference a few months later. 'You want chancroid?' the Kenyan asked. 'We've got chancroid.'

And so Allan Ronald flew to Nairobi in 1980. He soon noticed that sexually transmitted infections, or STIs, such as chlamydia and gonorrhoea were rampant. He also noticed that most of the people seeking help at government clinics for these infections had in common the fact that they frequented prostitutes in an industrial slum. He and a couple of colleagues set up a shop-front clinic in Nairobi, offering free treatment to anyone in return for participation in medical research. Before long the operation expanded into slums around the city. They were candy-store settings for young western researchers, with more weird microbes coming through the door in a single morning than they might see in a year back home. And their patients were more than happy to participate, in exchange for the top-notch health care they could never have afforded to purchase in Nairobi. 'Here we got treatment if we were diagnosed - the city clinic never had any drugs,' said Agnes, who first attended a clinic in 1983 and soon became a regular. And, she said, she and the other women felt less judged in the research clinic; no one gossiped about the way they earned their living.

In those first few years, the Manitobans and colleagues from other universities in the west who joined them did some important research on sexually transmitted diseases, and the impact on children whose mothers were infected with gonorrhoea or chlamydia. But the discovery that would rock the scientific world came from the whim of a graduate student. In 1985, Joan Kreiss, a student researcher from the University of Washington, decided to test the sex workers, including Agnes, for HIV. The virus had been identified in New York four years earlier, and Kreiss wanted to use the new test for antibodies to HIV. Her older colleagues were dubious. They suspected, from post-mortems on patients who had symptoms similar to those being reported in New York, that HIV was present in Nairobi - and years later, tests of stored blood from east Africa would show that, in fact, some communities in the region at that point had infection rates as high as 20 per cent. But there was not a single documented case of Aids in Kenya at the time, and many scientists were doubtful that women could even catch the disease through sex. So no one was prepared for what Kreiss found. Two-thirds of the women she tested were HIV-positive.

Her findings - one of the earliest recorded signs of the African epidemic - did not go down well. The government of Kenya threatened to deport the foreign researchers and shut the whole project down. 'The government said, "It's not true what you are saying! You're going to drive the tourists out of Kenya!"' recalled a rueful Elizabeth Ngugi, a community health professor at the University of Nairobi. She was working ('in the mud and in the sun and in the rain and in the dust') to get to know Agnes and the Majengo women, building relationships that would be the core of research through the decades. She soon organised 600 women into support groups, brought them into the clinic for classes on sexually transmitted diseases, gave them condoms and encouraged them to present a united front to clients, insisting on protected sex.

Over the next few years, research involving the women yielded two big discoveries. The first was that mothers passed HIV to their babies in breast milk. Researchers already knew there was some transmission of the virus this way, but a study in the slum showed that the longer a mother breastfed, the higher was the risk of transmission - and that far from being negligible, this was in fact a major source of infection. The second major finding was that a person with a conventional STI, such as gonorrhoea, has a much higher chance of contracting HIV - as much as 70 per cent higher - than a person not infected. All of this, however, paled beside a discovery that emerged in the late Eighties. Frank Plummer, now the director of Canada's Centre for Infectious Disease Prevention and Control, in Ottawa, worked in the Nairobi project from its early days. He was intrigued by these HIV-positive women, who gave the lie to so much of the predominant thinking about Aids at the time - that it didn't exist in Africa, that women couldn't get it, that heterosexual sex was no real risk. By 1988, he had noticed something bizarre: over time, more and more of the women were testing positive for HIV - but not all of them. Some, including Agnes, were still around, three and four and five years later, and in their biannual HIV tests they were still negative. Plummer began to track them closely, and concluded that a small number of the women - perhaps five per cent - were simply not getting infected. 'They're basically immune to HIV,' he told me. 'Their immune systems for whatever reason are able to recognise and kill HIV.' In the study of a particularly impenetrable virus, this was a massive discovery.

Keith Fowke, a professor of medical microbiology at the University of Manitoba, who was then a student working under Frank Plummer in Nairobi, explained it like this. 'We did the models and found that these women were not just really, really, really lucky - it was beyond the statistical chance of luck playing a role. We estimated that many of these women have had 500 to 2,000 sexual exposures to infected men when they weren't using a condom.' Surveys found that a quarter of the men who frequented sex workers in the area were HIV-positive. And while Ngugi's shack-to-shack education efforts had early success getting Agnes and the other women to use condoms with some of their one-off clients, there were still many exceptions: men would pay extra not to use condoms - money that women hard-up for cash were reluctant to forgo - and sex workers didn't use them with their 'regulars', men they saw every week or two. Ngugi's surveys found that the women used condoms, at best, only 75 per cent of the time, so there could be no question that Agnes and a handful of others had been routinely exposed to HIV over a decade or more.

Yet they weren't infected. It wasn't good nutrition - the women did not earn enough to eat well - and it wasn't that they somehow took better care of themselves, because they had had other STIs and ailments. Something else was happening to make these women immune.

Then Plummer and his team noticed something even more peculiar. The women's likelihood of being infected with HIV/Aids was related to the length of time they had been doing sex work: the longer a woman had been selling sex in Majengo, the less likely she was to be infected. If she'd been doing it for five years and was still HIV-negative, the data suggested, then the odds were she was going to stay that way. These findings were so counterintuitive that Plummer and his team struggled to find anyone who would publish them. The phenomenon didn't get major attention until two years later, when he described the resistant women at the International Aids Conference in Amsterdam in 1992.

Once the public really began to understand that there were people who were immune to Aids - and the dark irony that it was the sex workers vilified for spreading the disease - Majengo became a focus of attention. Television news teams poured into the slum, clamouring to meet the women. The attention left Agnes baffled. 'I just thank God,' she said then, as she does now. She couldn't explain why she wasn't sick. She could just give thanks for it at Mass every Sunday morning.

The researchers, however, were frantically trying to decode what was going on in the bodies of Agnes and the other women. 'Either the virus couldn't infect their cells at all or the virus could but their bodies were clearing the infection in some way,' explained Fowke. 'But when we isolated the blood cells of some women in the lab and exposed their cells to HIV, it could get inside their cells and was able to replicate and able to grow just fine. So we started looking at their immune system - HIV was able to establish initial infection and the immune system was able to clear it,' Fowke said. 'We've really found cells that can kill HIV in these women.'

Agnes has, in effect, a callus: the first time she was exposed to the virus, her body produced enough killer T cells to fight it off. This part isn't unique - the body of every person who is exposed to HIV mounts some level of response, and sometimes manages to fight it off; a single exposure does not guarantee infection. But Agnes's body, it seems, not only produced sufficient and strong enough cells to fight the virus off the first time, it then produced a whole raft of those killer Ts, flooding her system with guardians whose sole brief was to keep an eye out for cells infected with HIV. The infected cells have a distinct pattern of little bumps on them, called epitopes, which act like a red rose in the lapel as far as the killer Ts are concerned, letting them know just which cells they want to hunt down. Then every subsequent time - probably thousands of times - that HIV got into Agnes's body, her killer T cells drove it back. A person does not normally maintain a large number of killer T cells for a long period - just long enough to kill something off, then production drops. But in Agnes, fairly constant exposure to HIV kept her killer T cell count high.

This conclusion was reinforced when Plummer and his team noticed that women who take a 'sex break' - who make a trip home to the village for a few weeks, or save up a little money and leave sex work for a while to try selling shoes instead, or hook up with a regular who keeps them in cash for a year or two - were far more likely to get infected, almost immediately, if they returned to sex work, even though previously they had had years of apparent immunity. On the break, their bodies stopped making the killer T cells, leaving them vulnerable again.

The Nairobi women aren't the only people in the world immune to HIV. Some Caucasian men have been found to have a genetic mutation that means their cells lack one of the molecular 'hooks' that HIV latches on to, and so they cannot be infected. And no doubt there are other groups of people who, like these women, are able to kill off the virus - but it is much easier to see, and monitor, in this community of women who are repeatedly exposed to the virus than it would be in, say, a group of nuns in a convent in Europe. They might be immune to HIV, too, but how would anyone ever tell?

From the moment it became clear that Agnes and a handful of other women in Majengo - about 100 to date - really could fight off the virus, the researchers in Nairobi hoped that their biology would hold the secret of an HIV vaccine. Soon a team from Oxford University was at work on a vaccine that used the epitopes (the tell-tale bumps on infected cells) that triggered Agnes's killer Ts. They hoped it would provoke other people's bodies to produce killer T cells in the same way that the real virus appeared to trigger production in the sex workers. Trials began in Nairobi in 2001, and a second trial was mounted by Pontiano Kaleebu and his colleagues in Entebbe a couple of years later. But despite high hopes, the Oxford vaccine didn't cause that explosion of killer T cells. And so it was back to the painstaking work of trying to figure out the secret of Agnes's immunity. 'Sometimes a vaccine feels impossibly far away,' sighed Keith Fowke. 'All our knowledge about these HIV-resistant people is interesting and I feel it's important... but it is frustrating.'

For Ngugi, watching as Aids decimates ever more of this community where she has built such strong ties, the gains are hollow. 'Yes, it's fascinating,' she told me. 'But sometimes I feel very sad. Sometimes you are not a scientist but a friend, and you feel the emptiness inside.'

There was a certain sense of breath-holding among the Nairobi researchers when Plummer and his team first proved the women's bodies were able to kill off HIV, but that breath has long since been let out. Today, the research strategy in Majengo revolves around intense study of Agnes and the other resistant women (who make up about five per cent of the cohort at any one time), from analysing their genome to breaking down the chemical components of the mucosal membranes in their vaginas, in an effort to figure out what may be protecting them. So far researchers have not found anything present in 100 per cent of the women, so it may be that the protection comes from multiple overlapping factors, including some that are genetic. There is a strong family correlation - people related to an HIV-resistant woman seem to be half as likely to get infected as people who are not related.

Agnes is aware that she is a fascinating specimen. 'Most of the people have been very interested in me,' she said matter-of-factly. But she has no understanding of the biological basis for her HIV resistance. 'No one has told me,' she said with a shrug. She gets good, free health care at the clinic for the occasional sexually transmitted infection and also for respiratory infections which plague residents of the polluted slum. So she is happy to give them her blood a couple of times a year, and to enjoy a sense of contributing something to her community.

But Agnes's survival has served to highlight a disquieting aspect of this research. She has come to the clinic for more than 20 years. In that time, more than $22m in scientific grant money has flowed through the project, and many of the researchers have earned reputations as the top experts in their fields. Yet Agnes and a handful of other women are still selling sex, to an average of eight clients a day, still for a dollar or two each time - although they say they would like nothing more than to get out of sex work. When I asked her what she would like to do instead, Agnes's broad face lit up. 'Any kind of job I could do. I could be a cleaner or anything. But it's very difficult to get a job - you have to know somebody to get a job.' And Agnes said she doesn't know anybody who could help. With only limited literacy after three years of primary school, and no other skills, Agnes said she sees no other options. 'It's embarrassing, this profession,' she said. She refuses to discuss what she does for a living with her children, although she is sure they know. 'I've never told them what I do, but I think they can see it. I think they know what I'm doing is not good but they know I do it to provide for them.'

Agnes's frustration with her life in sex work raises troubling ethical questions about research, the kind that bedevil investigations into Aids vaccines, prevention technologies and treatment, all of which, by definition, involve large groups of poor Africans, the people most at risk. What obligation does a researcher such as Plummer have to the women who have given him their blood for 20 years? What does this project owe Agnes?

'Those are difficult questions,' Plummer told me. 'My philosophy has been: try to help as many people as we can with what resources we have so we can ultimately solve it. We provide treatment for a lot of medical conditions and counselling for safer sexual behaviour and free condoms and referral to other medical services - which prevents about 10,000 infections each year. We do have an obligation to provide some basic level of care, and since 2004 we have provided anti-retroviral treatment [ARV], which is an important step. But ARV drugs are not going to solve this problem.' Plummer doesn't disagree that women like Agnes need a route out of prostitution. 'I don't know what those ways out are, though, and anything we could do is just working on the margins - it's unlikely we'll be able to do anything to get them to the point that they're not partially dependent on sex work: you can only make so much money selling tomatoes or weaving baskets.'

His Kenyan colleague Elizabeth Ngugi is unconvinced by this line of argument. 'These women have given the world such a huge body of knowledge, but what has the world done to help them change? The research findings have given us so much, but what have we given back? There is more research money coming all the time - quite clearly there is an imbalance.' In 2002, she received funds from a donor agency to train 120 of the women in new skills such as dressmaking and hairdressing, and she said 80 of them successfully made the transition out of sex work. She has helped a few others make their way to local benevolent agencies and out of the business, but most are stuck, and the research budget includes no funds to give them other options - a grim irony when, as she pointed out, they've educated all the women about what a huge risk sex work is to their lives.

Plummer agreed that the women need basic education in numeracy and savings and small-business skills. 'But you can't get a research grant for that,' he said. The ethics of science today require that the women get counselling and condoms, but ethics approval boards make no demands about maths classes or instruction in how to set up an alleyway beauty salon.

There is a small patch of grey at Agnes's hairline these days, and her body has thickened to that of a woman of a certain age. 'I'm getting old,' she said. 'There will be a time that I'm too old - at around 60. Maybe 10 years from now clients will not even look for me. It will be difficult.' Now she feels lucky to get 100 shillings from a client, when a young woman newly arrived in Majengo might get as much as 300 - although in any case, trade is not what it once was. 'Ever since we got this disease, business has dropped. Most men go home to their wives on the weekend.'

Of the men who still buy sex (and she manages to find nine or 10 each day), most now agree to use condoms - but not all, and Agnes worries. She would like to start a small business that would keep her family when men no longer stop outside her room, but she used all the few thousand shillings she had saved to put up a single-room house on the land her father left her back in the village: insurance in case her luck runs out and she needs to go home.

Agnes's mysterious immune system has garnered her considerable fame in the world of Aids, but little else. She lives a life almost totally unchanged from her first days in umalaya 30 years ago. 'I can buy our daily food out of what I earn, and that's all,' she told me as we sat in the shade of her bustling alley. 'I don't feel famous. It's only that my problems push me to do sex work. If I could find something else, I would.'

· This is an extract from Twenty-Eight: Stories of Aids in Africa by Stephanie Nolen, published by Portobello Books on 28 May. To order a copy at £11.99 with free UK p&p, call 0870 836 0885, or visit observer.co.uk/bookshop