Skip to content

[Due for payment 2026-08-12] Immediately open the agent DM after creating a new agent #94395

Closed

Description

@melvin-bot

Problem

After creating a new agent, it appears on the agents page but there's no clear next action. The actual next step is to open a DM with the agent, but nothing guides the user there — they have to discover it on their own.

Proposed solution

Immediately open the DM with the newly created agent right after creation (or provide a clear deep link / next-step CTA to it), so users land directly in the conversation where they can start using the agent.

Context

Came out of feedback on the new custom agent creation flow — there was no clear next action after creation, which left users unsure how to proceed.

Reported in Slack.

Activity

  1. self-assigned this
    on Jul 6, 2026
  2. mjasikowski commented on Jul 7, 2026

    @mjasikowski
    Contributor

    @MelvinBot create an implementation plan

  3. MelvinBot commented on Jul 7, 2026

    @MelvinBot
    Contributor

    Implementation Plan: Open the agent DM right after creation

    TL;DR: All the pieces already exist. createAgent already returns the new agent's optimisticAccountID, and the useChatWithAgent hook already knows how to open a DM by accountID (it's what each row on the Agents list uses). The fix is to stop discarding that accountID in AddAgentPage.handleSubmit and hand it to chatWithAgent(...) instead of just calling Navigation.goBack().

    The one change that matters

    AddAgentPage.handleSubmit currently ignores the return value of createAgent and does a plain Navigation.goBack(), landing the user back on the Agents list with no next step.

    // add alongside the other hooks near the top of the component
    const chatWithAgent = useChatWithAgent();
    
    const handleSubmit = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.ADD_AGENT_FORM>) => {
        const firstName = values[INPUT_IDS.FIRST_NAME].trim() || defaultAgentName;
        const prompt = values[INPUT_IDS.PROMPT].trim();
        const pendingFile = pendingFileRef.current;
    
        const {optimisticAccountID} = pendingFile
            ? createAgent(firstName, prompt, undefined, pendingFile.file, pendingFile.uri, policyID)
            : createAgent(firstName, prompt, selectedPresetID ?? undefined, undefined, undefined, policyID);
    
        // Replaces Navigation.goBack() — drop the user straight into the DM with the new agent.
        chatWithAgent(optimisticAccountID);
    };

    This stays fully offline-first and matches the existing "pure optimistic flow" comment: createAgent returns {optimisticAccountID, avatarURI}, and useChatWithAgent → navigateToAndOpenReportWithAccountIDs([accountID], ...) optimistically builds + opens the DM report client-side.

    ⚠️ The one thing to verify first

    The client generates optimisticAccountID via generateReportID() and sends it to the backend in the CreateAgent params (Agent.ts:100). The whole plan hinges on the backend honoring that client-supplied accountID as the agent's real, permanent accountID (the standard optimistic-ID pattern). If it does, the DM opened against it stays valid after the server responds — done.

    If instead the backend assigns a different accountID, opening the DM optimistically would point at a phantom account (the successData nulls the optimistic personal detail), and the plan changes: you'd need CreateAgent to return the real accountID and open the DM from the success callback (awaiting the write), giving up the pure-optimistic UX. Confirm the backend behavior before implementing — it determines which of the two paths above is correct.

    Supporting detail: files, existing precedent, and navigation notes
    • Create action: createAgent fires WRITE_COMMANDS.CREATE_AGENT and already returns {optimisticAccountID, avatarURI} — currently discarded by the caller.
    • Existing DM-open precedent: each row on AgentsPage already wires onChatPress={chatWithAgent} from the same hook, so opening a DM by agent accountID is a proven, in-use path — we're just triggering it one step earlier.
    • Underlying action: navigateToAndOpenReportWithAccountIDs does getChatByParticipants → buildOptimisticChatReport + openReport → navigateToReport(ROUTES.REPORT_WITH_ID).
    • Navigation stack: AddAgentPage is a settings/RHP screen. Verify that navigating to the report cleanly dismisses the RHP/modal so the DM lands in the central pane (rather than stacking under the settings modal). If it doesn't dismiss on its own, dismiss the modal before/as part of the navigation.
    • Scope: this is a single-file change in AddAgentPage.tsx (plus the backend confirmation above). No new hook, action, or route is needed.
    • Testing: create an agent online and offline; confirm you land in the DM, the agent renders (optimistic → reconciled), and the DM remains the same report after the server responds (the key regression to watch given the optimistic-accountID question above).

    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/94395#issuecomment-4902205853) to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting this plan.

  4. mjasikowski commented on Jul 7, 2026

    @mjasikowski
    Contributor

    @MelvinBot implement [this](#94395 (comment)

  5. MelvinBot commented on Jul 7, 2026

    @MelvinBot
    Contributor

    🤖 Draft PR created: #95482

    What it does: AddAgentPage.handleSubmit now captures the optimisticAccountID returned by createAgent and opens the DM with the new agent via the existing useChatWithAgent hook, instead of just calling Navigation.goBack(). Fully optimistic/offline-first — no waiting on the server.

    Checks run locally (all green): npm run fmt, lint-changed, typecheck-tsgo, React Compiler compliance, and the AddAgentPage + Agent action unit tests (64 passed). I updated the two AddAgentPage submit tests to assert the new "open the DM" behavior.

    ⚠️ One thing to confirm during review (flagged in the plan): this relies on the backend honoring the client-supplied optimisticAccountID as the agent's permanent accountID. If the server assigns a different accountID, the DM would need to open from the CreateAgent success response instead. Worth verifying the DM stays the same report after the server reconciles.

    Please fill out the Tests/QA sections and mark it as "Ready for review" when it's ready.

  6. 19 remaining items

  7. added and removed on Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions