P
Peekr Cloud
DemoAcme Agents

← Traces

agent.run

trace_id: trace_00004g · tenant: acme

5 spans·5337msok

Context growing unboundedly: 151 → 231 tokens across 3 calls

Input token counts are climbing with each LLM call in this trace (151 → 49 → 231). 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_heavy_44
openai › chat › completions › create

openai.chat.completions.create

gpt-4-mini227 tok0.01¢faithful 0.77user: u_heavy_44
Input

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

Output

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

openai › chat › completions › create

openai.chat.completions.create

gpt-4-mini136 tok0.00¢faithful 0.92user: u_heavy_44
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…)

openai › chat › completions › create

openai.chat.completions.create

gpt-4-mini266 tok0.01¢faithful 0.97user: u_heavy_44
Input

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

Output

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

Tool: web_fetch

tool.web_fetch

user: u_heavy_44

Faithfulness · openai.chat.completions.create0.50

1 supported · 0 contradicted · 1 unsupported of 2 claims

  • unsupported

    All chapters were translated.

  • supported

    Tables were preserved in the output.

Faithfulness · openai.chat.completions.create0.33

1 supported · 2 contradicted · 0 unsupported of 3 claims

  • contradicted

    Globex Logistics is the lowest-cost vendor for SKU 88-A.

  • contradicted

    The quoted unit price is $14.20.

  • supported

    Delivery date is 2026-06-28.