sdk

module
v0.0.89 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: GPL-3.0

README

Grateful Agents SDK

A Go toolkit for embedding tool-using AI agents in your application. The runner is small, provider-neutral, and host-driven: your code stays in charge of credentials, persistence, UI, approvals, policy, and deployment.

Builds and tests with Go 1.26.3.

Install

go get github.com/gratefulagents/sdk

Hello World

package main

import (
	"context"
	"fmt"

	"github.com/gratefulagents/sdk/pkg/agentsdk"
	sdkopenai "github.com/gratefulagents/sdk/pkg/agentsdk/providers/openai"
)

func main() {
	provider := sdkopenai.NewProviderWithConfig(sdkopenai.ProviderConfig{
		APIKey: "<your-api-key>",
	})
	runner := agentsdk.NewRunnerWithProvider(provider)

	result, err := runner.Run(context.Background(), &agentsdk.Agent{
		Name:         "hello",
		Model:        sdkopenai.DefaultChatModel,
		Instructions: "Reply with exactly: hello world",
	}, []agentsdk.RunItem{{
		Type:    agentsdk.RunItemMessage,
		Message: &agentsdk.MessageOutput{Text: "Say hello world."},
	}}, agentsdk.RunConfig{MaxTurns: 1})
	if err != nil {
		panic(err)
	}

	fmt.Println(result.FinalText())
}

Features

Each feature links to a focused doc with a runnable example.

Feature What it does
Agent runtime Multi-turn loop with tools, handoffs, approvals, retries, usage, and hooks.
Model abstraction Custom Model/ModelProvider, MultiProvider, and provider-prefixed routing.
Providers OpenAI (Responses/Chat), OpenAI OAuth, Anthropic API key/OAuth, OpenRouter, local gateways.
Tools FunctionTool, JSON schemas, approvals, and tool policies.
Tool registry Permission-aware built-in tools: shell, fs, search, git, LSP, web, and more.
MCP Load .mcp.json stdio servers and expose their tools and resources.
Sandbox Subprocess execution with a configurable, fail-closed boundary.
ChatLoop Conversation helper for interactive multi-turn sessions.
Handoffs & sub-agents Agent handoffs, Agent.AsTool, specialists, and async sub-agent tasks.
Guardrails Input/output/tool guardrails with destructive-command and secret rules.
Structured output JSON-schema prompting, validation, and custom parsing.
Streaming Raw model deltas, run-item events, and final streamed result.
Context compaction Local and provider-native history compaction with carry-forward guards.
Settings & routing Reasoning/verbosity settings, mode routing, and role overrides.
Observability Run/agent hooks, progress tracking, event streams, and request snapshots.
Errors & retries Typed run errors, retry policy, and capped retry-after delays.
Costs Usage mapping and per-provider cost estimation.
Policy Permission and access-clamping primitives.
Memory Optional memory stores and embedders.
Trace store Filesystem trace persistence and OpenTelemetry bridging.

Run every feature example offline:

GRATEFUL_LIVE_TESTS=skip go test ./examples/features/...

Documentation

Testing

GRATEFUL_LIVE_TESTS=skip go test ./...   # deterministic, offline
go vet ./...
make verify-sdk-purity

Live example tests skip when credentials are missing. Set GRATEFUL_LIVE_TESTS=required to fail instead.

Contributing

See CONTRIBUTING.md. Report security issues via SECURITY.md, not public issues.

License

GPL-3.0-only. See LICENSE.

Directories

Path Synopsis
cmd
examples
features/internal/liveanthropic
Package liveanthropic provides a shared Anthropic-backed runner for feature-example tests.
Package liveanthropic provides a shared Anthropic-backed runner for feature-example tests.
features/internal/liveopenai
Package liveopenai provides a shared OpenAI OAuth-backed runner for feature-example tests.
Package liveopenai provides a shared OpenAI OAuth-backed runner for feature-example tests.
features/internal/liveopenrouter
Package liveopenrouter provides a shared OpenRouter-backed runner for feature-example tests.
Package liveopenrouter provides a shared OpenRouter-backed runner for feature-example tests.
features/internal/liverunner
Package liverunner is the central provider-dispatch helper used by every feature-example test.
Package liverunner is the central provider-dispatch helper used by every feature-example test.
features/internal/livetest
Package livetest centralizes live-test gating for feature examples.
Package livetest centralizes live-test gating for feature examples.
internal
modelactivity
Package modelactivity carries an optional per-call model stream activity callback through context.
Package modelactivity carries an optional per-call model stream activity callback through context.
modeldelta
Package modeldelta carries an optional per-call sink for streamed model reasoning text through context.
Package modeldelta carries an optional per-call sink for streamed model reasoning text through context.
pkg
agentsdk
Package agentsdk exposes the reusable agent runtime.
Package agentsdk exposes the reusable agent runtime.
agentsdk/host
Package host exposes the SDK host-boundary interfaces used by ChatLoop.
Package host exposes the SDK host-boundary interfaces used by ChatLoop.
agentsdk/host/fileconfig
Package fileconfig provides file-backed SDK host configuration.
Package fileconfig provides file-backed SDK host configuration.
agentsdk/mode
Package mode defines the SDK-native mode template shape.
Package mode defines the SDK-native mode template shape.
agentsdk/modelsdev
Package modelsdev resolves per-model context-window limits from the models.dev open catalog (https://models.dev/api.json).
Package modelsdev resolves per-model context-window limits from the models.dev open catalog (https://models.dev/api.json).
agentsdk/projectstate
Package projectstate implements durable, event-sourced project state for agents: typed tasks, typed long-term memories, session summaries, and a prime-context builder.
Package projectstate implements durable, event-sourced project state for agents: typed tasks, typed long-term memories, session summaries, and a prime-context builder.
agentsdk/providers
Package providers contains SDK provider wiring for common model backends.
Package providers contains SDK provider wiring for common model backends.
agentsdk/providers/anthropic
Package anthropic exposes the Anthropic provider and client helpers as part of the public agent SDK surface.
Package anthropic exposes the Anthropic provider and client helpers as part of the public agent SDK surface.
agentsdk/providers/oauth
Package oauth exposes provider OAuth material parsing and refresh helpers.
Package oauth exposes provider OAuth material parsing and refresh helpers.
agentsdk/providers/openai
Package openai exposes the OpenAI-compatible provider, client, and auth helpers as part of the public agent SDK surface.
Package openai exposes the OpenAI-compatible provider, client, and auth helpers as part of the public agent SDK surface.

Jump to

Keyboard shortcuts

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