Commit graph

21 commits

Author SHA1 Message Date
Vegard Stikbakke
8bdcd4498a fix(coding-agent): compact oversized trailing tool results
Fall back to the latest safe assistant boundary when trailing tool results exceed the retained-token budget, allowing older history to compact before the next provider request.

Closes #9740
2026-09-18 13:38:30 +02:00
Armin Ronacher
9e05370b29
Mid conversation system messages (#9548)
This change makes system prompt text and tool changes part of the transcript rather than silently rewriting its starting conditions. This lets Pi record when instructions changed or tools became available, restore that state after resuming or navigating branches, and preserve cached prompt prefixes where the upstream supports it.
2026-09-16 15:54:07 +02:00
Vegard Stikbakke
46bde88a1c feat(coding-agent): support per-model compaction token budgets
Closes #8133
2026-09-10 08:37:20 +02:00
David Brailovsky
bea67d90d1 fix(coding-agent): cancel compaction on session abort
Include compaction and branch summarization in session idle tracking so abort waits for cancellation to settle.\n\nfixes #8920
2026-09-03 09:41:55 +02:00
David Brailovsky
56700d42ed
fix(coding-agent): compact before post-tool model requests (#8782)
Run next-turn preparation only when the agent loop continues, allowing threshold compaction before the next provider request. Restore interactive progress when the same run resumes.

Closes #6879

Important to notice:
this changes when prepareNextTurn & prepareNextTurnWithContext are invoked:
the now run only when a next turn actually happens, and after shouldStopAfterTurn.
2026-08-28 13:40:59 +02:00
Vegard Stikbakke
ef8dc7385b feat(coding-agent): centralize compaction summary requests 2026-08-18 14:19:01 +02:00
Cristina Poncela Cubeiro
a6b1dbceb1
fix(extensions): emit compaction failed for extensions (#8241)
* fix(extensions): emit compaction failed

* changelog yeet
2026-08-17 13:10:08 +02:00
Vegard Stikbakke
c7c763f5c4 fix(coding-agent): clarify truncated recovery failure
closes #8130
2026-08-17 11:03:07 +02:00
Armin Ronacher
3852cb2b81 fix(coding-agent): send prompts queued during compaction 2026-08-05 21:20:44 +02:00
David Brailovsky
32850ef7c5
fix(coding-agent): resume after context-limited length stops (#7540)
* fix(coding-agent): resume after context-limited length stops

Treat length stops as context overflow when prompt usage is within 1% of
Pi's configured context window. Include cache-write tokens in that usage
and allow non-zero output because OpenAI may emit reasoning tokens before
returning an incomplete response.

After compaction, remove any retryable error or truncated-length assistant
message restored from persisted session history so the interrupted agent
turn can continue.

This is specifically for handling this case for openai models:
https://developers.openai.com/api/docs/guides/reasoning

> If the generated tokens reach the context window limit or the max_output_tokens value you’ve set, you’ll receive a response with a status of incomplete and incomplete_details with reason set to max_output_tokens. This might occur before any visible output tokens are produced, meaning you could incur costs for input and reasoning tokens without receiving a visible response.

This detection currently assumes the reported prompt usage is within 1% of
the context window configured in Pi. Its reliability therefore depends on
Pi's model contextWindow metadata matching the provider's effective limit.

Maybe we should consider treating OpenAI incomplete responses as requiring compaction
regardless of the local context-window estimate?

fixes #7020

* fix(coding-agent): recover truncated responses after compaction

Classify length stops by comparing provider-reported output usage with the model's intended output limit. Compact and retry once when generation ends below that limit, avoiding unreliable context-window estimates while preserving genuine max-output stops.

Normalize OpenAI Responses incomplete reasons so only max_output_tokens is treated as a length stop. Preserve qualified provider reasons for diagnostics, surface other reasons as errors, and use neutral truncation wording in the TUI.
2026-08-03 18:07:53 +02:00
Armin Ronacher
24e5cc04f4
fix(ai): support Anthropic bearer token env (#6148)
Fixes #5871
2026-07-24 15:13:22 +02:00
Mario Zechner
1235c0ec64 fix(agent): decouple agent streams from compat
closes #6851
2026-07-20 17:54:36 +02:00
David Brailovsky
2fd3868401
add usage info to branch summary, compaction and tool result entries (#6671)
* add usage info to branch summary entries

* add usage to compaction entries

* allow custom tools to report llm usage in tool results

* allow observing and patching usage in tool_result hooks

* agent-harness: save usage in entries

for compaction, branch summaries and tool results
2026-07-20 16:41:43 +02:00
Armin Ronacher
c60f6a8ab3 feat(coding-agent): expose post-compaction token estimates
closes #5877
2026-06-18 23:01:10 +02:00
Armin Ronacher
7d08c81a09 fix(coding-agent): avoid empty compaction summaries
closes #4811
2026-06-18 22:17:57 +02:00
Armin Ronacher
6b9f3f492f fix(coding-agent): avoid retrying successful overflow compaction
closes #5720
2026-06-18 19:30:14 +02:00
Mario Zechner
2e02c74dcb chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
Mario Zechner
32bcdc9739 fix(coding-agent): simplify agent session settlement 2026-05-19 09:53:20 +02:00
Armin Ronacher
35f807cfaf fix(coding-agent): route compaction through streamFn
closes #4484
2026-05-17 01:57:03 +02:00
Mario Zechner
3e5ad67e0f chore: migrate pi packages to earendil works scope 2026-05-07 15:59:42 +02:00
Mario Zechner
746f770b10 test(coding-agent): add session lifecycle characterization suite 2026-04-01 22:59:49 +02:00