forgeagent

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT, AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package forgeagent wires forge-agent into a Forge application. It exposes AgentJob as a Forge content type, which gives it full lifecycle management (Draft → Published → Archived) and auto-generated MCP tools (create_agent_job, get_agent_job, list_agent_jobs, update_agent_job, publish_agent_job, archive_agent_job, delete_agent_job).

Usage:

db := forge.OpenDB("forge.db")
forgeagent.CreateTable(db)

agentMod := forgeagent.New(db, forgeagent.Config{
    MCPURL:   "http://localhost:8080/mcp",
    MCPToken: os.Getenv("FORGE_TOKEN"),
})
agentMod.Register(app)
defer agentMod.Stop()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTable

func CreateTable(db forge.DB) error

CreateTable creates the agent_jobs table if it does not already exist. Call this once at application startup before New.

Types

type AgentJob

type AgentJob struct {
	forge.Node
	// Name is the human-readable identifier for this job. Used as the slug source.
	Name string `forge:"required"`
	// Trigger is a 5-field cron expression or a forge.Signal string value.
	Trigger string `forge:"required"`
	// ContentTypeFilter restricts signal-triggered jobs to the named content type.
	// Empty matches all types. Ignored for cron triggers.
	ContentTypeFilter string `db:"content_type_filter" json:"content_type_filter"`
	// SystemPrompt is the agent's system instruction, prepended to every run.
	SystemPrompt string `forge:"required" db:"system_prompt" json:"system_prompt"`
	// Model is the Anthropic model ID. Defaults to "claude-sonnet-4-6" when empty.
	Model string
	// MaxTurns is the maximum tool-use loops per run. Defaults to 10 when zero.
	MaxTurns int `db:"max_turns" json:"max_turns"`
	// WebhookURL is an optional output channel. When set, the agent's task
	// prompt includes an instruction to POST output here via http_post.
	WebhookURL string `db:"webhook_url" json:"webhook_url"`
}

AgentJob is a Forge Node module representing a scheduled or signal-triggered agent task. Published jobs are active; Draft and Archived jobs do not run.

Trigger is either a 5-field cron expression (e.g. "45 13 * * *") or the string value of a forge.Signal constant (e.g. "after_publish"). The distinction is by whitespace: cron expressions contain spaces; signal names do not.

Set ContentTypeFilter to restrict a signal-triggered job to a specific content type (e.g. "Post"). An empty ContentTypeFilter matches all content types — including other AgentJobs. Use ContentTypeFilter whenever the trigger is a content lifecycle signal to avoid unintended cross-job activation.

func (*AgentJob) ContentTitle

func (j *AgentJob) ContentTitle() string

ContentTitle implements forge.Titled so signal events carry the job name.

type Config

type Config struct {
	// MCPURL is the forge-mcp endpoint (e.g. "http://localhost:8080/mcp").
	MCPURL string
	// MCPToken is a forge token with Author-or-higher role for agent MCP calls.
	MCPToken string
	// StreamableHTTP switches the MCP client from SSE to Streamable HTTP transport.
	// Use true when connecting to forge-mcp; false for SSE-only servers.
	StreamableHTTP bool
}

Config holds the connection settings passed to every agent run.

type Module

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

Module integrates forge-agent with a Forge application. It registers AgentJob as a content type, subscribes to the signal bus, and manages a gocron scheduler for cron-triggered jobs.

Call New to create the module, Module.Register to wire it into the app, and Module.Stop in the application's shutdown handler.

func New

func New(db forge.DB, cfg Config) *Module

New creates a Module backed by db with the given agent Config. Call CreateTable before New so the agent_jobs table exists.

func (*Module) Register

func (m *Module) Register(app *forge.App)

Register wires the module into app: registers the AgentJob content type (HTTP routes + MCP tools), subscribes to the signal bus for signal-triggered jobs, and starts the cron scheduler from currently published jobs.

Call Register after all other content modules have been registered with app so that signal subscriptions are established before app.Run().

func (*Module) Stop

func (m *Module) Stop()

Stop gracefully shuts down the cron scheduler. Call this in the application's shutdown handler.

Jump to

Keyboard shortcuts

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