mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-10-26 02:04:37 +08:00
Multi-turn agent conversations rebuilt history as plain text, dropping all tool calls and results. Later turns could not see what the model had actually retrieved, so it imitated tool-free answers and hallucinated chat records instead of re-querying (worse after incremental imports and in long conversations). - Persist provider-issued toolCallId, truncated result text and isError on tool content blocks (written by the shared frontend store from stream chunks; pi-agent-core events already carry these fields) - Replay persisted tool blocks as real toolCall/toolResult message pairs in toPiHistoryMessages: stable ids keep requests byte-identical across turns (prompt cache friendly), unfinished blocks are skipped so no toolCall is left unanswered, errors map to isError, results are capped at 4000 chars, runtime-injected underscore params are stripped - Legacy messages without persisted tool data fall back to the old plain-text replay; no migration needed Verified on a real CLI web session: 25+ replayed tool pairs accepted by the provider across turns with zero API errors. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>