-
Notifications
You must be signed in to change notification settings - Fork 42
feat(chat): add @agent mentions with open_in_agent tool #3093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3d344a5
feat(chat): add @agent mentions with open_in_agent tool
rafavalls 53a2fd3
feat(chat): rebuild @ as two-level menu with categories
rafavalls 1147b4c
fix(chat): reset @ menu mode on close + add Enter kbd hint
rafavalls 6bcf839
feat(chat): search both agents and resources when typing after @
rafavalls 3acd317
fix(chat): remove unused extractAgentMentions export to fix knip
rafavalls 9032adb
fix(chat): mark open_in_agent as non-idempotent
viktormarinho 4b78d33
refactor(chat): move open_in_agent stream start to frontend
viktormarinho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
apps/mesh/src/api/routes/decopilot/built-in-tools/open-in-agent.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /** | ||
| * open_in_agent Built-in Tool | ||
| * | ||
| * Validates the target agent and creates an empty thread (task). | ||
| * Returns immediately with a taskId — the frontend starts the actual | ||
| * agent run via the standard decopilot/stream endpoint. | ||
| */ | ||
|
|
||
| import type { MeshContext, OrganizationScope } from "@/core/mesh-context"; | ||
| import type { UIMessageStreamWriter } from "ai"; | ||
| import { tool, zodSchema } from "ai"; | ||
| import { z } from "zod"; | ||
|
|
||
| const OpenInAgentInputSchema = z.object({ | ||
| agent_id: z | ||
| .string() | ||
| .min(1) | ||
| .max(128) | ||
| .describe("The ID of the agent (Virtual MCP) to open."), | ||
| context: z | ||
| .string() | ||
| .min(1) | ||
| .max(50_000) | ||
| .describe( | ||
| "The context/task to forward to the agent. Include all relevant information " + | ||
| "from the current conversation — the agent will start fresh with only this context.", | ||
| ), | ||
| }); | ||
|
|
||
| const description = | ||
| "Open a task in another agent's UI. Use this when the user @mentions an agent " + | ||
| "and wants to hand off work to that agent's specialized interface. " + | ||
| "The user will see a clickable card to navigate to the agent.\n\n" + | ||
| "Usage notes:\n" + | ||
| "- Include full context (conversation summary, tool results, relevant data) in the context field.\n" + | ||
| "- The agent starts fresh — it has no access to this conversation.\n" + | ||
| "- This is NOT subtask — the work runs in the agent's own UI, not inline."; | ||
|
|
||
| export interface OpenInAgentParams { | ||
| organization: OrganizationScope; | ||
| userId: string; | ||
| needsApproval?: boolean; | ||
| } | ||
|
|
||
| const ANNOTATIONS = { | ||
| readOnlyHint: false, | ||
| destructiveHint: false, | ||
| idempotentHint: false, | ||
| openWorldHint: false, | ||
| } as const; | ||
|
|
||
| export function createOpenInAgentTool( | ||
| writer: UIMessageStreamWriter, | ||
| params: OpenInAgentParams, | ||
| ctx: MeshContext, | ||
| ) { | ||
| const { organization, userId, needsApproval } = params; | ||
|
|
||
| return tool({ | ||
| description, | ||
| inputSchema: zodSchema(OpenInAgentInputSchema), | ||
| needsApproval, | ||
| execute: async ({ agent_id }, options) => { | ||
| const startTime = performance.now(); | ||
| try { | ||
| const virtualMcp = await ctx.storage.virtualMcps.findById( | ||
| agent_id, | ||
| organization.id, | ||
| ); | ||
|
|
||
| if (!virtualMcp || virtualMcp.organization_id !== organization.id) { | ||
| throw new Error("Agent not found"); | ||
| } | ||
|
|
||
| if (virtualMcp.status !== "active") { | ||
| throw new Error("Agent is not active"); | ||
| } | ||
|
|
||
| if (!userId) { | ||
| throw new Error("User ID is required to create a thread"); | ||
| } | ||
|
|
||
| const taskId = crypto.randomUUID(); | ||
| await ctx.storage.threads.create({ | ||
| id: taskId, | ||
| created_by: userId, | ||
| virtual_mcp_id: agent_id, | ||
| }); | ||
|
|
||
| return { | ||
| success: true, | ||
| agent_id: virtualMcp.id, | ||
| agent_title: virtualMcp.title, | ||
| task_id: taskId, | ||
| }; | ||
| } finally { | ||
| const latencyMs = performance.now() - startTime; | ||
| writer.write({ | ||
| type: "data-tool-metadata", | ||
| id: options.toolCallId, | ||
| data: { annotations: ANNOTATIONS, latencyMs }, | ||
| }); | ||
| } | ||
| }, | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
apps/mesh/src/web/components/chat/message/parts/tool-call-part/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| export { GenericToolCallPart } from "./generic.tsx"; | ||
| export { OpenInAgentPart } from "./open-in-agent.tsx"; | ||
| export { UserAskPart } from "./user-ask.tsx"; | ||
| export { SubtaskPart } from "./subtask.tsx"; | ||
| export { ProposePlanPart } from "./propose-plan.tsx"; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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
contextbut 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 thecontextfield and update the description to match.Prompt for AI agents