Skip to content

feat(chat): add @agent mentions with open_in_agent tool#3093

Merged
viktormarinho merged 7 commits intomainfrom
rafavalls/agent-mentions
Apr 10, 2026
Merged

feat(chat): add @agent mentions with open_in_agent tool#3093
viktormarinho merged 7 commits intomainfrom
rafavalls/agent-mentions

Conversation

@rafavalls
Copy link
Copy Markdown
Collaborator

@rafavalls rafavalls commented Apr 9, 2026

What is this contribution about?

Adds @agent mentions to the chat input for cross-agent collaboration. Users can type @ to see a dropdown of available agents, select one, and the AI will call the new open_in_agent built-in tool to create a task in the target agent and run it in the background. A clickable card renders in the assistant response to navigate to the agent's task.

Also restructures mention triggers: / now shows both prompts and resources in a unified dropdown, while @ is dedicated to agents.

Key changes:

  • @ trigger: Agent mention dropdown with icons (AgentAvatar), violet-styled chips
  • / trigger: Unified prompts + resources dropdown (replaces separate mention-prompts.tsx and mention-resources.tsx)
  • open_in_agent built-in tool (server-side): Validates agent, creates thread, saves user message, runs agent in background via fire-and-forget
  • OpenInAgentPart renderer: Clickable card in assistant response that navigates to /$org/$agentId/?taskId=$taskId
  • Mention system: Added optional allow prop to Suggestion component for trigger customization

Screenshots/Demonstration

WIP - agent mention dropdown, violet chips in editor, tool call card with agent icon + "Open" arrow

How to Test

  1. Start dev server with bun run dev
  2. In chat input, type @ — agent dropdown should appear with icons
  3. Select an agent, type a message, and send
  4. AI should call open_in_agent tool — a card with the agent icon appears
  5. Click the card — navigates to the target agent with the created task
  6. Type / — should show both prompts and resources in one dropdown

Review Checklist

  • PR title is clear and descriptive
  • Changes are tested and working
  • Documentation is updated (if needed)
  • No breaking changes

Summary by cubic

Adds @agent mentions to delegate work across agents via the new open_in_agent tool, and rebuilds @ into a two‑level menu (Agents, Resources) with top‑level search. / is unified for prompts + resources, and delegated tasks render as a clickable card that also starts the agent run on the frontend.

  • New Features

    • @ trigger: two-level menu with icons and ↵ hint; typing at top level searches agents and resources; selecting an agent inserts a violet chip and delegates via open_in_agent; selecting a resource inserts it inline.
    • open_in_agent tool: validates the agent, creates an empty thread, returns task_id; marked non‑idempotent to avoid duplicate threads on retries.
    • Assistant UI: OpenInAgentPart renders a card that starts the agent run via decopilot/stream (idempotent via a module Set + sessionStorage) and navigates to /$org/$agentId/?taskId=$taskId; collapses 3+ tool calls into one expandable row.
    • / trigger: unified dropdown for prompts and resources; keeps the prompt-args dialog.
  • Refactors

    • Tool registration: built-ins now receive userId; open_in_agent is outside the provider gate (works with Claude Code) and excluded from subagent tool sets.
    • Mention system: Suggestion supports allow and onOpenChange; derive-parts distinguishes agent vs resource @ mentions and inserts clear hints for open_in_agent calls.
    • Cleanup: remove unused extractAgentMentions export to satisfy knip.

Written for commit 4b78d33. Summary will update on new commits.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

🧪 Benchmark

Should we run the Virtual MCP strategy benchmark for this PR?

React with 👍 to run the benchmark.

Reaction Action
👍 Run quick benchmark (10 & 128 tools)

Benchmark will run on the next push after you react.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

Release Options

Suggested: Minor (2.258.0) — based on feat: prefix

React with an emoji to override the release type:

Reaction Type Next Version
👍 Prerelease 2.257.1-alpha.1
🎉 Patch 2.257.1
❤️ Minor 2.258.0
🚀 Major 3.0.0

Current version: 2.257.0

Note: If multiple reactions exist, the smallest bump wins. If no reactions, the suggested bump is used (default: patch).

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

4 issues found across 20 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/mesh/src/api/routes/decopilot/built-in-tools/open-in-agent.ts">

<violation number="1" location="apps/mesh/src/api/routes/decopilot/built-in-tools/open-in-agent.ts:61">
P2: `idempotentHint` is incorrectly set to `true` for a state-creating tool; retries can create duplicate tasks.</violation>

