Agents

Go Memory + Consequence

Install the Go 1.25+ SDK:

go get github.com/neutron-ai/neutron/packages/sdk-go

The module handles memory and agent context. A small net/http helper calls industry-library and Consequence endpoints that are not yet exposed as typed Go methods.

Client and authenticated REST helper

package main

import (
    "bytes"
    "context"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
    "os"
    "strings"
    "time"

    neutron "github.com/neutron-ai/neutron/packages/sdk-go"
)

const nucleusID = "checkout-platform"

func requiredEnv(name string) (string, error) {
    value := os.Getenv(name)
    if strings.TrimSpace(value) == "" {
        return "", fmt.Errorf("%s is required", name)
    }
    return value, nil
}

func scoped(body map[string]any) map[string]any {
    output := map[string]any{"nucleusId": nucleusID}
    for key, value := range body {
        output[key] = value
    }
    return output
}

func postJSON(
    ctx context.Context,
    httpClient *http.Client,
    baseURL string,
    token string,
    path string,
    body map[string]any,
) (map[string]any, error) {
    payload, err := json.Marshal(body)
    if err != nil {
        return nil, err
    }
    request, err := http.NewRequestWithContext(
        ctx,
        http.MethodPost,
        strings.TrimRight(baseURL, "/")+path,
        bytes.NewReader(payload),
    )
    if err != nil {
        return nil, err
    }
    request.Header.Set("authorization", "Bearer "+token)
    request.Header.Set("content-type", "application/json")

    response, err := httpClient.Do(request)
    if err != nil {
        return nil, err
    }
    defer response.Body.Close()
    rawBody, err := io.ReadAll(response.Body)
    if err != nil {
        return nil, err
    }
    if response.StatusCode >= 400 {
        return nil, fmt.Errorf("Neutron request failed: %s", response.Status)
    }
    output := map[string]any{}
    if err := json.Unmarshal(rawBody, &output); err != nil {
        return nil, err
    }
    return output, nil
}

Keep workspace, approver, and internal credentials outside the agent runtime.

Install knowledge and build context

func prepareContext(
    ctx context.Context,
    httpClient *http.Client,
    baseURL string,
) (*neutron.Client, error) {
    workspaceKey, err := requiredEnv("NEUTRON_WORKSPACE_API_KEY")
    if err != nil {
        return nil, err
    }
    if _, err := postJSON(
        ctx,
        httpClient,
        baseURL,
        workspaceKey,
        "/v1/platform/industry-library/plugins/ai-engineering-delivery/install",
        map[string]any{"nucleusId": nucleusID},
    ); err != nil {
        return nil, err
    }

    agentToken, err := requiredEnv("NEUTRON_API_TOKEN")
    if err != nil {
        return nil, err
    }
    memory, err := neutron.NewClient(neutron.Options{
        BaseURL: baseURL, Token: agentToken, NucleusID: nucleusID,
    })
    if err != nil {
        return nil, err
    }
    if _, err := memory.Remember(ctx, map[string]any{
        "scopeId": "history:checkout-releases",
        "agentId": "agent:release-manager",
        "type": "experience",
        "privacyClass": "tenant",
        "text": strings.Join([]string{
            "Release 3.7 used a 5% cohort for 20 minutes before expansion.",
            "The rollout paused when database lock time exceeded 250 ms.",
            "Rollback succeeded. Verify lock duration before expanding similar changes.",
        }, " "),
        "metadata": map[string]any{
            "source": "approved-release-review", "release": "3.7", "outcome": "rolled-back",
        },
    }); err != nil {
        return nil, err
    }
    _, err = memory.AgentContext(ctx, map[string]any{
        "scopeIds": []string{
            "industry:ai-engineering-delivery",
            "service:checkout-api",
            "history:checkout-releases",
            "policy:production-change",
        },
        "agentId": "agent:release-manager",
        "task": "Prepare a safe release recommendation for checkout API version 3.8.",
        "privacyClasses": []string{"tenant"},
        "tokenBudget": 1600,
        "cachePolicy": map[string]any{
            "mode": "prefer_cache", "keyMode": "intent_profile",
            "ttlSeconds": 300, "includeDynamicRag": true,
        },
    })
    return memory, err
}

Pass the returned promptContext to the chosen model only as supporting context.

Plan, decide, and approve

