Acontext
FeaturesContext Engineering

Session Summary

Compact task summary for prompts

Get a token-efficient summary of session tasks for prompt injection.

Usage

import os
from acontext import AcontextClient

client = AcontextClient(api_key=os.getenv("ACONTEXT_API_KEY"))

# Ensure all messages have been processed
client.sessions.flush(session_id)

summary = client.sessions.get_session_summary(session_id)

system_prompt = f"""You are a helpful assistant.

Previous tasks:
{summary}

Continue helping the user.
"""
import { AcontextClient } from '@acontext/acontext';

const client = new AcontextClient({
    apiKey: process.env.ACONTEXT_API_KEY,
});

// Ensure all messages have been processed
await client.sessions.flush(sessionId);

const summary = await client.sessions.getSessionSummary(sessionId);

const systemPrompt = `You are a helpful assistant.

Previous tasks:
${summary}

Continue helping the user.
`;

Output Format

<task id="1" description="Search for iPhone 15 news">
<progress>
1. Searched and found key specs
2. Compiled feature comparison
</progress>
<user_preference>
1. Focus on camera capabilities
</user_preference>
</task>

Options

client.sessions.flush(session_id)
# Limit to last 5 tasks
summary = client.sessions.get_session_summary(session_id, limit=5)
await client.sessions.flush(sessionId);
// Limit to last 5 tasks
const summary = await client.sessions.getSessionSummary(sessionId, { limit: 5 });

Task extraction is async and may lag 1-6 messages. Keep the 4-6 most recent messages in full when using summary as compression.

Next Steps

Last updated on

On this page