Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(agent/agentcontainers): support apps for dev container agents #18346

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 16 commits into from
Jun 18, 2025

Conversation

DanielleMaywood
Copy link
Contributor

@DanielleMaywood DanielleMaywood commented Jun 12, 2025

Add apps to the sub agent based on the dev container customization.

{
  "name": "Development Container",
  "image": "mcr.microsoft.com/devcontainers/typescript-node:18",
  "customizations": {
    "coder": {
      "apps": [
        {
          "slug": "web-app",
          "displayName": "Web Application",
          "url": "http://localhost:8080/${localEnv:CODER_USER_NAME}/${localEnv:CODER_WORKSPACE_NAME}/${localEnv:CODER_AGENT_NAME}",
          "openIn": "tab",
          "share": "owner",
          "icon": "${localEnv:CODER_URL}/icons/web.svg",
          "order": 1,
          "group": "Web Editors"
        }
      ]
    }
  }
}

The implementation also provides the following env variables for use in the devcontainer json

  • CODER_WORKSPACE_AGENT_NAME
  • CODER_WORKSPACE_USER_NAME
  • CODER_WORKSPACE_NAME
  • CODER_URL

@DanielleMaywood DanielleMaywood force-pushed the dm-sub-agent-apps-configuration-2 branch from d06023f to 08f0f9c Compare June 12, 2025 19:47
Base automatically changed from dm-sub-agent-apps-configuration to main June 12, 2025 22:36
@DanielleMaywood DanielleMaywood force-pushed the dm-sub-agent-apps-configuration-2 branch from 08f0f9c to 6270098 Compare June 12, 2025 22:42
@DanielleMaywood DanielleMaywood requested a review from Copilot June 12, 2025 22:43
Copilot

This comment was marked as outdated.

@DanielleMaywood DanielleMaywood force-pushed the dm-sub-agent-apps-configuration-2 branch 3 times, most recently from c3ba85a to c800571 Compare June 17, 2025 16:07
@DanielleMaywood DanielleMaywood force-pushed the dm-sub-agent-apps-configuration-2 branch from 75709b9 to 8ec61b6 Compare June 18, 2025 10:14
@DanielleMaywood DanielleMaywood requested a review from Copilot June 18, 2025 10:14
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for passing app definitions to sub agents based on dev container customizations and updates related tests and API integrations.

  • Extends the API to accept new app-related configuration options.
  • Adds new tests for sub-agent apps functionality and updates environment variable handling in the devcontainer CLI.
  • Updates various components (API, client, tests, and mocks) to support the new apps configuration.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
agent/api.go Appends options for user and workspace names and devcontainer apps; injects environment variables.
agent/agenttest/client.go Introduces GetSubAgentApps for retrieving app definitions.
agent/agentcontainers/subagent_test.go Adds tests for sub-agent creation with app configurations.
agent/agentcontainers/subagent.go Extends the SubAgent struct and converts app configuration for API calls.
agent/agentcontainers/devcontainercli_test.go Updates devcontainer CLI test to include an explicit env argument.
agent/agentcontainers/devcontainercli.go Adds environment variables to CLI commands.
agent/agentcontainers/api_test.go Updates tests to include env validations for sub-agent app settings.
agent/agentcontainers/acmock/acmock.go Adjusts mock method signatures to include the new env arg.
Comments suppressed due to low confidence (1)

@DanielleMaywood DanielleMaywood marked this pull request as ready for review June 18, 2025 10:28
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

I still need to take a closer look at the tests, but I identified some things that may require some refactoring.

fmt.Sprintf("CODER_WORKSPACE_AGENT_NAME=%s", dc.Name),
fmt.Sprintf("CODER_WORKSPACE_OWNER_NAME=%s", api.userName),
fmt.Sprintf("CODER_WORKSPACE_NAME=%s", api.workspaceName),
fmt.Sprintf("CODER_DEPLOYMENT_URL=%s", api.subAgentURL),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fmt.Sprintf("CODER_DEPLOYMENT_URL=%s", api.subAgentURL),
fmt.Sprintf("CODER_AGENT_URL=%s", api.subAgentURL),

The naming is slightly unfortunate but we currently have both CODER_URL and CODER_AGENT_URL in the product, and a third one seems like too much.

