Forge documentation
Go

Go agents

Agents contracts and source references for Go.

AgentConfig contains a concrete core.LanguageModel, tool registry, limits, optional identity and ACT, approval handler, and telemetry. Run(ctx, prompt) returns (*AgentOutput, error); propagate the request context and check the error before dereferencing output. The result exposes FinalText, Messages, StepsTaken, and Usage.

A bounded run

This complete function accepts a model already configured by the caller. No tools are registered. Supply a model supported by your application and handle the returned error or exception at the caller. This example does not provision provider credentials, identity or deployment.

package example

import (
    "context"
    "github.com/l1fe-labs/forge-go/agent"
    "github.com/l1fe-labs/forge-go/core"
    "github.com/l1fe-labs/forge-go/tool"
)

func RunAgent(ctx context.Context, model core.LanguageModel, prompt string) (*agent.AgentOutput, error) {
    instance, err := agent.NewToolLoopAgent(&agent.AgentConfig{
        Name: "reader",
        Model: model,
        MaxSteps: 3,
        ApprovalHandler: tool.DenyAllHandler,
    })
    if err != nil {
        return nil, err
    }
    return instance.Run(ctx, prompt)
}

Go reference

Each reference records the source path, hash and declaration inventory for this language. Start at the import boundary before using a symbol found in a deeper implementation file.

Lifecycle and failures

Choose finite iteration and token budgets, handle generation and execution failures, and release resources on termination. Inspect the returned usage and completion state before recording a successful run. The SDK health/lifecycle object describes local runtime state; it is not a deployment health check.

Continue

On this page