Your question is deceptively simple. But jamming takes years to master. For a deep answer to this question I suggest that you get the 900 page "Thinking in Jazz: The Infinite Art of Improvisation" by Paul F Berliner.
To quote from the site:
A landmark in jazz studies, Thinking in Jazz reveals as never before
how musicians, both individually and collectively, learn to improvise.
Chronicling leading musicians from their first encounters with jazz to
the development of a unique improvisatory voice, Paul Berliner
documents the lifetime of preparation that lies behind the skilled
improviser’s every idea.
The product of more than fifteen years of immersion in the jazz world,
Thinking in Jazz combines participant observation with detailed
musicological analysis, the author’s experience as a jazz trumpeter,
interpretations of published material by scholars and performers, and,
above all, original data from interviews with more than fifty
Thinking in Jazz overflows with musical examples from the 1920s to the
present, including original transcriptions (keyed to commercial
recordings) of collective improvisations by Miles Davis’s and John
Coltrane’s groups. These transcriptions provide additional insight
into the structure and creativity of jazz improvisation and represent
a remarkable resource for jazz musicians as well as students and
Berliner explores the alternative ways—aural, visual, kinetic, verbal,
emotional, theoretical, associative—in which these performers
conceptualize their music and describes the delicate interplay of
soloist and ensemble in collective improvisation. Berliner’s skillful
integration of data concerning musical development, the rigorous
practice and thought artists devote to jazz outside of performance,
and the complexities of composing in the moment leads to a new
understanding of jazz improvisation as a language, an aesthetic, and a
Too much? Then the other answer is just one word: listen. You are absolutely correct in comparing improvisation to a musical conversation. Jazz musicians tend to use chord progressions as the common ground upon which they base their conversations--one notable exception being Bill Frisell, who uses the melody ("head"). I like to say that music is the only conversation that gets better when everybody talks and listens at once.
Chord progressions start with the lead sheets and a common jamming trope is to trade solos, 4s (four bar sections) or 8s (eight bar sections). Reharmonization of the bare-bones lead sheet chord progressions is something that the rhythm section negotiate among themselves.
If notes or chords clash more-experienced musicians will correct on the fly. Less-experienced musicians may have to stop and discuss.
Like playing guitar, you can get the bare basics in a few months but you will spend the rest of your life trying to master it.