Repository source: docs/plans/post_summary_thread_context_agent_reply_plan_v1.md
Post Summary and Thread Context for Agent Replies Plan V1
Goal
Add a neutral one-sentence post_summary to stored post analysis, then use each thread comment's post_summary and full body text as context when deciding/generated agent replies.
Current State
Post analysis returns exactly four top-level keys:
engagement,moderation,quality, andrespondability.The only existing summary is
moderation.summary, which is moderation-specific and should not be reused as a neutral content summary./api/generate_agent_replycurrently does not make a second model call. It postsanalysis.engagement.suggested_responsefrom the existing post analysis result.The current analysis context includes the target post body, thread root subject/body preview, and immediate parent body preview, but not all comments in the thread.
Thread posts are already fetchable in sequence order through
fetchThreadPosts().
Assumptions
post_summaryshould be a top-level analysis field, not nested under moderation.post_summaryshould be one sentence, neutral, ASCII-only, and about the content of the post rather than moderation or reply-worthiness.The reply-generation context should include all comments in the target thread in chronological/thread sequence order.
Each thread comment context entry should include at least
post_id,parent_id,author_label,created_at,post_summary, and fullbody.For comments without a completed current-schema analysis,
post_summaryshould be empty rather than blocking reply generation.Full comment text should still be capped by a conservative per-comment and total-context budget to avoid unbounded prompt growth.
Implementation Plan
Update the post analysis schema and prompt.
Add top-level
post_summarytoprompts/dedalus_post_analysis_system.txt.Update
DedalusPostAnalyzer::responseSchema()to require a top-levelpost_summarystring.Update
DedalusPostAnalyzer::analyze()to returnpost_summaryalongside the existing analysis sections.Update tests that construct expected analysis payloads.
Persist and hydrate
post_summary.Add a
post_summarycolumn topost_analyses.Extend
SqlitePostAnalysisStore::ensureSchema()with anALTER TABLEmigration for existing SQLite databases.Save and hydrate
post_summaryin complete analysis rows.Keep failed/config-missing analysis rows without a summary.
Bump the analysis schema version.
Change
analysis_schema_versionfrom2to3inApplication::postAnalysisContext().This changes the content hash, preventing old cached analyses from being treated as complete for the new response shape.
Display the neutral summary in Post analysis.
Add
Post summary:near the top of the<details class="post-analysis">panel.Keep the existing moderation
Summary:field but relabel it if needed to avoid ambiguity, for exampleModeration summary:.
Build full-thread reply context.
Add an application helper that builds
thread_commentsfor a target post.Fetch all posts in the thread with
fetchThreadPosts($threadId).For each comment, compute its current analysis content hash and look up the stored analysis.
Include the hydrated
post_summaryif present, plus full body text capped through a new limit helper.Include metadata that lets the model distinguish the target post, parent post, root post, and existing reply-agent posts.
Use thread context for generated replies.
Because reply generation currently posts
analysis.engagement.suggested_response, update the analysis context before the initial analysis call so suggested responses can use all thread comments.Also add
thread_commentsto$generationContextstored inpost_generated_responses, so the persisted generation record shows the context used.If we later re-enable
DedalusAgentReplyGenerator::generate(), pass the samethread_commentscontext into that model call too.
Gate context size.
Add per-comment body truncation for reply context, separate from post-analysis target body truncation.
Add a total thread comment budget so very large threads do not create oversized requests.
Prefer preserving the target post, root post, parent post, and latest comments if truncation is necessary.
Verification.
Update
DedalusPostAnalyzerTestfor the new top-levelpost_summaryshape.Add or update store tests to confirm
post_summarypersists and hydrates.Add an application-level test that reply/analysis context for a thread includes multiple comments with summaries and body text.
Run
php tests/run.php.
Implementation Progress
Baseline committed in
fa4e313with the reviewed plan.Slice 1: complete - added
post_summaryto the Dedalus post-analysis prompt/schema and direct analyzer tests. Verification:php tests/run.php.Slice 2: complete - persisted and hydrated
post_summaryin SQLite analysis storage, including migration coverage and stub analyzer output. Verification:php tests/run.php.Slice 3: complete - bumped analysis schema version to 3 and displayed
post_summaryin approved API/page analysis output with separate moderation summary labeling. Verification:php tests/run.php.Slice 4: complete - added bounded full-thread
thread_commentscontext to post analysis/generation inputs and persisted generated-response request context for auditing. Verification:php tests/run.php.
Open Decisions
Resolved: thread comment context uses 3000 chars per comment and 18000 chars total.
Resolved: the UI uses
Post summaryfor the neutral content summary andModeration summaryfor moderation-specific text.Resolved: missing per-comment summaries remain empty; reply generation does not cascade provider calls to analyze missing comments.