gogent

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: MIT Imports: 8 Imported by: 0

README

gogent

Framework for ai agents on go (openai)

telegram-cloud-photo-size-2-5458393535154882991-y

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent struct {
	Config AgentConfig

	Handoff Handoff
	// contains filtered or unexported fields
}

Agent represents an OpenAI agent that can perform tasks

func NewAgent

func NewAgent(config AgentConfig) *Agent

NewAgent creates a new agent with the given configuration

func (*Agent) AddMessage

func (a *Agent) AddMessage(ctx context.Context, thread *Thread, message Message) error

AddMessage adds a message to a thread

func (*Agent) AddMessageWithUser

func (a *Agent) AddMessageWithUser(ctx context.Context, thread *Thread, message Message, userID string) error

AddMessageWithUser adds a message to a thread with user identification

func (*Agent) AddMessageWithoutSaving

func (a *Agent) AddMessageWithoutSaving(ctx context.Context, thread *Thread, message Message, userID string) error

AddMessageWithoutSaving adds a message to a thread without saving to repository

func (*Agent) CancelRun

func (a *Agent) CancelRun(ctx context.Context, run *Run) error

CancelRun cancels a running run

func (*Agent) CreateRun

func (a *Agent) CreateRun(ctx context.Context, thread *Thread) (*Run, error)

CreateRun creates a new run on a thread

func (*Agent) CreateThread

func (a *Agent) CreateThread(ctx context.Context, messages []Message, metadata map[string]interface{}) (*Thread, error)

CreateThread creates a new conversation thread

func (*Agent) CreateThreadWithUser

func (a *Agent) CreateThreadWithUser(ctx context.Context, userID string, messages []Message, metadata map[string]interface{}) (*Thread, error)

CreateThreadWithUser creates a new conversation thread with user identification

func (*Agent) DelegateToChild

func (a *Agent) DelegateToChild(ctx context.Context, target string, input *Message, metadata map[string]interface{}) (map[string]interface{}, error)

DelegateToChild performs a programmatic handoff to a registered child agent and returns the child's final response.

func (*Agent) ExecuteRun

func (a *Agent) ExecuteRun(ctx context.Context, run *Run, thread *Thread) error

ExecuteRun executes a run synchronously

func (*Agent) ExecuteRunWithRepository

func (a *Agent) ExecuteRunWithRepository(ctx context.Context, run *Run, thread *Thread, userID string, repo interface{}) error

ExecuteRunWithRepository executes a run synchronously and saves messages to repository

func (*Agent) GetChild

func (a *Agent) GetChild(name string) (*Agent, bool)

GetChild retrieves a registered child agent by name

func (*Agent) RegisterChild

func (a *Agent) RegisterChild(name string, child *Agent)

RegisterChild registers a child agent by name for handoffs

func (*Agent) SetClient

func (a *Agent) SetClient(client *LLMClient)

SetClient sets the LLM client for the agent

func (*Agent) SetDescription

func (a *Agent) SetDescription(s string)

SetDescription sets the Description for the agent

func (*Agent) SetSystemPrompt

func (a *Agent) SetSystemPrompt(s string)

SetSystemPrompt sets the SystemPrompt for the agent

func (*Agent) StreamRun

func (a *Agent) StreamRun(ctx context.Context, run *Run, thread *Thread, callback func(Message) error) error

StreamRun executes a run and streams the results

type AgentConfig

type AgentConfig struct {
	Model       string                 `json:"model"`
	Tools       []Tool                 `json:"tools"`
	MaxSteps    int                    `json:"max_steps"`
	Temperature float64                `json:"temperature"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

AgentConfig holds configuration for an agent

type Config

type Config struct {
	OpenAI OpenAIConfig
}

type Handoff

type Handoff struct {
	Enabled  bool     `json:"enabled"`
	Children []string `json:"children,omitempty"`
}

Handoff contains configuration/state for agent-to-agent delegation (not a tool)

type LLMClient

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

Client represents an LLM client that can generate responses

func NewClient

func NewClient(cfg *Config) *LLMClient

NewClient creates a new LLM client with the given configuration

func (*LLMClient) ExecuteToolCalls

func (c *LLMClient) ExecuteToolCalls(ctx context.Context, message *Message, tools []Tool) error

ExecuteToolCalls executes the tool calls in a message

func (*LLMClient) GenerateResponse

func (c *LLMClient) GenerateResponse(ctx context.Context, thread *Thread, tools []Tool) (*Message, error)

GenerateResponse generates a response from the LLM based on the thread messages

type Message

type Message struct {
	Role         string                 `json:"role"` // "user", "assistant", "system", "tool"
	Content      string                 `json:"content"`
	MultiContent openai.ChatMessagePart `json:"multiContent"`
	ToolCalls    []ToolCall             `json:"tool_calls,omitempty"`
	ToolCallID   string                 `json:"tool_call_id,omitempty"` // Used for tool messages
	Metadata     map[string]interface{} `json:"metadata,omitempty"`
	CreatedAt    time.Time              `json:"created_at"`
}

Message represents a message in a conversation

type OpenAIConfig

type OpenAIConfig struct {
	APIKey          string
	VisionModelName string
	ThinkingModel   string
}

type Run

type Run struct {
	ID        string                 `json:"id"`
	ThreadID  string                 `json:"thread_id"`
	Status    RunStatus              `json:"status"`
	Tools     []Tool                 `json:"tools"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
	CreatedAt time.Time              `json:"created_at"`
	StartedAt *time.Time             `json:"started_at,omitempty"`
	EndedAt   *time.Time             `json:"ended_at,omitempty"`
}

Run represents an execution of an agent on a thread

type RunStatus

type RunStatus string

RunStatus represents the status of a run

const (
	RunStatusQueued     RunStatus = "queued"
	RunStatusInProgress RunStatus = "in_progress"
	RunStatusCompleted  RunStatus = "completed"
	RunStatusFailed     RunStatus = "failed"
	RunStatusCancelled  RunStatus = "cancelled"
)

type Thread

type Thread struct {
	ID        string                 `json:"id"`
	Messages  []Message              `json:"messages"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
	CreatedAt time.Time              `json:"created_at"`
}

Thread represents a conversation thread

type Tool

type Tool struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	Parameters  map[string]interface{} `json:"parameters"`
	Function    func(ctx context.Context, params map[string]interface{}) (interface{}, error)
}

Tool represents a function that an agent can use to interact with external systems

type ToolCall

type ToolCall struct {
	ID        string                 `json:"id"`
	ToolName  string                 `json:"tool_name"`
	Arguments map[string]interface{} `json:"arguments"`
	Output    string                 `json:"output,omitempty"`
}

ToolCall represents a call to a tool by the agent

Jump to

Keyboard shortcuts

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