Skip to content

feat: attach AI reasoning as a comment on approval requests#1733

Merged
Scra3 merged 3 commits into
mainfrom
feat/ai-approval-request-message
Jul 3, 2026
Merged

feat: attach AI reasoning as a comment on approval requests#1733
Scra3 merged 3 commits into
mainfrom
feat/ai-approval-request-message

Conversation

@Scra3

@Scra3 Scra3 commented Jul 3, 2026

Copy link
Copy Markdown
Member

Context

When an AI triggers a custom action that requires approval — via the MCP executeAction tool or the workflow-executor trigger-action step — the created approval request carried no explanation. The approver saw a bare request with no idea why the AI triggered it.

This PR lets the AI attach its reasoning, surfaced as a comment on the approval request.

Why a comment (not an attribute)

Checked the Forest server (forestadmin-server): POST /api/action-approvals only validates status / action_name / collection_name / record_ids / inputs — any extra attribute is dropped, and the actionApproval model has no message field. The free-text channel is the dedicated actionApprovalComment resource (POST /api/action-approvals/:id/comments, data.attributes.comment), same auth stack as creation. So the message is posted there.

Changes

  • agent-client
    • Action.execute(signedApprovalRequest?, approvalRequestMessage?) forwards an optional message.
    • makeCreateApprovalRequest posts the message to /api/action-approvals/:id/comments after the approval is created — best-effort: a comment failure never turns the successful approval into an error.
  • mcp-serverexecuteAction exposes an optional reasoning field (LLM-facing description asks it to always explain why), forwarded to execute(). Covers direct MCP use and the workflow mcp step.
  • workflow-executor — the trigger-action step captures the AI action-selection reasoning (previously discarded in selectAction), falling back to the step prompt for pre-recorded actions, and threads it through ExecuteActionQuery.approvalMessage. Reasoning stays out of StepOutcome (privacy invariant preserved).

Tests

  • agent-client: comment posted with correct path/body; skipped when no approval id; approval id still returned when the comment POST fails.
  • mcp-server: reasoning forwarded to execute().
  • workflow-executor: approvalMessage transmitted to the port; AI reasoning captured; prompt fallback for pre-recorded actions.

All suites green (agent-client 344, mcp-server 548, workflow-executor 1155), builds + lint clean.

Verification

Verified end-to-end against a local agent + Forest server: triggering the approval-gated Create new card action via MCP with a reasoning creates the approval request with the reasoning shown as a comment in the front. 🤖 Generated with Claude Code

Note

Attach AI reasoning as a comment on approval requests

  • When an action requires approval, the AI's reasoning (or the step prompt as a fallback) is now posted as a comment on the created approval request.
  • Action.execute in action.ts now accepts an options object with an optional approvalRequestMessage; after creating the approval request, a follow-up POST is made to /api/action-approvals/{id}/comments.
  • The MCP executeAction tool gains an optional reasoning input field that is forwarded through to the approval request comment.
  • The TriggerRecordActionStepExecutor derives the approval message from the AI selection's reasoning, falling back to the step prompt, and omits the message if neither is available.
  • Risk: comment posting is best-effort — failures are swallowed with console.warn and do not affect the approval request result. Callers previously passing a bare signedApprovalRequest to Action.execute must now wrap it in an options object.

Macroscope summarized 787b9be.

…ests

When an AI triggers an approval-gated custom action (via the MCP executeAction
tool or the workflow-executor trigger-action step), the created approval request
now carries the AI's reasoning as a comment so the approver understands why it
was triggered.

- agent-client: Action.execute() accepts an optional message; the approval
  request creator posts it to /api/action-approvals/:id/comments (best-effort).
- mcp-server: executeAction exposes an optional `reasoning` field forwarded to
  the approval request.
- workflow-executor: the trigger-action step captures the AI action-selection
  reasoning (previously discarded), falling back to the step prompt, and threads
  it through as approvalMessage.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@qltysh

qltysh Bot commented Jul 3, 2026

Copy link
Copy Markdown

1 new issue

Tool Category Rule Count
qlty Structure Function with many returns (count = 6): handleFirstCall 1

@qltysh

qltysh Bot commented Jul 3, 2026

Copy link
Copy Markdown

Qlty


Coverage Impact

This PR will not change total coverage.

Modified Files with Diff Coverage (5)

RatingFile% DiffUncovered Line #s
Coverage rating: A Coverage rating: A
packages/mcp-server/src/tools/execute-action.ts100.0%
Coverage rating: A Coverage rating: A
packages/agent-client/src/approval-request-creator.ts100.0%
Coverage rating: A Coverage rating: A
...-executor/src/executors/trigger-record-action-step-executor.ts100.0%
Coverage rating: A Coverage rating: A
packages/agent-client/src/domains/action.ts100.0%
Coverage rating: A Coverage rating: A
...ages/workflow-executor/src/adapters/agent-client-agent-port.ts100.0%
Total100.0%
🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

alban bertolini and others added 2 commits July 3, 2026 10:50
…ss review

- Action.execute now takes an ActionExecuteOptions object instead of two
  positional optionals (signedApprovalRequest, approvalRequestMessage).
- approval-request-creator: bind and warn on a failed comment POST instead of
  a bare silent catch (keeps best-effort semantics).
- Add tests for the AI-empty-reasoning → step.prompt fallback and the
  no-message-omitted path in the trigger-action executor.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…threading

Keep only the non-obvious rationale (best-effort comment post, comment
destination, prompt fallback); drop comments that restate self-documenting
names.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@christophebrun-forest christophebrun-forest left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manual test OK
LGTM

@Scra3 Scra3 merged commit bb6ee3f into main Jul 3, 2026
37 checks passed
@Scra3 Scra3 deleted the feat/ai-approval-request-message branch July 3, 2026 12:08
forest-bot added a commit that referenced this pull request Jul 3, 2026
# @forestadmin/agent-client [1.10.0](https://github.com/ForestAdmin/agent-nodejs/compare/@forestadmin/agent-client@1.9.0...@forestadmin/agent-client@1.10.0) (2026-07-03)

### Features

* attach AI reasoning as a comment on approval requests ([#1733](#1733)) ([bb6ee3f](bb6ee3f))
forest-bot added a commit that referenced this pull request Jul 3, 2026
# @forestadmin/mcp-server [1.16.0](https://github.com/ForestAdmin/agent-nodejs/compare/@forestadmin/mcp-server@1.15.1...@forestadmin/mcp-server@1.16.0) (2026-07-03)

### Features

* attach AI reasoning as a comment on approval requests ([#1733](#1733)) ([bb6ee3f](bb6ee3f))

### Dependencies

* **@forestadmin/agent-client:** upgraded to 1.10.0
forest-bot added a commit that referenced this pull request Jul 3, 2026
# @forestadmin/workflow-executor [1.13.0](https://github.com/ForestAdmin/agent-nodejs/compare/@forestadmin/workflow-executor@1.12.0...@forestadmin/workflow-executor@1.13.0) (2026-07-03)

### Features

* attach AI reasoning as a comment on approval requests ([#1733](#1733)) ([bb6ee3f](bb6ee3f))

### Dependencies

* **@forestadmin/agent-client:** upgraded to 1.10.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants