P
Peekr Cloud
DemoAcme Agents

← Traces

agent.run

trace_id: trace_00006k · tenant: soylent

4 spans·4411msok

Context growing unboundedly: 69 → 393 tokens across 3 calls

Input token counts are climbing with each LLM call in this trace (69 → 289 → 393). 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 › run

agent.run

user: u_105
anthropic › messages › create

anthropic.messages.create

claude-opus-4-7271 tok$0.011faithful 0.99user: u_105
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-7695 tok$0.027faithful 0.24user: u_105
Input

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

Output

Refund approved under policy P-204(b), $189.99 returned to card ending 4421 within 3 days…

anthropic › messages › create

anthropic.messages.create

claude-opus-4-7441 tok$0.017faithful 0.51user: u_105
Input

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

Output

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

Faithfulness · anthropic.messages.create0.25

1 supported · 2 contradicted · 1 unsupported of 4 claims

  • contradicted

    Q3 revenue was $4.2B.

  • contradicted

    YoY growth was 38%.

  • unsupported

    Operating margin expanded to 27%.

  • supported

    Net income grew faster than revenue.