P
Peekr Cloud
DemoAcme Agents

← Traces

agent.plan

trace_id: trace_000032 · tenant: acme

5 spans·3544msok

Context growing unboundedly: 846 → 1482 tokens across 3 calls

Input token counts are climbing with each LLM call in this trace (846 → 2649 → 1482). This is the unbounded conversation history pattern — cost and latency grow O(N²) as the session continues. At this rate, long sessions will become expensive and slow.

Fix: trim context with a rolling window or summarisation

fix.py
# Option 1: rolling window — keep only the last N messages
MAX_MESSAGES = 10
messages = messages[-MAX_MESSAGES:]

# Option 2: summarise when context exceeds a threshold
def trim_context(messages, max_tokens=3000):
    total = count_tokens(messages)
    if total <= max_tokens:
        return messages
    # Summarise the oldest half, keep the recent half verbatim
    old = messages[:-5]
    recent = messages[-5:]
    summary = llm.summarise(old)
    return [{"role": "system", "content": f"Earlier context: {summary}"}] + recent

Waterfall

agent › plan

agent.plan

user: u_heavy_12
anthropic › messages › create

anthropic.messages.create

claude-opus-4-7866 tok$0.034faithful 0.90user: u_heavy_12
Input

Summarize the Q3 earnings report attached. Focus on revenue, margin, and guidance.

Output

(answer to: Summarize the Q3 earnings report attache…)

anthropic › messages › create

anthropic.messages.create

claude-opus-4-73.2k tok$0.124faithful 0.97user: u_heavy_12
Input

Given the customer ticket below, draft a refund response that follows policy P-204.

Output

(answer to: Given the customer ticket below, draft a…)

anthropic › messages › create

anthropic.messages.create

claude-opus-4-72.3k tok$0.089faithful 0.98user: u_heavy_12
Input

Translate the user manual section to Japanese, preserving the table structure.

Output

(answer to: Translate the user manual section to Jap…)

Tool: calculator

tool.calculator

user: u_heavy_12

Faithfulness · anthropic.messages.create0.50

2 supported · 1 contradicted · 1 unsupported of 4 claims

  • supported

    Policy P-204(b) applies to this request.

  • contradicted

    The refund amount is $189.99.

  • unsupported

    The card on file ends in 4421.

  • supported

    Refunds settle within 3 business days.