bridge

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package bridge connects the eval harness to the extension that runs inside the agent process under test.

Pi's harness registers an inline extension and custom tools inside its own process (harness.ts:287-301, 345-355, createAgentSessionFromServices) and keeps the API key in that process's memory. A PiG Session runs as a separate pig process, so the harness serves these over a Unix socket: the system prompt transform, the custom tool executions and the API key. The extension binary (cmd/pig-eval-extension) is the client.

Index

Constants

View Source
const (
	// EnvSocket is the Unix socket the harness serves.
	EnvSocket = "PIG_EVAL_BRIDGE_SOCKET"
	// EnvSpec is the path of the JSON Spec file.
	EnvSpec = "PIG_EVAL_BRIDGE_SPEC"
)

Environment names the variables the harness sets for the extension process.

View Source
const (
	OpTransform = "transform"
	OpTool      = "tool"
	// OpCredential returns the run's API key to the credential command.
	OpCredential = "credential"
)

Operations of a Request.

View Source
const CredentialCommand = "credential"

CredentialCommand is the argument that makes the extension binary print the run's API key and exit. The agent's auth.json names it in a "!" command, so the key never reaches a file.

View Source
const ExtensionName = "pig-eval-extension"

ExtensionName is the registered name of the bridge extension. PiG requires it to equal the extension executable's file name (Pi's inline extension is named "eval-system-prompt-transform", harness.ts:292).

Variables

This section is empty.

Functions

This section is empty.

Types

type ConstrainedSampling

type ConstrainedSampling struct {
	Type   string `json:"type"`
	Strict string `json:"strict,omitempty"`
}

ConstrainedSampling is a provider-side constrained sampling request.

type Request

type Request struct {
	Op           string         `json:"op"`
	SystemPrompt string         `json:"systemPrompt,omitempty"`
	Tool         string         `json:"tool,omitempty"`
	ToolCallID   string         `json:"toolCallId,omitempty"`
	Params       map[string]any `json:"params,omitempty"`
}

Request is one extension-to-harness call.

type Response

type Response struct {
	SystemPrompt string `json:"systemPrompt,omitempty"`
	Content      string `json:"content,omitempty"`
	Details      any    `json:"details,omitempty"`
	Terminate    bool   `json:"terminate,omitempty"`
	Credential   string `json:"credential,omitempty"`
	Error        string `json:"error,omitempty"`
}

Response answers a Request. A non-empty Error is the harness handler's failure.

func Call

func Call(request Request) (Response, error)

Call sends request to the harness and returns its response.

type Spec

type Spec struct {
	// TransformSystemPrompt registers a before_agent_start handler that sends the prompt to the harness.
	TransformSystemPrompt bool   `json:"transformSystemPrompt"`
	Tools                 []Tool `json:"tools"`
}

Spec is what the extension registers at startup.

func LoadSpec

func LoadSpec() (Spec, error)

LoadSpec reads the Spec file named by EnvSpec.

type Tool

type Tool struct {
	Name        string `json:"name"`
	Label       string `json:"label,omitempty"`
	Description string `json:"description"`
	// PromptSnippet is the tool's line in the system prompt's tool list (defineTool promptSnippet).
	PromptSnippet string `json:"promptSnippet,omitempty"`
	// Parameters is the tool's JSON Schema as its author wrote it: the members keep their order across the spec file.
	Parameters schema.Schema `json:"parameters"`
	// ConstrainedSampling is the tool's constrainedSampling request, nil when absent.
	ConstrainedSampling *ConstrainedSampling `json:"constrainedSampling,omitempty"`
}

Tool declares one custom tool the extension registers.

Jump to

Keyboard shortcuts

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