Skip to content

Commit 8b6f55c

Browse files
authored
chore: improve remote mcp workspace and file prompts (coder#20475)
I have been experimenting (via blink) and these seem to have made the LLM behave more intelligently and consistently when it comes to creating workspaces and manipulating files. Partially addresses coder/internal#1047
1 parent 40fc337 commit 8b6f55c

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

codersdk/toolsdk/bash.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,16 @@ If the command times out, all output captured up to that point is returned with
5353
For background commands (background: true), output is captured until the timeout is reached, then the command
5454
continues running in the background. The captured output is returned as the result.
5555
56+
For file operations (list, write, edit), always prefer the dedicated file tools.
57+
Do not use bash commands (ls, cat, echo, heredoc, etc.) to list, write, or read
58+
files when the file tools are available. The bash tool should be used for:
59+
60+
- Running commands and scripts
61+
- Installing packages
62+
- Starting services
63+
- Executing programs
64+
5665
Examples:
57-
- workspace: "my-workspace", command: "ls -la"
5866
- workspace: "john/dev-env", command: "git status", timeout_ms: 30000
5967
- workspace: "my-workspace", command: "npm run dev", background: true, timeout_ms: 10000
6068
- workspace: "my-workspace.main", command: "docker ps"`,

codersdk/toolsdk/toolsdk.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,18 @@ var CreateWorkspace = Tool[CreateWorkspaceArgs, codersdk.Workspace]{
353353
If a user is asking to "test a template", they are typically referring
354354
to creating a workspace from a template to ensure the infrastructure
355355
is provisioned correctly and the agent can connect to the control plane.
356+
357+
Before creating a workspace, always confirm the template choice with the user by:
358+
359+
1. Listing the available templates that match their request.
360+
2. Recommending the most relevant option.
361+
2. Asking the user to confirm which template to use.
362+
363+
It is important to not create a workspace without confirming the template
364+
choice with the user.
365+
366+
After creating a workspace, watch the build logs and wait for the workspace to
367+
be ready before trying to use or connect to the workspace.
356368
`,
357369
Schema: aisdk.Schema{
358370
Properties: map[string]any{
@@ -530,8 +542,13 @@ type CreateWorkspaceBuildArgs struct {
530542

531543
var CreateWorkspaceBuild = Tool[CreateWorkspaceBuildArgs, codersdk.WorkspaceBuild]{
532544
Tool: aisdk.Tool{
533-
Name: ToolNameCreateWorkspaceBuild,
534-
Description: "Create a new workspace build for an existing workspace. Use this to start, stop, or delete.",
545+
Name: ToolNameCreateWorkspaceBuild,
546+
Description: `Create a new workspace build for an existing workspace. Use this to start, stop, or delete.
547+
548+
After creating a workspace build, watch the build logs and wait for the
549+
workspace build to complete before trying to start another build or use or
550+
connect to the workspace.
551+
`,
535552
Schema: aisdk.Schema{
536553
Properties: map[string]any{
537554
"workspace_id": map[string]any{
@@ -1531,8 +1548,20 @@ type WorkspaceWriteFileArgs struct {
15311548

15321549
var WorkspaceWriteFile = Tool[WorkspaceWriteFileArgs, codersdk.Response]{
15331550
Tool: aisdk.Tool{
1534-
Name: ToolNameWorkspaceWriteFile,
1535-
Description: `Write a file in a workspace.`,
1551+
Name: ToolNameWorkspaceWriteFile,
1552+
Description: `Write a file in a workspace.
1553+
1554+
If a file write fails due to syntax errors or encoding issues, do NOT switch
1555+
to using bash commands as a workaround. Instead:
1556+
1557+
1. Read the error message carefully to identify the issue
1558+
2. Fix the content encoding/syntax
1559+
3. Retry with this tool
1560+
1561+
The content parameter expects base64-encoded bytes. Ensure your source content
1562+
is correct before encoding it. If you encounter errors, decode and verify the
1563+
content you are trying to write, then re-encode it properly.
1564+
`,
15361565
Schema: aisdk.Schema{
15371566
Properties: map[string]any{
15381567
"workspace": map[string]any{

0 commit comments

Comments
 (0)