Language-model API calls are stateless: each call sees only the messages sent with it. Conversation continuity therefore depends on retaining prior messages and resending them with each request. section 2.2.4
For a basic exchange, append user messages and assistant replies to a messages list, then send the accumulated list on the next call. Agents may also need to retain tool results, search results, and intermediate reasoning. As history grows, token use, cost, and response time grow too. section 2.2.4 section 2.2.4
Across separate agent runs, store history in a session and retrieve it using the same session ID. A session can also preserve execution state; a session manager loads or creates it before a run and saves it afterward. section 6.3.3 section 6.3
Listing 2.6 Managing conversation history
from litellm import completion
messages = []
# First exchange
messages.append({"role": "user", "content": "My name is Jungjun."})
response1 = completion(model="gpt-5-mini", messages=messages)
assistant_message1 = response1.choices[0].message.content
messages.append({"role": "assistant", "content": assistant_message1})
print(assistant_message1)
# Second exchange - includes previous conversation history
messages.append({"role": "user", "content": "What is my name?"})
response2 = completion(model="gpt-5-mini", messages=messages)
assistant_message2 = response2.choices[0].message.content
print(assistant_message2)
Trace how user and assistant messages accumulate and are resent to maintain continuity. section 2.2.4
# Maintaining conversation continuity with the same session_id
result1 = await agent.run("My name is Alice", session_id="session_1")
# → "Nice to meet you, Alice!"
result2 = await agent.run("What's my name?", session_id="session_1")
# → "Your name is Alice."
See how reusing a session ID carries a name from one agent run into the next. section 6.3









