agentfactory

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package agentfactory builds ADK-compatible agents from runtime config.

A Factory holds provider definitions plus MCP server lookup and exposes Factory.Build for runtime agent construction. It also exposes Factory.BuildSessionState for canonical session-state initialization that stays stable across provider backends.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildRequest

type BuildRequest struct {
	// AgentID selects a provider entry from the factory registry.
	AgentID string `json:"agent_id" validate:"required,min=1"`
	// Name overrides the runtime agent display name.
	Name string `json:"name,omitempty"`
	// Description overrides the runtime agent description.
	Description string `json:"description,omitempty"`
	// Instruction overrides the provider-specific invocation instruction.
	Instruction string `json:"instruction,omitempty"`
	// GlobalInstruction is prepended ahead of Instruction for each invocation.
	GlobalInstruction string `json:"global_instruction,omitempty"`
	// WorkingDirectory is the session working directory for the built agent.
	WorkingDirectory string `json:"working_directory" validate:"required,min=1"`
	// MCPServerIDs overrides provider-level MCP server references for this build.
	MCPServerIDs []string `json:"mcp_server_ids,omitempty"`
	// SessionID requests a specific remote session identifier when supported.
	SessionID string `json:"session_id,omitempty"`
}

BuildRequest defines the parameters for building a new agent instance.

func (BuildRequest) Validate

func (r BuildRequest) Validate() error

Validate validates the build request.

type Factory

type Factory struct {
	// contains filtered or unexported fields
}

Factory is a registry of agent configurations.

func New

func New(agents map[string]agentconfig.Config, mcp mcpregistry.Reader, opts ...Option) *Factory

New creates a new Factory from agent configurations and an MCP registry.

func (*Factory) Build

func (f *Factory) Build(ctx context.Context, req BuildRequest) (agent.Agent, error)

Build creates an agent.Agent instance from request.

func (*Factory) BuildSessionState

func (f *Factory) BuildSessionState(agentID, workspaceDir string) (map[string]any, error)

BuildSessionState builds canonical ADK session state for runtime sessions.

The returned state is backend-agnostic and currently always includes the canonical per-session working directory at key sessionstate.CWDKey.

Example
workspaceDir, err := os.MkdirTemp("", "runtime-agentfactory-example-*")
if err != nil {
	fmt.Println(err)
	return
}
defer func() { _ = os.RemoveAll(workspaceDir) }()

factory := New(map[string]agentconfig.Config{
	"openai": {
		Type: agentconfig.AgentTypeOpenAI,
		OpenAI: &agentconfig.LocalAPIConfig{
			APIKey: "test-key",
			Model:  "gpt-5",
		},
	},
}, mcpregistry.New(nil))

state, err := factory.BuildSessionState("openai", workspaceDir)
if err != nil {
	fmt.Println(err)
	return
}

cwd, _ := state[sessionstate.CWDKey].(string)
fmt.Println(filepath.IsAbs(cwd))
Output:
true

func (*Factory) GetAgentConfig

func (f *Factory) GetAgentConfig(agentID string) (agentconfig.Config, error)

GetAgentConfig returns the schema configuration for agentID.

func (*Factory) ValidateAgent

func (f *Factory) ValidateAgent(agentID string) error

ValidateAgent checks if an agent with agentID can be built.

type Option

type Option func(*Factory)

Option configures factory behavior.

func WithPermissionHandler

func WithPermissionHandler(handler acpagent.PermissionHandler) Option

WithPermissionHandler configures a default ACP permission callback for all built agents.

func WithStderrWriter

func WithStderrWriter(writer io.Writer) Option

WithStderrWriter configures where ACP subprocess stderr is written.

Jump to

Keyboard shortcuts

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