Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 38 additions & 2 deletions packages/cloud-agents/src/server/cloud-agent-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,30 @@ export function resolveStandardTaskSurface({
}
}

export function isResultOnlyAutomationChatDelivery({
initiatorKind,
slackThreadTs,
communicationMessageId,
}: {
initiatorKind?: string | null;
slackThreadTs?: string | null;
communicationMessageId?: string | null;
}): boolean {
return (
initiatorKind === 'automation' && !slackThreadTs && !communicationMessageId
);
}

export function shouldAttachChatLifecycleInstructions({
inheritedCommunicationContext,
resultOnlyChatDelivery,
}: {
inheritedCommunicationContext: boolean;
resultOnlyChatDelivery: boolean;
}): boolean {
return !inheritedCommunicationContext && !resultOnlyChatDelivery;
}

export async function generatePrompt({
taskRun,
taskSpec,
Expand Down Expand Up @@ -147,6 +171,7 @@ export async function generatePrompt({
actorDisplayName: true,
slackThreadTs: true,
surface: true,
initiatorKind: true,
},
});
const commitAuthor = taskRow
Expand Down Expand Up @@ -316,6 +341,16 @@ export async function generatePrompt({
const communicationMessageId = getCommunicationMessageIdFromTaskPayload(
taskSpec.payload,
);
const resultOnlyChatDelivery = isResultOnlyAutomationChatDelivery({
initiatorKind: taskRow?.initiatorKind,
slackThreadTs,
communicationMessageId,
});
const attachChatLifecycleInstructions =
shouldAttachChatLifecycleInstructions({
inheritedCommunicationContext,
resultOnlyChatDelivery,
});
const teamsTenantId = getCommunicationTenantIdFromTaskPayload(
taskSpec.payload,
);
Expand Down Expand Up @@ -386,6 +421,7 @@ export async function generatePrompt({
sourceChannelId: communicationChannelId ?? undefined,
sourceThreadId: communicationThreadId ?? undefined,
sourceMessageId: communicationMessageId ?? undefined,
resultOnlyChatDelivery,
interactiveMode: taskSpec.payload.bootstrap?.interactiveMode,
requestFormat,
linkedWorkItems: taskSpec.payload.linkedWorkItems,
Expand All @@ -398,7 +434,7 @@ export async function generatePrompt({
prAction,
});

if (!inheritedCommunicationContext && slackChannel && slackThreadTs) {
if (attachChatLifecycleInstructions && slackChannel && slackThreadTs) {
const slackInstructions = buildSlackMessageInstructions({
includeRequestUserInputGuidance: true,
});
Expand All @@ -407,7 +443,7 @@ export async function generatePrompt({
: slackInstructions;
}

if (!inheritedCommunicationContext && nonSlackChatProvider) {
if (attachChatLifecycleInstructions && nonSlackChatProvider) {
const chatInstructions =
nonSlackChatProvider === 'teams'
? buildTeamsMessageInstructions()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion packages/cloud-agents/src/server/workflows/standardTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export function standardTask({
sourceChannelId,
sourceThreadId,
sourceMessageId,
resultOnlyChatDelivery = false,
linkedWorkItems,
interactiveMode = false,
requestFormat = 'plain',
Expand Down Expand Up @@ -122,6 +123,8 @@ export function standardTask({
sourceChannelId?: string;
sourceThreadId?: string;
sourceMessageId?: string;
/** Initial automation report with no directed chat turn to acknowledge. */
resultOnlyChatDelivery?: boolean;
linkedWorkItems?: LinkedWorkItem[];
interactiveMode?: boolean;
requestFormat?: 'plain' | 'structured';
Expand Down Expand Up @@ -258,6 +261,11 @@ export function standardTask({
`
: '';
const defaultMode = interactiveMode ? 'interactive' : 'autonomous';
const isChatTaskSurface =
taskSurface === 'slack' ||
taskSurface === 'teams' ||
taskSurface === 'telegram' ||
taskSurface === 'discord';
const taskSurfaceContext =
taskSurface === 'slack'
? `
Expand Down Expand Up @@ -330,6 +338,15 @@ ${buildGitHubMessageInstructions()}`
<rule>If a workflow or packaged skill distinguishes web dashboard tasks from other surfaces, treat this run as a web dashboard task.</rule>
<rule>When a secure web-task flow exists for the current step, prefer that flow over asking the user to paste secrets into chat or make local-only task edits.</rule>
</task_surface_context>`;
const effectiveTaskSurfaceContext =
resultOnlyChatDelivery && isChatTaskSurface
? `
<task_surface_context>
<rule>This run was launched by an automation with ${taskSurface} as its report destination. It was not launched by a directed chat turn.</rule>
<rule>The automation's chat message must always be its result, never an in-progress message. Keep acknowledgements, reactions, progress updates, partial findings, and routine status in the web task only.</rule>
<rule>The automation-specific prompt remains authoritative for whether to report, which chat tools to use, and the number and shape of final messages. This context only suppresses acknowledgements and in-progress updates before that delivery contract's result.</rule>
</task_surface_context>`
: taskSurfaceContext;
const sourceContext =
sourceProvider && (sourceChannelId || sourceThreadId || sourceMessageId)
? `
Expand Down Expand Up @@ -404,7 +421,7 @@ ${buildGitHubMessageInstructions()}`
<visual_proof_context>Screencast auto-classification is disabled for this task.</visual_proof_context>
</task_context>

${taskSurfaceContext}
${effectiveTaskSurfaceContext}
${sourceContext}
${sourceControlContext}
${codeReviewSelfReviewCloseoutContext}
Expand Down
Loading