ModelBox Open Source

/

AgentKit
Getting Started/Quick Start

Quick Start

Build your first AgentKit agent in 5 minutes

|

This guide will help you create your first AgentKit agent in under 5 minutes.

Prerequisites

Step 1: Set up your environment

First, set your OpenAI API key:

export OPENAI_API_KEY="your-openai-api-key"

Step 2: Create your first agent

Create a new file called main.go:

package main

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

    "github.com/model-box/agent-kit/agent"
    "github.com/model-box/agent-kit/model"
    "github.com/model-box/agent-kit/session"
)

func main() {
    // Create model
    model := model.Model("gpt-4o").
        SetAPIKey(os.Getenv("OPENAI_API_KEY"))
    
    // Create agent
    ag := agent.New().
        SetModel(model).
        SetSystemPrompt("You are a helpful assistant.")
    
    // Create session and run
    sess := session.New(ag)
    result, err := sess.Run(context.Background(), []agent.ChatMessage{
        agent.NewUserMessage("Hello, world!"),
    }, nil)
    if err != nil {
        log.Fatal(err)
    }
    
    fmt.Println(result.FinalOutput)
}

Step 3: Run your agent

go run main.go

You should see your agent respond to your greeting!

Step 4: Try a conversation

Let's make it more interactive by adding a simple conversation loop:

package main

import (
    "bufio"
    "context"
    "fmt"
    "log"
    "os"
    "strings"

    "github.com/model-box/agent-kit/agent"
    "github.com/model-box/agent-kit/model"
    "github.com/model-box/agent-kit/session"
)

func main() {
    // Create model
    model := model.Model("gpt-4o").
        SetAPIKey(os.Getenv("OPENAI_API_KEY"))
    
    // Create agent
    ag := agent.New().
        SetModel(model).
        SetSystemPrompt("You are a helpful assistant.")

    // Create a conversation session
    sess := session.New(ag)
    
    fmt.Println("🤖 ChatBot: Hello! I'm your AI assistant. Type 'quit' to exit.")
    
    scanner := bufio.NewScanner(os.Stdin)
    ctx := context.Background()
    
    for {
        fmt.Print("👤 You: ")
        if !scanner.Scan() {
            break
        }
        
        input := strings.TrimSpace(scanner.Text())
        if input == "quit" {
            fmt.Println("🤖 ChatBot: Goodbye!")
            break
        }
        
        if input == "" {
            continue
        }
        
        // Send message to agent
        result, err := sess.Run(ctx, []agent.ChatMessage{agent.NewUserMessage(input)}, nil)
        if err != nil {
            log.Printf("Error: %v", err)
            continue
        }
        
        fmt.Printf("🤖 ChatBot: %s\n\n", result.FinalOutput)
    }
}

Run this version to have a back-and-forth conversation with your agent!

What's Next?

Congratulations! 🎉 You've built your first AgentKit agent. Here's what you can explore next:

Learn Core Concepts

  • Agents - Learn about agent configuration
  • Models - Explore different model providers
  • Tools - Add function calling capabilities
  • Sessions - Manage conversation state

Follow Guides

Explore Examples

Need Help?

Edit on GitHub