func planAndDecide(
    ctx context.Context,
    httpClient *http.Client,
    baseURL string,
) (map[string]any, error) {
    agentToken, err := requiredEnv("NEUTRON_API_TOKEN")
    if err != nil {
        return nil, err
    }
    decisionScopes := []string{
        "industry:ai-engineering-delivery",
        "service:checkout-api",
        "history:checkout-releases",
        "policy:production-change",
    }
    run, err := postJSON(ctx, httpClient, baseURL, agentToken, "/v1/consequence/plan", scoped(map[string]any{
        "scopeIds": decisionScopes,
        "agentId": "agent:release-manager",
        "task": "Compare delaying release 3.8, a 1% pilot, a 5% staged rollout, and immediate release while preserving compatibility and the lock budget.",
        "domain": "engineering_ops",
        "objectiveHints": []string{
            "Reduce customer impact", "Preserve rollback capability", "Collect evidence before expansion",
        },
        "constraintHints": []string{
            "Database lock time must remain below the approved threshold",
            "Expansion requires the accountable release owner",
            "Rollback must remain available",
        },
        "idempotencyKey": "checkout-3.8-release-review-v1",
        "retentionDays": 90,
        "contextPolicy": map[string]any{
            "includeMemory": true, "includeKnowledge": true,
            "includeContextCapsules": true, "includePastDecisions": true,
            "includeReflections": true,
        },
        "policy": map[string]any{
            "mode": "deep", "depth": 10, "maxScenarios": 8, "maxRuntimeMs": 8000,
            "requireApprovalAboveRisk": "medium", "allowExecution": false,
            "storeSafeArtifactsOnly": true, "includeCounterfactuals": true,
            "includeReflections": true,
        },
    }))
    if err != nil {
        return nil, err
    }
    scenarioID, _ := run["recommendedScenarioId"].(string)
    runID, _ := run["runId"].(string)
    if scenarioID == "" || runID == "" {
        return nil, fmt.Errorf("no scenario satisfied the current decision boundary")
    }

    decided, err := postJSON(ctx, httpClient, baseURL, agentToken, "/v1/consequence/decide", scoped(map[string]any{
        "runId": runID,
        "scopeIds": []string{"service:checkout-api", "policy:production-change"},
        "selectedScenarioId": scenarioID,
        "decisionSummary": "Selected the bounded pilot scenario for owner review.",
        "rationaleSummary": "The pilot preserves rollback and gathers current lock evidence; expansion requires threshold compliance and owner review.",
    }))
    if err != nil {
        return nil, err
    }
    decision, ok := decided["decisionRecord"].(map[string]any)
    if !ok {
        return nil, fmt.Errorf("the decision record was not created")
    }
    if decision["status"] == "draft" {
        approverToken, err := requiredEnv("NEUTRON_APPROVER_TOKEN")
        if err != nil {
            return nil, err
        }
        _, err = postJSON(ctx, httpClient, baseURL, approverToken, "/v1/consequence/approve", scoped(map[string]any{
            "decisionId": decision["decisionId"],
            "scopeIds": []string{"service:checkout-api", "policy:production-change"},
            "note": "Release owner approved the pilot only; expansion needs another review.",
        }))
        if err != nil {
            return nil, err
        }
    }
    return decision, nil
}

Use the approver token only after verifying the authenticated human. Approval records authorization; it does not execute the release.

Observe and reflect

func observeAndReflect(
    ctx context.Context,
    httpClient *http.Client,
    baseURL string,
    decision map[string]any,
) error {
    agentToken, err := requiredEnv("NEUTRON_API_TOKEN")
    if err != nil {
        return err
    }
    _, err = postJSON(ctx, httpClient, baseURL, agentToken, "/v1/consequence/observe", scoped(map[string]any{
        "decisionId": decision["decisionId"],
        "scopeIds": []string{"service:checkout-api", "history:checkout-releases"},
        "summary": "The 1% pilot completed without customer errors and was held for review.",
        "observedMetrics": map[string]any{
            "pilot_percent": 1, "pilot_minutes": 30,
            "database_lock_p95_ms": 180, "customer_error_rate": 0,
        },
        "unexpectedConsequences": []string{"Cache warm-up took ten minutes longer than estimated."},
        "sourceRefs": []string{
            "release-run:checkout-3.8-pilot", "dashboard:database-locks-2026-08-15",
        },
    }))
    if err != nil {
        return err
    }
    internalToken, err := requiredEnv("NEUTRON_INTERNAL_TOKEN")
    if err != nil {
        return err
    }
    _, err = postJSON(ctx, httpClient, baseURL, internalToken, "/v1/consequence/reflect", scoped(map[string]any{
        "decisionId": decision["decisionId"],
        "scopeIds": []string{"service:checkout-api", "history:checkout-releases"},
    }))
    return err
}

func main() {
    ctx := context.Background()
    httpClient := &http.Client{Timeout: 30 * time.Second}
    baseURL, err := requiredEnv("NEUTRON_API_URL")
    if err != nil {
        panic(err)
    }
    if _, err := prepareContext(ctx, httpClient, baseURL); err != nil {
        panic(err)
    }
    decision, err := planAndDecide(ctx, httpClient, baseURL)
    if err != nil {
        panic(err)
    }
    if err := observeAndReflect(ctx, httpClient, baseURL, decision); err != nil {
        panic(err)
    }
}

Call observeAndReflect only after a separately authorized action produces trusted evidence, then review the reflection lesson before memory promotion.

Return to the shared lifecycle and production checklist.