Skip to content

FE-1986: Add a Draft message with AI flow action - #10099

Open
kostandinang wants to merge 4 commits into
kostandin/fe-1985-add-create-entity-and-update-entity-flow-actionsfrom
kostandin/fe-1986-add-a-draft-message-with-ai-flow-action
Open

kostandinang wants to merge 4 commits into
kostandin/fe-1985-add-create-entity-and-update-entity-flow-actionsfrom
kostandin/fe-1986-add-a-draft-message-with-ai-flow-action

Conversation

@kostandinang

@kostandinang kostandinang commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🌟 Purpose

Adds Draft Message: an AI-written email-style subject and plain-text body for a later step to send or a person to review. Nothing is sent. It builds on Query (#10050) and Create/Update entity (#10060).

  • Inputs: instructions (required), context (Text, e.g. from Read Entity), entities (Query Entities' list, or a for-each item with wrap: true).
  • Outputs: subject (one line) and body (plain text).
  • Reads entities as the running user, in the run's web, honouring draft IDs.

🔍 Changes

Where What
flow-activities/draft-message-action.ts The activity. Start here.
flows/action-definitions.ts, flows/limits.ts draftMessage and its 20-entity limit.
flow-activities.ts Registration.

🤔 Decisions to review

  • Claude Haiku 4.5, temperature 0: cheap and consistent for per-entity drafting. Haiku 5.5 is the intended successor once it's allowed in the worker.
  • A forced submitDraft tool for output only: no lookups, code or sandbox.
  • Fail, never omit: over 20 entities, missing, unreadable, other-web or link entities, empty instructions, or a prompt over 400,000 characters fail before any model call.
  • Entities via getSimpleGraph, without links. The prompt treats context and entities as data, not instructions.
  • Up to 3 calls for a missing or empty draft, each saying what was wrong, then fail with no outputs.
  • Bounded to the 5-minute timeout: drafts are capped at 2,000 tokens, and no attempt starts after 2 minutes.
  • Errors: an off-schema or over-long draft fails the step. Provider errors are thrown for Temporal to retry.

⚠️ Known issues

  • No templating, and no Send email action yet.
  • Same-titled properties on different types share a key.
  • A model refusal fails with an unclear error, as the shared Anthropic code throws on it.

🔀 Merge order

Stacked on #10060. Retarget to main after it merges, rebasing if squashed.

🛡 Tests

  • Mocked model and graph: every input shape, all limits on both sides, each failure above, retries that succeed or run out, the time budget, and a multi-line subject.
  • Lint, types and unit tests pass. Not run against the real model or end to end.

@vercel

vercel Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hash Ready Ready Preview Oct 20, 2026 11:18am UTC
petrinaut Ready Ready Preview Oct 20, 2026 11:18am UTC
2 Skipped Deployments
Project Deployment Actions Updated
hashdotdesign-tokens Ignored Ignored Preview Oct 20, 2026 11:18am UTC
petrinaut-docs Skipped Skipped Oct 20, 2026 11:18am UTC

Request Review

@vercel
vercel Bot temporarily deployed to Preview – petrinaut-docs October 19, 2026 17:05 Inactive
@github-actions github-actions Bot added area/apps > hash* Affects HASH (a `hash-*` app) area/libs Relates to first-party libraries/crates/packages (area) type/eng > backend Owned by the @backend team area/apps labels Oct 19, 2026
@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.65432% with 10 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (kostandin/fe-1985-add-create-entity-and-update-entity-flow-actions@3cefbe9). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...activities/flow-activities/draft-message-action.ts 87.50% 5 Missing and 5 partials ⚠️
Additional details and impacted files
@@                                          Coverage Diff                                          @@
##             kostandin/fe-1985-add-create-entity-and-update-entity-flow-actions   #10099   +/-   ##
=====================================================================================================
  Coverage                                                                      ?   68.07%           
=====================================================================================================
  Files                                                                         ?     2012           
  Lines                                                                         ?   206478           
  Branches                                                                      ?     8869           
=====================================================================================================
  Hits                                                                          ?   140555           
  Misses                                                                        ?    64242           
  Partials                                                                      ?     1681           
Flag Coverage Δ
apps.hash-ai-worker-ts 9.78% <87.50%> (?)
apps.hash-api 15.59% <ø> (?)
local.hash-backend-utils 6.21% <ø> (?)
local.hash-isomorphic-utils 33.06% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vercel
vercel Bot temporarily deployed to Preview – petrinaut-docs October 20, 2026 07:29 Inactive
@vercel
vercel Bot temporarily deployed to Preview – petrinaut October 20, 2026 07:29 Inactive
@kostandinang
kostandinang added this pull request to stack #10055 October 20, 2026 07:30
@kostandinang
kostandinang requested a review from CiaranMn October 20, 2026 07:36
@kostandinang
kostandinang marked this pull request as ready for review October 20, 2026 07:36
@kostandinang
kostandinang requested a review from a team as a code owner October 20, 2026 07:36
@cursor

cursor Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
New LLM-backed flow step reads user-accessible entity data and enforces strict validation, but it does not send messages and follows existing flow activity patterns.

Overview
Adds a new draftMessage AI flow action that produces a one-line subject and plain-text body from required instructions, optional context text, and up to 20 in-web entities (read via the graph as the running user, including draft editions). Nothing is sent.

The worker activity calls Claude Haiku with a forced submitDraft tool, validates inputs strictly (empty instructions, wrong web, missing/unreadable/link entities, prompt > 400k chars) before any LLM or graph work, normalizes subjects to a single line, and retries up to three times within a two-minute budget when the draft is missing or empty. draftMessage is registered in flow activities; maxDraftMessageEntities (20) and the action schema live in isomorphic flow definitions. Unit tests cover limits, failures, retries, and timeouts with mocked LLM/graph.

Reviewed by Cursor Bugbot for commit a4b9ade. Bugbot is set up for automated code reviews on this repo. Configure here.

kostandinang and others added 4 commits October 20, 2026 13:04
Drafts a subject and a plain-text body from instructions, optional context
text, and the properties of up to 20 entities in the flow's web, read as the
user running the flow. A stored list of entity IDs and a wrapped for-each item
both work. More than 20 entities, or one that is missing or unreadable, fails
the step before the model is called.

The model (Claude Haiku 4.5, at temperature 0) must submit the draft through a
submitDraft tool. A missing draft or an empty subject or body is asked for
again, up to 3 calls, then fails the step with no outputs.

Co-authored-by: Amp <[email protected]>
Empty instructions fail the step, as does a prompt longer than 400,000
characters (about 100,000 tokens), rather than being cut short. Each draft is
limited to 2,000 tokens, and no attempt starts more than 2 minutes after the
first, so the step finishes within the 5 minutes an action that doesn't
heartbeat has.

Co-authored-by: Amp <[email protected]>
…ext isn't instructions

A line break in a subject could add headers to an email sent from it, so
whitespace in the subject is collapsed to single spaces. The system prompt
now says the context and entities are data to draw on, so instructions in
an entity's properties aren't followed.

Co-authored-by: Amp <[email protected]>
@kostandinang
kostandinang removed this pull request from stack #10055 October 20, 2026 11:07
@kostandinang
kostandinang force-pushed the kostandin/fe-1986-add-a-draft-message-with-ai-flow-action branch from b9b6cc6 to a4b9ade Compare October 20, 2026 11:07
@vercel
vercel Bot temporarily deployed to Preview – petrinaut-docs October 20, 2026 11:07 Inactive
@kostandinang
kostandinang added this pull request to stack #10120 October 20, 2026 11:07

This branch was successfully deployed

3 active and 1 inactive deployments
Preview – hash — a4b9ade3 Deployed Oct 20, 2026 by vercel[bot]
Preview – petrinaut — a4b9ade3 Deployed Oct 20, 2026 by vercel[bot]
pull-request — a4b9ade3 Deployed Oct 20, 2026 by kostandinang via Sourcemaps (@apps/hash-ai-worker-ts) #40600
Preview – petrinaut-docs — a4b9ade3 Deployed Oct 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/apps > hash* Affects HASH (a `hash-*` app) area/apps area/libs Relates to first-party libraries/crates/packages (area) type/eng > backend Owned by the @backend team

Development

Successfully merging this pull request may close these issues.

1 participant