managed

package module
v0.62.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package managed serves a Scope run as an A2A task. StartID derives its root identity; the committed log supplies status, artifacts and outstanding questions. Reading or reconnecting never acquires a writer epoch. Hosts supply authentication and resource authority; the protocol token and message/context IDs are not credentials. If the initial commit has no acknowledgment, retry the same message and context IDs with the same input to reconcile its Started record. Changing the input conflicts with an accepted identity; choosing a new message ID can start separate work.

SendMessage accepts one plain text part or JSON carried losslessly as raw bytes or text. SDK Data values with numbers cannot prove their original precision and are rejected. Files and lossy multi-part conversions are rejected before starting work. Card.DefaultOutputModes owns output encoding, independently of the program's JSON Schemas. Its default is application/json, preserving every result's JSON representation, including quoted strings. Explicit text/plain renders strings as text and other values as their exact JSON text. Declaring both modes uses text/plain for strings and JSON for other values. Questions and final artifacts follow the same frozen policy; clients must accept every declared output mode.

An input-required status lists every pending question, its owner and schema. An absent question projects as JSON null, and an absent answer schema as the unrestricted schema true. Question IDs derive from the committed wait address and runtime root, so reads and writer recovery preserve the same identity. Reply to the task/context with the chosen scope.wait address (process and local key) in message metadata. Repeating a consumed answer reconciles through the committed SignalAdmitted record, even after the original writer exits. CancelTask requests termination and returns the observed status; only an acknowledged terminal head proves it stopped. A different host can read or subscribe but cannot take over to act.

This handler does not provide task enumeration, message history, push notification configuration or an extended card. Hosts own HTTP authentication, transport deadlines, runtime shutdown and durable-store retention.

Index

Examples

Constants

View Source
const (
	// PendingKey lists the questions the tree is waiting on.
	PendingKey = "scope.pending"
	// ProgramKey names the Program reference the task runs.
	ProgramKey = "scope.program"
	// RootKey is the root Process ID.
	RootKey = "scope.root_id"
	// RootStatusKey is the root Process status.
	RootStatusKey = "scope.root_status"
	// TerminationKey is the root's termination cause once it has exited.
	TerminationKey = "scope.termination"
)

Task metadata keys a managed task publishes; clients read each by name.

Variables

This section is empty.

Functions

func NewHTTPHandler

func NewHTTPHandler(cfg Config) (http.Handler, error)

Tasks derive acceptance and lifecycle facts from readable runtime storage; the protocol endpoint cannot maintain an independent task store.

Example
package main

import (
	"context"
	"fmt"

	sdk "github.com/a2aproject/a2a-go/v2/a2a"

	"github.com/Tangerg/scope/a2a/managed"
	"github.com/Tangerg/scope/agent/interaction"
	"github.com/Tangerg/scope/agent/run"
	"github.com/Tangerg/scope/core/chat"
)

func main() {
	ctx := context.Background()
	model := chat.ModelFunc(func(context.Context, *chat.Request) (*chat.Response, error) {
		return &chat.Response{Output: &chat.Output{Message: new(chat.NewAssistantMessage(chat.NewTextPart("Hello"))), FinishReason: chat.FinishReasonStop}}, nil
	})
	runtime, err := run.New(ctx, run.Config{Build: "greeter-example", Store: run.NewMemoryStore()})
	if err != nil {
		panic(err)
	}
	program, err := interaction.Compile(runtime.Compiler(), interaction.Config{Name: "public.greeter", Description: "Answer a greeting", Revision: "example-model", Model: interaction.CallModel(model)})
	if err != nil {
		panic(err)
	}
	defer runtime.Close(ctx)
	// This endpoint is intentionally shared. A private endpoint must derive its
	// authority from the authenticated principal established by HTTP middleware.
	_, err = managed.NewHTTPHandler(managed.Config{Runtime: runtime, Program: program.Erase(), Service: "greeter", Authority: func(context.Context, string) (string, error) { return "public", nil }, Card: &sdk.AgentCard{Name: "greeter", SupportedInterfaces: []*sdk.AgentInterface{sdk.NewAgentInterface("https://agent.example/rpc", sdk.TransportProtocolJSONRPC)}}})
	fmt.Println(err)
}
Output:
<nil>

Types

type Config

type Config struct {
	Runtime *run.Runtime
	// Program fixes the binding used for new submissions. Bind an existing
	// typed program with Program.Erase; its actual input/output schemas remain.
	Program run.Program[run.Payload, run.Payload]
	// Card declares the encoding policy independently of the program's value
	// schemas. DefaultOutputModes defaults to application/json; text/plain
	// renders strings as text and other values as their exact JSON text. When
	// both modes are declared, strings use text/plain and other values use JSON.
	// The same policy encodes questions and artifacts. Clients must accept every
	// declared output mode. Construction freezes the declaration.
	Card *sdk.AgentCard
	// Authority returns a stable server-authorized scope for this authenticated
	// caller and requested tenant. Never return the untrusted tenant verbatim.
	Authority func(ctx context.Context, tenant string) (string, error)
	// Service isolates independently deployed endpoints sharing a runtime store.
	Service string
	// MaxRequestBytes has the meaning of [a2a.ServerConfig.MaxRequestBytes].
	MaxRequestBytes int64
}

Jump to

Keyboard shortcuts

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