Over time the ants have acquired a series of triggers and actions that have (apparently) made them more fit to survive.
They don't necessarily understand that for example that planting and fertilizing seeds will yield a safe place to live, they are just driven to take those actions when they encounter whatever trigger those seeds activate in them.
For example when an ant dies it puts off oleic acid and when others pick up on this scent they cart if off to a "burial" site.
However the ants don't understand death. If you coat a live ant with oleic acid the ants will carry it off even as it resists and tries to clean itself and dump it in the dead pile.
Collective intelligence is a strange concept to work with because the ant isn't really the animal, the animal is the colony.
Even still I don't know that the colony "understands" what is happening, it just feels a collective drive to take the actions.
Don't get me wrong, it's quite impressive.
Still, considering how fastidious ants are about cleaning in and around their nests* it's quite feasible one or more colonies might take to disposing of seeds in a way that lets the seeds grow and/or pick up on the habit of dumping waste products on the seedlings which the plants then use as fertilizer.
One thing that shouldn't be ignored is that it could work the other way as well. Maybe a seed was made one day that carried chemicals which caused the ants to plant it and/or poop on it.
There's evidence of this sort of thing with moths whose young emit chemicals causing the ants to carry them back to the nest and feed them until they reach adulthood and fly off.
And there's the infamous "zombie ant" fungus.
Again, the ants probably don't "know" or "care" in any intellectual sense whether it will work, it's simply an idiosyncrasy they picked up. I imagine there are plenty of strange activities ants are evolving to pick up right now that will or wont work to make them more fit to survive.
* The next time you see an ant hill note how well maintained and free of surrounding debris it is.
They don't think in terms of "this is stinky/dead", more like "this smells like oleic acid so it goes over there."
FWIW this was tested by putting oleic acid on bits of paper: https://pdfs.semanticscholar.org/6400/112aff930da566312315ef...
They would sometimes carry it to the burial site and other times they would carry it back and treat it as a food item. The "decision" is said to be based on the current "social context" (read: goals of the ant or colony).
Also a note on that poor ant they coated with the stuff; she cleaned herself off and was back to work after an hour or two.