Skip to content

Get Started with the Mila Coding Agent

Mila provides a locally hosted AI agent running on the Mila cluster. Any agent harness that supports OpenAI-compatible API can use it.

We recommend the agent harness OpenCode in this guide, feel free to use another one.

Beta

The Mila agent is in beta. Announcements are posted on the #mila-local-agent Slack channel, but this is a community channel. Feel free to reach out there or to the IDT team if you encounter issues or have ideas.

Requirements

  • sudo privileges on your machine.

What this guide covers

  • Overview of the Mila agent
  • Get and store an API key
  • Route traffic to the agent node from a local machine
  • Test the connection with a direct API call
  • Configure OpenCode

Overview of the Mila agent

Why use it?

A locally hosted coding agent

  • Data do not leave the Mila ecosystem
  • It runs on our own resources
  • Free for Mila researchers
  • You can be part of it by your feedback

What's in there?

Model Qwen3.8-Flash-Next-fp8
Node 8 x DGX-A100 (Node cn-d003.server.mila.quebec)

Get an API key

  1. Get an API key by filling this form.

  2. Store it by adding the export to ~/.bashrc:

    export MILA_AGENT_KEY=sk-…
    
  3. Then reload the shell configuration:

    source ~/.bashrc
    

Route traffic to the agent node from a local machine

How it works

The Mila agent stack listens on port 8080 at cn-d003.server.mila.quebec. The node is not directly accessible from the Mila wifi yet, so traffic must be routed through a Mila login node:

graph LR
    A[Local machine] -->|"ssh mila -L 8080:...:8080"| B[Login node]
    B -->|forwards port 8080| C[cn-d003:8080]

Once the route is active, the stack is reachable at http://cn-d003.server.mila.quebec:8080 from the local machine. OpenCode and other harnesses address the gateway by hostname, so the local machine must resolve cn-d003.server.mila.quebec to itself and forward the port through the login node.

  1. Start a SSH tunnel with port forwarding:

    ssh mila -L 8080:cn-d003.server.mila.quebec:8080  # (1)!
    
    1. -L 8080:cn-d003.server.mila.quebec:8080 forwards local port 8080 to port 8080 on the node, through the login node. Keep this session open while working with the Mila agent.
  2. Then add this line to /etc/hosts (editing /etc/hosts requires sudo):

    127.0.0.1   cn-d003.server.mila.quebec
    

Test the connection

Send a direct request to the chat completions endpoint. The same command works from the local machine (with the SSH tunnel active) and from any login node or compute node on the cluster:

1
2
3
4
curl "http://cn-d003.server.mila.quebec:8080/v1/chat/completions" \
  -H "Authorization: Bearer $MILA_AGENT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"Qwen/Qwen3.8-Flash-Next-FP8","messages":[{"role":"user","content":"Reply with OK."}],"max_tokens":16}'

A successful call returns a JSON object whose message content echoes the prompt:

{"choices":[{"message":{"content":"OK","role":"assistant"}}]}

Plain HTTP, not HTTPS

The connection between the login node and the agent node currently uses plain HTTP. In theory, someone on the cluster with network interface access or sudo could capture the LiteLLM, Grafana, or API keys β€” not the @mila.quebec account credentials. These cases are extreme, but keep them in mind until HTTPS is set up.

Configure OpenCode

Endpoint for the harness

To use the agent with another harness, point the latter to the OpenAI-compatible endpoint:

http://cn-d003.server.mila.quebec:8080/v1/
  1. Install OpenCode from https://opencode.ai/. Then create the configuration file at ~/.config/opencode/opencode.jsonc:

    ~/.config/opencode/opencode.jsonc
    {
        "$schema": "https://opencode.ai/config.json",
    
        // Basic suggested Guardrails: never let the agent fetch .cn domains (last matching rule wins,
        // so the specific denies must come after the broad ask rules).
        "permissions": [
            { "action": "shell", "resource": "curl *", "effect": "ask" },
            { "action": "shell", "resource": "wget *", "effect": "ask" },
            { "action": "shell", "resource": "curl *://*.cn*", "effect": "deny" },
            { "action": "shell", "resource": "curl *.cn*", "effect": "deny" },
            { "action": "shell", "resource": "wget *://*.cn*", "effect": "deny" },
            { "action": "shell", "resource": "wget *.cn*", "effect": "deny" },
            { "action": "shell", "resource": "* curl *://*.cn*", "effect": "deny" },
            { "action": "shell", "resource": "* wget *://*.cn*", "effect": "deny" },
            { "action": "webfetch", "resource": "*.cn", "effect": "deny" },
            { "action": "webfetch", "resource": "*.cn/*", "effect": "deny" },
            { "action": "webfetch", "resource": "*.cn:*", "effect": "deny" }
        ],
    
        // Hard layer: evaluated after permissions and saved "Allow always"
        // approvals, so no approval or agent rule can lift these.
        "policies": [
            { "action": "tool.use", "resource": "shell:*://*.cn*", "effect": "deny" },
            { "action": "tool.use", "resource": "shell:*curl *.cn*", "effect": "deny" },
            { "action": "tool.use", "resource": "shell:*wget *.cn*", "effect": "deny" },
            { "action": "tool.use", "resource": "webfetch:*://*.cn", "effect": "deny" },
            { "action": "tool.use", "resource": "webfetch:*://*.cn/*", "effect": "deny" },
            { "action": "tool.use", "resource": "webfetch:*://*.cn:*", "effect": "deny" }
        ],
    
        "plugin": [
            "opencode-models-discovery@latest"
        ],
        "skills": [
        "https://mila-iqia.github.io/skills/opt-tools/skills",
        "https://mila-iqia.github.io/skills/mila-tools/skills",
        "https://mila-iqia.github.io/skills/pytorch-opt-skills/skills"
        ],
        "mcp": {
            "servers": {
                "mila-docs": {
                    "type": "remote",
                    "url": "https://558773LESW.algolia.net/mcp/1/3_N8rKyLQhaxUEpt0FMx6A/mcp",
                    "enabled": true
                }
            }
        },
        "provider": {
            "a100": {
                "npm": "@ai-sdk/openai-compatible",
                "name": "DGX A100",
                "options": {
                    "baseURL": "http://cn-d003.server.mila.quebec:8080/v1",
                    "apiKey": "{env:MILA_AGENT_KEY}",
                    "modelsDiscovery": {
                        "enabled": true,
                        "smartModelName": true,
                        "modelInfoFormat": "litellm"
                    }
                }
            }
        }
    }
    
    Configuration explanation
    • The skills part loads the Mila Skills, available in this Github repository.
    • The mcp refers to the MCP of the Mila cluster documentation.
    • The a100 provider speaks the OpenAI-compatible protocol to the gateway.
      • baseURL is the agent node URL
      • apiKey reads the MILA_AGENT_KEY environment variable at runtime, so no key is stored in the file.
      • The opencode-models-discovery plugin lists the models available on the gateway automatically, so newly deployed models appear in OpenCode without a configuration change.
  2. Launch OpenCode

    opencode
    

    Here you are! You can check:

    • The model is Qwen3.8 Flash Next Fp8.
    • Your repository is the repository where you want to work (~/Desktop/my-repo on the screenshot).
    • One MCP is active (the Mila docs one, as described in the configuration).

    OpenCode


Key concepts

Model discovery
Querying the gateway's model list at runtime so the harness shows the currently deployed models without manual configuration.

Comments