liveBook · Manning

Session

As explained in Context Engineering

An ongoing interaction between a user and an assistant.

A session is an ongoing interaction between a user and an agent. Because each LLM call is independent, the application replays a curated view of the session—its turns and the agent’s actions—to maintain continuity. Session state lives outside the model and ends when the interaction ends. section 1.5.4

A session is short-term memory, not a store for information that should persist across conversations. Long-term memory keeps useful information across sessions and supplies only matching entries when retrieved. Within a session, a curation policy decides what history survives each turn; the full transcript need not enter the context window. section 5.5.3 section 1.5.4

A session can curate history in several ways:

  • Retain only the last N user turns verbatim for predictable context size. section 5.5.3
  • Prepend a running summary of older interactions to preserve continuity across longer exchanges. section 5.5.3

A preference carried forward

If a user says they prefer evening flights, the agent can apply that preference several turns later in the same session by replaying the relevant curated history. section 1.5.4

Listing 5.4 Illustrative Python excerpt showing a custom session that curates short-term memory before each agent run
from agents import Agent, Runner
from agents.memory.session import SessionABC
from collections import deque
from typing import List

class SummarizingSession(SessionABC): #1
    def _materialize(self):
        trimmed = self._trim_to_last_turns(list(self._items)) #2
        if self._summary:
            summary_msg = { #3
                "type": "message",
                "role": "assistant",
                "content": f"Running summary:\n{self._summary}",
            }
            return [summary_msg] + trimmed
        return trimmed

    async def _refresh_summary_locked(self): #4
        prompt = f"Update the summary with older history:\n{drop_text}"
        result = await Runner.run(summarizer, prompt)
        self._summary = (result.final_output or "").strip()

agent = Agent(name="Support", model="gpt-5",
              instructions="Troubleshoot step-by-step.")
session = SummarizingSession("support_demo", max_turns=6) #5
result = await Runner.run(agent, user_input, session=session) #6

Illustrates a custom OpenAI Agents SDK session that trims turns, prepends a summary when available, and refreshes that summary. The excerpt is schematic, not runnable as printed. section 5.5.3

How Context Engineering covers it

How deep it goes
Explains last-turn trimming and summary-based curation, while leaving implementation plumbing aside.
Examples
Uses an evening-flight preference across turns and illustrates last-N-turn retention with a running summary.
What it assumes
Assumes agent calls and context windows, while explaining how replayed history gives stateless calls continuity.
What you can do after
Apply the OpenAI Agents SDK Session abstraction with deterministic trimming or summary-based compression.
How it connects
Connects short-term memory to LLM statelessness, context windows, and long-term memory.

Also explained in

Compare how 9 books explain session →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Context Engineering. The section links point to the parts of the book it draws on.