<violation number="2" location="apps/mesh/src/api/routes/decopilot/built-in-tools/open-in-agent.ts:221">
P1: `mcpClient` is not closed on error paths; move cleanup to a `finally` so the connection is always released.</violation>
</file>

<file name="apps/mesh/src/web/components/chat/derive-parts.ts">

<violation number="1" location="apps/mesh/src/web/components/chat/derive-parts.ts:294">
P3: `extractAgentMentions` is introduced but not used anywhere in the repository, adding dead code to maintain.</violation>
</file>

<file name="apps/mesh/src/web/components/chat/message/parts/tool-call-part/open-in-agent.tsx">

<violation number="1" location="apps/mesh/src/web/components/chat/message/parts/tool-call-part/open-in-agent.tsx:44">
P2: Remove the client-side debug `console.log` that prints tool output; it can leak task data in production browser consoles.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

cubic-dev-ai[bot]

This comment was marked as outdated.

rafavalls and others added 3 commits April 10, 2026 11:29
Adds agent mentions to the chat input (`@` trigger) that delegate work
to other agents via a new `open_in_agent` built-in tool. Also unifies
prompts and resources under a single `/` trigger.

- `@` trigger shows agent dropdown with icons (via AgentAvatar)
- `/` trigger shows unified prompts + resources dropdown
- New `open_in_agent` server-side tool: validates agent, creates thread,
  saves user message, runs agent in background
- Custom tool call renderer with clickable navigation card
- Agent mention nodes styled in violet, slash mentions in amber

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ now shows "Agents" and "Resources" categories first. Selecting a
category drills into the items list. Also fixes toolsFromMCP
destructuring in open_in_agent background runner.

- New AtMention component with category → items drill-in navigation
- useSuggestion supports onSelect returning false to keep menu open
- @ resources use readResource and insert as mention nodes
- derive-parts handles both agent and resource @ mentions
- Removed old mention-agents.tsx (replaced by mention-at.tsx)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Reset mode to "categories" when @ menu closes (onOpenChange callback)
- Add ↵ kbd badge on drillable category items
- Add onOpenChange prop to Suggestion/useMentionState

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@rafavalls rafavalls force-pushed the rafavalls/agent-mentions branch from 946766a to 1147b4c Compare April 10, 2026 14:29
rafavalls and others added 4 commits April 10, 2026 12:24
When at the top-level category view, typing now searches across both
agents and resources simultaneously instead of just filtering the
two category names.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Each call creates a new thread and fires a background agent run,
so retries would produce duplicates.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Backend tool now only validates the agent and creates an empty thread.
The frontend component starts the agent run via the standard
decopilot/stream endpoint on render, with idempotency via a module-level
Set (re-renders) and sessionStorage (page refreshes).

This removes the bespoke runAgentInBackground server-side logic and
lets the existing stream infrastructure handle the agent run. Also
moves open_in_agent outside the provider gate so it works with
Claude Code agents too.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 3 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/mesh/src/api/routes/decopilot/built-in-tools/open-in-agent.ts">

<violation number="1" location="apps/mesh/src/api/routes/decopilot/built-in-tools/open-in-agent.ts:63">
P2: The tool still requires `context` but execute ignores it and creates an empty thread. That drops the supplied context, so the delegated agent can start without the intended task details. Either persist the context to the thread or remove/relax the `context` field and update the description to match.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

description,
inputSchema: zodSchema(OpenInAgentInputSchema),
needsApproval,
execute: async ({ agent_id }, options) => {
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Apr 10, 2026

Choose a reason for hiding this comment

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

P2: The tool still requires context but execute ignores it and creates an empty thread. That drops the supplied context, so the delegated agent can start without the intended task details. Either persist the context to the thread or remove/relax the context field and update the description to match.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/mesh/src/api/routes/decopilot/built-in-tools/open-in-agent.ts, line 63:

<comment>The tool still requires `context` but execute ignores it and creates an empty thread. That drops the supplied context, so the delegated agent can start without the intended task details. Either persist the context to the thread or remove/relax the `context` field and update the description to match.</comment>

<file context>
@@ -67,16 +54,15 @@ export function createOpenInAgentTool(
     inputSchema: zodSchema(OpenInAgentInputSchema),
     needsApproval,
-    execute: async ({ agent_id, context }, options) => {
+    execute: async ({ agent_id }, options) => {
       const startTime = performance.now();
       try {
</file context>
Fix with Cubic

@viktormarinho viktormarinho merged commit e49c5cb into main Apr 10, 2026
15 checks passed
@viktormarinho viktormarinho deleted the rafavalls/agent-mentions branch April 10, 2026 19:46
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