Skip to main content

Go SDK Examples

Complete End-to-End Example

This example shows the full workflow: creating an agent, running a job, and getting results.
package main

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

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

// Set your credentials as environment variables:
// export ROE_API_KEY="your-api-key-here"
// export ROE_ORGANIZATION_ID="your-organization-uuid"

func main() {
    // Initialize the client
    client, err := roe.NewClient(
        os.Getenv("ROE_API_KEY"),
        os.Getenv("ROE_ORGANIZATION_ID"),
        "", // base URL (optional)
        0,  // timeout (optional)
        0,  // max retries (optional)
    )
    if err != nil {
        log.Fatalf("Failed to create client: %v", err)
    }
    defer client.Close()

    ctx := context.Background()

    // Step 1: Create an agent
    fmt.Println("Creating agent...")
    agent, err := client.Agents.CreateWithContext(
        ctx,
        "Document Analyzer",
        "MultimodalExtractionEngine",
        []map[string]any{
            {
                "key":         "text",
                "data_type":   "text/plain",
                "description": "Text to analyze",
            },
        },
        map[string]any{
            "model":       "gpt-5.2-2025-12-11",
            "instruction": "Analyze the provided text and extract key insights.",
            "output_schema": map[string]any{
                "type": "object",
                "properties": map[string]any{
                    "summary": map[string]any{
                        "type":        "string",
                        "description": "Brief summary of the text",
                    },
                    "key_insights": map[string]any{
                        "type": "array",
                        "items": map[string]any{
                            "type": "string",
                        },
                        "description": "Key insights from the analysis",
                    },
                    "sentiment": map[string]any{
                        "type":        "string",
                        "description": "Overall sentiment (positive/negative/neutral)",
                    },
                },
                "required": []string{"summary", "key_insights", "sentiment"},
            },
        },
        "v1",
        "Initial version of document analyzer",
    )
    if err != nil {
        log.Fatalf("Failed to create agent: %v", err)
    }

    fmt.Printf("✓ Created agent: %s\n", agent.Name)
    fmt.Printf("  Agent ID: %s\n", agent.ID)
    fmt.Printf("  Version ID: %s\n", agent.CurrentVersionID)

    // Step 2: Run the agent with sample input
    fmt.Println("\nRunning agent job...")
    job, err := client.Agents.RunWithContext(ctx, agent.ID, 0, map[string]any{
        "text": "Artificial intelligence is transforming industries worldwide. " +
            "Companies are leveraging AI to improve efficiency, reduce costs, " +
            "and create innovative products. However, ethical considerations " +
            "around data privacy and bias remain critical challenges.",
    })
    if err != nil {
        log.Fatalf("Failed to run agent: %v", err)
    }

    fmt.Printf("  Job ID: %s\n", job.ID)

    // Step 3: Wait for results
    fmt.Println("  Waiting for results...")
    result, err := job.WaitContext(ctx, 0, 0)
    if err != nil {
        log.Fatalf("Failed to get results: %v", err)
    }

    // Step 4: Display results
    fmt.Println("\n✓ Job completed successfully!")
    fmt.Println("\nResults:")
    for _, output := range result.Outputs {
        fmt.Printf("  %s: %v\n", output.Key, output.Value)
    }

    fmt.Printf("\n✓ Job completed in %.2f seconds\n", result.DurationSeconds)
}

Authentication

Set credentials as environment variables:
export ROE_API_KEY="your-api-key-here"
export ROE_ORGANIZATION_ID="your-organization-uuid"

Quick Start

package main

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

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

func main() {
    client, err := roe.NewClient(
        os.Getenv("ROE_API_KEY"),
        os.Getenv("ROE_ORGANIZATION_ID"),
        "", // base URL (optional)
        0,  // timeout (optional)
        0,  // max retries (optional)
    )
    if err != nil {
        log.Fatal(err)
    }
    defer client.Close()

    // Run an agent
    job, err := client.Agents.Run("agent-uuid", 0, map[string]any{
        "text": "Hello world",
    })
    if err != nil {
        log.Fatal(err)
    }

    result, err := job.Wait(0, 0)
    if err != nil {
        log.Fatal(err)
    }

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

Batch Processing

inputs := []map[string]any{
    {"text": "Analyze sentiment: I love this!"},
    {"text": "Analyze sentiment: This is terrible."},
}

batch, err := client.Agents.RunMany("agent-uuid", inputs)
if err != nil {
    log.Fatal(err)
}

results, err := batch.Wait(0, 0)
if err != nil {
    log.Fatal(err)
}

for _, result := range results {
    fmt.Println(result.Outputs)
}

File Uploads

// File path (auto-upload)
job, err := client.Agents.Run("agent-uuid", 0, map[string]any{
    "document": "path/to/file.pdf",
    "text": "Analyze this document",
})

// Existing Roe file ID
job, err := client.Agents.Run("agent-uuid", 0, map[string]any{
    "document": "file-uuid-here",
    "text": "Analyze this document",
})