Skip to main content
These workflows assume ROE_API_KEY and ROE_ORGANIZATION_ID are set. The first example provisions a policy and an agent from scratch; the later two reuse an existing agent id so they stay focused on the run-and-fetch calls.

Create a policy and run a policy-aware agent

package main

import (
    "fmt"
    "log"
    "os"
    "time"

    roe "github.com/roe-ai/roe-golang"
)

func main() {
    client, err := roe.NewClient(os.Getenv("ROE_API_KEY"), os.Getenv("ROE_ORGANIZATION_ID"), "", 0, 0)
    if err != nil {
        log.Fatal(err)
    }
    defer client.Close()

    policy, err := client.Policies.Create("AML Investigation Policy", map[string]any{
        "guidelines": map[string]any{
            "categories": []map[string]any{
                {
                    "title": "Transaction Patterns",
                    "rules": []map[string]any{
                        {
                            "title":       "Structuring below reporting thresholds",
                            "flag":        "RED_FLAG",
                            "description": "Deposits just under CTR thresholds in a short window.",
                        },
                    },
                },
            },
        },
        "dispositions": map[string]any{
            "classifications": []map[string]any{
                {"name": "SAR", "description": "File a Suspicious Activity Report."},
                {"name": "DISMISS", "description": "Close as non-suspicious."},
            },
        },
    }, "", "")
    if err != nil {
        log.Fatal(err)
    }

    agent, err := client.Agents.Create(
        "AML Investigation Agent",
        "AMLInvestigationEngine",
        []map[string]any{{"key": "alert_data", "data_type": "text/plain", "description": "Alert to investigate."}},
        map[string]any{"policy_version_id": *policy.CurrentVersionID, "alert_data": "${alert_data}"},
        "", "",
    )
    if err != nil {
        log.Fatal(err)
    }

    job, err := client.Agents.Run(agent.ID, 300, map[string]any{
        "alert_data": "Customer made 9 cash deposits of $9,500 over three days.",
    }, nil)
    if err != nil {
        log.Fatal(err)
    }

    result, err := job.Wait(5*time.Second, 5*time.Minute)
    if err != nil {
        log.Fatal(err)
    }

    for _, output := range result.Outputs {
        fmt.Printf("%s: %s\n", output.Key, output.Value)
    }
}

Run an agent and download a saved reference

package main

import (
    "encoding/json"
    "log"
    "os"
    "time"

    roe "github.com/roe-ai/roe-golang"
)

type reference struct {
    ResourceID string `json:"resource_id"`
}

func main() {
    client, err := roe.NewClient(os.Getenv("ROE_API_KEY"), os.Getenv("ROE_ORGANIZATION_ID"), "", 0, 0)
    if err != nil {
        log.Fatal(err)
    }
    defer client.Close()

    agentID := os.Getenv("ROE_URL_AGENT_ID")
    if agentID == "" {
        log.Fatal("Set ROE_URL_AGENT_ID")
    }

    job, err := client.Agents.Run(agentID, 300, map[string]any{"url": "https://www.roe-ai.com/"}, map[string]any{"use_case": "website-scan"})
    if err != nil {
        log.Fatal(err)
    }

    result, err := job.Wait(5*time.Second, 5*time.Minute)
    if err != nil {
        log.Fatal(err)
    }

    for _, output := range result.Outputs {
        for _, ref := range referencesFrom(output.Value) {
            content, err := client.Agents.Jobs.DownloadReference(job.ID(), ref.ResourceID, false)
            if err != nil {
                log.Fatal(err)
            }
            if err := os.WriteFile(ref.ResourceID+".bin", content, 0644); err != nil {
                log.Fatal(err)
            }
        }
    }
}

func referencesFrom(value string) []reference {
    var payload struct {
        References []reference `json:"references"`
    }
    if err := json.Unmarshal([]byte(value), &payload); err != nil {
        return nil
    }
    return payload.References
}

Run a batch of inputs

package main

import (
    "fmt"
    "log"
    "os"
    "time"

    roe "github.com/roe-ai/roe-golang"
)

func main() {
    client, err := roe.NewClient(os.Getenv("ROE_API_KEY"), os.Getenv("ROE_ORGANIZATION_ID"), "", 0, 0)
    if err != nil {
        log.Fatal(err)
    }
    defer client.Close()

    agentID := os.Getenv("ROE_TEXT_AGENT_ID")
    if agentID == "" {
        log.Fatal("Set ROE_TEXT_AGENT_ID")
    }

    batch, err := client.Agents.RunMany(agentID, []map[string]any{
        {"text": "Summarize the customer complaint."},
        {"text": "Extract the requested follow-up action."},
    }, 300, nil)
    if err != nil {
        log.Fatal(err)
    }

    results, err := batch.Wait(5*time.Second, 5*time.Minute)
    if err != nil {
        log.Fatal(err)
    }

    for _, result := range results {
        for _, output := range result.Outputs {
            fmt.Printf("%s: %s\n", output.Key, output.Value)
        }
    }
}