agent

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 10 Imported by: 0

README

GoModularAuth Agent Plugin (gomodularauth-agent)

Go Reference

The Agent Plugin provides first-class identity, credential issuance, and capability scoping for autonomous AI agents, LLM tool executors, and Model Context Protocol (MCP) clients.

Installation

go get github.com/BladiCreator/go-modular-auth/plugins/agent

Quick Start

package main

import (
	"context"
	"time"

	auth "github.com/BladiCreator/go-modular-auth"
	adaptermem "github.com/BladiCreator/go-modular-auth/adapters/memory"
	"github.com/BladiCreator/go-modular-auth/plugins/agent"
)

func main() {
	ctx := context.Background()

	engine, _ := auth.New(auth.Config{
		Adapter: adaptermem.NewAdapter(),
		Plugins: []auth.PluginModule{agent.New()},
	})

	mgr, _ := auth.Get[agent.AgentManager](engine)

	// Create an autonomous agent identity
	ag, _ := mgr.CreateAgent(ctx, "usr_owner_1", "CodeAgent", "Autonomous bot", []string{"repo:read"}, nil)

	// Issue an ephemeral credential (mcp_<hex>)
	token, cred, _ := mgr.IssueCredential(ctx, ag.ID, 30*time.Minute)
	_ = token
	_ = cred

	// Validate credential on tool execution
	authedAgent, _, _ := mgr.ValidateCredential(ctx, token)
	_ = authedAgent
}

Detailed guide: doc/plugins/agent.md.

Documentation

Overview

Package agent provides AI and autonomous agent authentication capabilities (reserved module).

Index

Constants

View Source
const (
	ModelAgents           = "agents"
	ModelAgentCredentials = "agent_credentials"
)
View Source
const PluginID = "agent"

Variables

View Source
var (
	ErrNotFound       = errors.New("agent: not found")
	ErrAgentInactive  = errors.New("agent: agent is inactive")
	ErrInvalidToken   = errors.New("agent: token is invalid or expired")
	ErrInvalidOwnerID = errors.New("agent: owner_id is required")
	ErrInvalidName    = errors.New("agent: name is required")
	ErrInvalidTTL     = errors.New("agent: credential ttl must be positive")
)

Functions

func RegisterSchema

func RegisterSchema(s *schema.Schema) error

RegisterSchema registers agent and credential models into the unified schema.

Types

type Agent

type Agent struct {
	ID          string            `json:"id"`
	Name        string            `json:"name"`
	Description string            `json:"description,omitempty"`
	OwnerID     string            `json:"owner_id"`
	Scopes      []string          `json:"scopes"`
	Metadata    map[string]string `json:"metadata,omitempty"`
	Active      bool              `json:"active"`
	CreatedAt   time.Time         `json:"created_at"`
	UpdatedAt   time.Time         `json:"updated_at"`
}

Agent represents an autonomous AI agent or MCP client identity.

type AgentManager

type AgentManager interface {
	CreateAgent(ctx context.Context, ownerID, name, description string, scopes []string, metadata map[string]string) (*Agent, error)
	GetAgent(ctx context.Context, id string) (*Agent, error)
	ListAgents(ctx context.Context, ownerID string) ([]*Agent, error)
	UpdateAgent(ctx context.Context, a *Agent) error
	DeleteAgent(ctx context.Context, id string) error

	IssueCredential(ctx context.Context, agentID string, ttl time.Duration) (string, *Credential, error)
	ValidateCredential(ctx context.Context, token string) (*Agent, *Credential, error)
	RevokeCredential(ctx context.Context, credentialID string) error
}

type Config

type Config struct{}

type Credential

type Credential struct {
	ID        string    `json:"id"`
	AgentID   string    `json:"agent_id"`
	TokenHash string    `json:"token_hash"`
	ExpiresAt time.Time `json:"expires_at"`
	CreatedAt time.Time `json:"created_at"`
}

Credential represents a short-lived token issued to an agent.

type Module

type Module struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *Module

func (*Module) ID

func (m *Module) ID() string

func (*Module) Init

func (m *Module) Init(h *auth.Host) error

func (*Module) RegisterSchema

func (m *Module) RegisterSchema(s *schema.Schema) error

type Option

type Option func(*Config)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL