extension

package
v0.0.30 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package extension provides hooks (before/after tool call), skill loading, and MCP tool integration for the pi-go agent.

Index

Constants

This section is empty.

Variables

View Source
var SkillTemplate string

Functions

func BuildAfterToolCallbacks

func BuildAfterToolCallbacks(hooks []HookConfig) []llmagent.AfterToolCallback

BuildAfterToolCallbacks converts HookConfigs with event "after_tool" into ADK AfterToolCallback functions.

func BuildBeforeToolCallbacks

func BuildBeforeToolCallbacks(hooks []HookConfig) []llmagent.BeforeToolCallback

BuildBeforeToolCallbacks converts HookConfigs with event "before_tool" into ADK BeforeToolCallback functions.

func BuildLLMTracingCallbacks added in v0.0.25

func BuildLLMTracingCallbacks() ([]llmagent.BeforeModelCallback, []llmagent.AfterModelCallback)

BuildLLMTracingCallbacks returns before/after model callbacks that emit OTEL spans for each LLM invocation inside the agent loop.

func BuildMCPToolsets

func BuildMCPToolsets(servers []MCPServerConfig) ([]tool.Toolset, error)

BuildMCPToolsets creates ADK Toolsets from MCP server configurations. Each server is launched as a subprocess using CommandTransport. Servers that fail to initialize are logged and skipped rather than failing the entire batch.

func BuildToolCallCallbacks added in v0.0.25

BuildToolCallCallbacks creates ADK before/after tool callbacks that report tool calls to the ACP peer via s. The BeforeToolCallback emits StartToolCall; the AfterToolCallback emits UpdateToolCall with the result or error.

Correlation: ctx.FunctionCallID() is the ADK-assigned unique identifier for each tool invocation. It is the same value in both the before and after callback, so it is used as the key to carry the ACP call ID (returned by OnToolStart) across the two callbacks. Without this, the result of every tool call would be silently dropped because OnToolEnd would receive an empty call ID and treat it as a no-op.

func BuildTracingCallbacks added in v0.0.25

func BuildTracingCallbacks() ([]llmagent.BeforeToolCallback, []llmagent.AfterToolCallback)

BuildTracingCallbacks returns before/after tool callbacks that emit OTEL spans for every tool invocation. The parent span context is propagated from the context passed to the callback, so spans are linked to the agent's trace.

func DefaultSkillDirs added in v0.0.29

func DefaultSkillDirs() []string

DefaultSkillDirs returns the default skill directories to search. It returns user-level (~/.pi-go/skills) plus project-level directories (.pi-go/skills, .claude/skills, .cursor/skills) found by walking up from the current working directory.

func DefaultSkillDirsIn added in v0.0.29

func DefaultSkillDirsIn(root string) []string

DefaultSkillDirsIn returns skill directories relative to the given root. User-level skill directory (~/.pi-go/skills) plus project-level directories (.pi-go/skills, .claude/skills, .cursor/skills) found by walking up from root.

func LoadBundledSkills added in v0.0.16

func LoadBundledSkills() (map[string][]BundledSkillFile, error)

LoadBundledSkills loads all embedded skill files. Returns a map of skill name → []BundledSkillFile (SKILL.md + supporting files).

Types

type AuditMode added in v0.0.10

type AuditMode string

AuditMode controls how skill loading handles audit findings.

const (
	// AuditBlock blocks skills with critical findings (default).
	AuditBlock AuditMode = "block"
	// AuditWarn loads all skills but logs warnings for critical findings.
	AuditWarn AuditMode = "warn"
	// AuditSkip skips scanning entirely (backward compat for tests).
	AuditSkip AuditMode = "skip"
)

type BundledSkillFile added in v0.0.16

type BundledSkillFile struct {
	SkillName string
	RelPath   string
	Content   []byte
}

BundledSkillFile represents a skill loaded from the embedded filesystem.

type HookConfig

type HookConfig struct {
	// Event is "before_tool" or "after_tool".
	Event string `json:"event"`
	// Command is the shell command to execute.
	Command string `json:"command"`
	// Tools optionally restricts this hook to specific tool names.
	// If empty, the hook fires for all tools.
	Tools []string `json:"tools,omitempty"`
	// Timeout in seconds for hook execution. Default: 10.
	Timeout int `json:"timeout,omitempty"`
}

HookConfig defines a shell command hook that runs before or after tool calls.

type LoadOptions added in v0.0.10

type LoadOptions struct {
	AuditMode AuditMode
}

LoadOptions controls skill loading behavior.

type MCPServerConfig

type MCPServerConfig struct {
	Name    string   `json:"name"`
	Command string   `json:"command,omitempty"`
	Args    []string `json:"args,omitempty"`
	URL     string   `json:"url,omitempty"` // HTTP transport (Streamable HTTP)
}

MCPServerConfig matches the config.MCPServer structure.

type MCPServerStatus added in v0.0.22

type MCPServerStatus struct {
	Name      string
	Connected bool   // true if Tools() succeeded at least once
	Failed    bool   // true if Tools() timed out or returned an error
	ToolCount int    // number of tools reported; 0 if not yet loaded
	Status    string // "connected", "failed", "pending"
}

func ToolsetStatuses added in v0.0.22

func ToolsetStatuses(toolsets []tool.Toolset) []MCPServerStatus

ToolsetStatuses returns the current status for each toolset that was created by BuildMCPToolsets. Toolsets that haven't been queried yet are reported as "pending".

type MCPToolEntry added in v0.0.22

type MCPToolEntry struct {
	Server string
	Tool   string
}

MCPToolEntry is a single resolved tool from a named MCP server.

func BuildMCPToolEntries added in v0.0.22

func BuildMCPToolEntries(toolsets []tool.Toolset) []MCPToolEntry

BuildMCPToolEntries returns a flat list of {Server, Tool} pairs for all connected MCP toolsets. Only toolsets whose tools have already been loaded (via a previous Tools() call) contribute entries — pending/failed servers are silently skipped.

type Skill

type Skill struct {
	// Name is the skill's identifier (derived from directory name).
	Name string
	// Description is a one-line description from frontmatter.
	Description string
	// Instruction is the markdown body (the system prompt to inject).
	Instruction string
	// Tools lists tool names this skill is allowed to use (from frontmatter).
	Tools []string
	// Source is where the skill came from: "bundled", "user", or "project".
	Source string
}

Skill represents a loaded skill from a SKILL.md file.

func FindSkill

func FindSkill(skills []Skill, name string) (Skill, bool)

FindSkill looks up a skill by name from a slice of loaded skills.

func LoadSkills

func LoadSkills(dirs ...string) ([]Skill, error)

LoadSkills discovers and loads skills from the given directories. It searches for <dir>/<skill-name>/SKILL.md subdirectories. Later directories override earlier ones (project overrides global). Skills with critical audit findings are blocked when AuditMode is "block" (default).

func LoadSkillsWithOptions added in v0.0.10

func LoadSkillsWithOptions(opts LoadOptions, dirs ...string) ([]Skill, error)

LoadSkillsWithOptions discovers and loads skills with configurable audit behavior. Bundled skills (embedded in the binary) are loaded first and can be overridden by user or project skills.

type ToolCallReporter added in v0.0.25

type ToolCallReporter interface {
	OnToolStart(ctx context.Context, name string, args map[string]any) (string, error)
	OnToolEnd(ctx context.Context, callID string, args map[string]any, result any, runErr error) error
}

ToolCallReporter is the interface that adapter.Stream exposes for reporting tool call lifecycle events to the ACP peer. This allows BuildToolCallCallbacks to bridge ADK Before/AfterToolCallbacks → ACP StartToolCall/UpdateToolCall.

Jump to

Keyboard shortcuts

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