Urgent.News

What's breaking now, across thousands of outlets.

AI

Build a Basic AI Agent From Scratch: Session Management II

Previous parts of Build a Basic AI Agent From Scratch : Basic Agent Tools Long Task Planning Human in the Loop & Security Security II Security III Memory Session Management You can find and clone this code in this blog series' GitHub repo . In the previous part we gave our agent sessions. It can save a conversation, list and search saved sessions, resume an unfinished one, and recover a tool call…

Session compaction is a mechanism designed to help AI agents manage large conversation contexts. Unlike session summaries used in session lists, compaction summaries become the working context for the agent to continue the current session without carrying the entire conversation history. Compaction is performed before each regular model request when the estimated message tokens exceed 80% of the --max-context-tokens limit. The default context window budget is 24000 tokens, so compaction starts after roughly 19200 tokens.

To ensure a safe split point, the agent chooses the latest user-turn boundary before reaching the token limit. It keeps the system prompt and everything from the latest user message onward, including current turn assistant messages and complete tool batches. Only older turns are summarized. If there are no older turns, no compaction is done.

The compaction summary itself is generated by an additional LLM call with a specific system prompt. It summarizes conversation data, preserving goals, constraints, decisions, modified files, verification, unresolved tasks, and errors. The summary is a concise factual continuation note and is not included in the system message to prevent prompt-injection issues.

Instead, a user data message with an explicit boundary is used to store the continuation message. If the summary is empty or makes the context bigger than before, it is rejected.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in AI

I Matched 10,000 People to Loans. It Took Just 1 AI Call.

Here's a problem that sounds simple: "I have a spreadsheet of 10,000 people. Tell each of them which personal loans they might actually get." Then you start asking questions, and it stops being…

  • Developed Loan Match to simplify loan assignment for 10,000 individuals.
  • System accesses 15 lenders' websites daily to determine eligibility.
  • Built on AWS services with data integrity checks and redundancy measures.

More from Saturday 24 October →