IMO CODER_URL would be more appropriate, however, it would be nice if these environment variables were also set on the parent workspace/agent (with CODER_AGENT_URL we're at 3/4). The reason is that if a user runs devcontainer up manually, these values are then serializable into the docker container label.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've replaced it with CODER_URL. If you'd rather CODER_AGENT_URL I'm happy to update it again.

I don't think we can rely on anything serialized at the point of devcontainer up, as the CODER_WORKSPACE_AGENT_NAME will be the parents agent name, not the child. So I'm not sure there is too much benefit there.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that's a good point about the conflicting env. Let's go with CODER_URL for now 👍🏻

agent/api.go Outdated
if manifest != nil {
containerAPIOpts = append(containerAPIOpts,
agentcontainers.WithUserName(manifest.OwnerName),
agentcontainers.WithWorkspaceName(manifest.WorkspaceName),
Copy link
Member

Choose a reason for hiding this comment

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

It'd be nice to consolidate similar things rather than having too many knobs, perhaps a agentcontainers.WithManifestInfo(url, owner, workspace)? (I'm aware my naming suggestion could've been better 😅.)

@@ -153,6 +156,15 @@ func WithSubAgentEnv(env ...string) Option {
}
}

// WithManifestInfo sets the owner name, and workspace name
// for the sub-agent.
func WithManifestInfo(owner, workspace string) Option {
Copy link
Member

Choose a reason for hiding this comment

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

nit: the naming suggests you can pass in the entire manifest?

Comment on lines +1146 to +1149
fmt.Sprintf("CODER_WORKSPACE_AGENT_NAME=%s", dc.Name),
fmt.Sprintf("CODER_WORKSPACE_OWNER_NAME=%s", api.ownerName),
fmt.Sprintf("CODER_WORKSPACE_NAME=%s", api.workspaceName),
fmt.Sprintf("CODER_URL=%s", api.subAgentURL),
Copy link
Member

Choose a reason for hiding this comment

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

Note for later: we'll need to document these environment variables somewhere.

@DanielleMaywood DanielleMaywood merged commit 529fb50 into main Jun 18, 2025
34 checks passed
@DanielleMaywood DanielleMaywood deleted the dm-sub-agent-apps-configuration-2 branch June 18, 2025 13:55
@github-actions github-actions bot locked and limited conversation to collaborators Jun 18, 2025
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

A few more things but other than that, looks good, nice work!

if config, err := api.dccli.ReadConfig(ctx, dc.WorkspaceFolder, dc.ConfigPath,
[]string{
fmt.Sprintf("CODER_WORKSPACE_AGENT_NAME=%s", dc.Name),
fmt.Sprintf("CODER_WORKSPACE_OWNER_NAME=%s", api.ownerName),
Copy link
Member

Choose a reason for hiding this comment

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

Can we modify agent/agent.go to set this on the parent as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to ensure I know what you're referring to:

In this stanza here?

coder/agent/agent.go

Lines 1293 to 1309 in 529fb50

// Define environment variables that should be set for all commands,
// and then merge them with the current environment.
envs := map[string]string{
// Set env vars indicating we're inside a Coder workspace.
"CODER": "true",
"CODER_WORKSPACE_NAME": manifest.WorkspaceName,
"CODER_WORKSPACE_AGENT_NAME": manifest.AgentName,
// Specific Coder subcommands require the agent token exposed!
"CODER_AGENT_TOKEN": *a.sessionToken.Load(),
// Git on Windows resolves with UNIX-style paths.
// If using backslashes, it's unable to find the executable.
"GIT_SSH_COMMAND": fmt.Sprintf("%s gitssh --", unixExecutablePath),
// Hide Coder message on code-server's "Getting Started" page
"CS_DISABLE_GETTING_STARTED_OVERRIDE": "true",
}

subAgentConfig.DisplayApps = displayApps
subAgentConfig.Apps = apps
Copy link
Member

Choose a reason for hiding this comment

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

We should log app creation errors from the response after agent creation too.

Hidden: &app.Hidden,
Order: &app.Order,
Subdomain: &app.Subdomain,
}
Copy link
Member

Choose a reason for hiding this comment

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

Did we check to see what the "defaults" when creating apps in terraform?

URL string `json:"url"`
}

func (app SubAgentApp) ToProtoApp() (*agentproto.CreateSubAgentRequest_App, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Comment: Typically these methods exist in agentsdk/convert.go. Personally I think it makes sense to keep here though.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants