Documentation
¶
Overview ¶
Package agent provides a Go harness for building model-backed agents, registering tools, managing memory, and composing teams and workflows.
Start with New and Harness.NewAgent for the common path. The model, memory, tool, engine, workflow, security, types, and mcp subpackages expose extension points for applications that need custom implementations or direct access.
Index ¶
- func ResolveModelDefaults(cfg *ModelConfig)
- type Config
- type Harness
- func (h *Harness) Agent(name string) (*engine.Agent, bool)
- func (h *Harness) AllowPermissions(permissions ...security.Permission)
- func (h *Harness) CheckPermission(permission security.Permission) error
- func (h *Harness) Close() error
- func (h *Harness) Config() Config
- func (h *Harness) CreateAgent(name, systemPrompt string) (*engine.Agent, error)
- func (h *Harness) CreateAgentWithTools(name, systemPrompt string, toolNames ...string) (*engine.Agent, error)
- func (h *Harness) CreateTeam(cfg workflow.TeamConfig) (*workflow.Team, error)
- func (h *Harness) CreateWorkflow(cfg workflow.WorkflowConfig) (*workflow.Workflow, error)
- func (h *Harness) DenyPermissions(permissions ...security.Permission)
- func (h *Harness) InitMCPClients(ctx context.Context) error
- func (h *Harness) Model() model.Model
- func (h *Harness) NewAgent(name, systemPrompt string) *engine.Agent
- func (h *Harness) NewTask(options taskpkg.Options) (*Task, error)
- func (h *Harness) NewTeam(cfg workflow.TeamConfig) *workflow.Team
- func (h *Harness) NewWorkflow(cfg workflow.WorkflowConfig) *workflow.Workflow
- func (h *Harness) RegisterAgent(runtimeAgent *engine.Agent) error
- func (h *Harness) RegisterTeam(team *workflow.Team) error
- func (h *Harness) RegisterTool(runtimeTool tool.Tool) error
- func (h *Harness) RegisterWorkflow(runtimeWorkflow *workflow.Workflow) error
- func (h *Harness) RestoreTask(input taskpkg.RestoreInput, sink taskpkg.EventSink) (*Task, error)
- func (h *Harness) RunAgent(ctx context.Context, name, input string, options ...engine.RunOption) *engine.RunOutput
- func (h *Harness) RunTeam(ctx context.Context, name, input string) *workflow.TeamOutput
- func (h *Harness) RunWorkflow(ctx context.Context, name, input string) *workflow.WorkflowResult
- func (h *Harness) Sanitize(input string) string
- func (h *Harness) Team(name string) (*workflow.Team, bool)
- func (h *Harness) ToolRegistry() *tool.Registry
- func (h *Harness) ValidateInput(input string) error
- func (h *Harness) ValidateOutput(output string) error
- func (h *Harness) Workflow(name string) (*workflow.Workflow, bool)
- type MCPClientConfig
- type MemoryConfig
- type ModelConfig
- type Option
- func WithInputValidator(validator security.InputValidator) Option
- func WithLogger(logger *slog.Logger) Option
- func WithMCPClient(name string, client *mcp.Client) Option
- func WithModel(runtimeModel model.Model) Option
- func WithOutputValidator(validator security.OutputValidator) Option
- func WithPermissionManager(manager security.PermissionManager) Option
- func WithSanitizer(sanitizer security.Sanitizer) Option
- type SecurityConfig
- type Task
- func (t *Task) AnswerInteraction(ctx context.Context, requestID string, answers map[string][]string) error
- func (t *Task) CancelTurn(_ context.Context, turnID string) error
- func (t *Task) Close()
- func (t *Task) StartAgent(ctx context.Context, agentName, input string, options ...engine.RunOption) (*taskpkg.Turn, error)
- func (t *Task) StartTeam(ctx context.Context, teamName, input string) (*taskpkg.Turn, error)
- func (t *Task) StartWorkflow(ctx context.Context, workflowName, input string) (*taskpkg.Turn, error)
- func (t *Task) TaskID() string
- func (t *Task) WaitTurn(ctx context.Context, turnID string) (*taskpkg.Result, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ResolveModelDefaults ¶
func ResolveModelDefaults(cfg *ModelConfig)
ResolveModelDefaults normalizes vendor/api_format and timeout. BaseURL is never inferred from vendor; configure it explicitly because vendor and api_format are independent.
Types ¶
type Config ¶
type Config struct {
Version string `json:"version"`
Name string `json:"name"`
LogLevel string `json:"log_level"`
DefaultModel ModelConfig `json:"default_model"`
AllowedTools []string `json:"allowed_tools"`
MemoryConfig MemoryConfig `json:"memory"`
PermissionMode string `json:"permission_mode"` // strict, permissive
MCPClients []MCPClientConfig `json:"mcp_clients,omitempty"`
Security SecurityConfig `json:"security"`
}
func DefaultConfig ¶
func DefaultConfig() Config
func LoadConfig ¶
type Harness ¶
type Harness struct {
// contains filtered or unexported fields
}
func (*Harness) AllowPermissions ¶
func (h *Harness) AllowPermissions(permissions ...security.Permission)
func (*Harness) CheckPermission ¶
func (h *Harness) CheckPermission(permission security.Permission) error
func (*Harness) CreateAgent ¶ added in v0.3.0
CreateAgent constructs and atomically registers an Agent. Production code should prefer this method over NewAgent so invalid or duplicate names cannot fail silently.
func (*Harness) CreateAgentWithTools ¶ added in v0.3.0
func (h *Harness) CreateAgentWithTools(name, systemPrompt string, toolNames ...string) (*engine.Agent, error)
CreateAgentWithTools constructs and atomically registers an Agent whose visible and executable Tool set is restricted to the supplied names. An empty list creates an Agent with no tools.
func (*Harness) CreateTeam ¶ added in v0.3.0
CreateTeam validates, constructs, and atomically registers a Team.
func (*Harness) CreateWorkflow ¶ added in v0.3.0
CreateWorkflow validates, constructs, and atomically registers a Workflow.
func (*Harness) DenyPermissions ¶
func (h *Harness) DenyPermissions(permissions ...security.Permission)
func (*Harness) NewAgent ¶
NewAgent is the compatibility convenience constructor. It returns nil and logs when validation or registration fails. Production code should prefer CreateAgent and handle its error.
func (*Harness) NewTask ¶ added in v0.3.0
NewTask creates an in-memory task runtime. TaskID must be stable and supplied by the caller so its own records can correlate events and checkpoints.
func (*Harness) NewTeam ¶
func (h *Harness) NewTeam(cfg workflow.TeamConfig) *workflow.Team
NewTeam is the compatibility convenience constructor. Production code should prefer CreateTeam and handle its error.
func (*Harness) NewWorkflow ¶
func (h *Harness) NewWorkflow(cfg workflow.WorkflowConfig) *workflow.Workflow
NewWorkflow is the compatibility convenience constructor. Production code should prefer CreateWorkflow and handle its error.
func (*Harness) RegisterAgent ¶ added in v0.2.0
func (*Harness) RegisterWorkflow ¶
func (*Harness) RestoreTask ¶ added in v0.3.0
RestoreTask recreates an in-memory task from a checkpoint previously handled by the caller. It never reads caller storage itself.
func (*Harness) RunWorkflow ¶
func (*Harness) ToolRegistry ¶
func (*Harness) ValidateInput ¶
func (*Harness) ValidateOutput ¶
type MCPClientConfig ¶
type MemoryConfig ¶
type ModelConfig ¶
type ModelConfig struct {
Vendor string `json:"vendor"` // deepseek / openai / anthropic / custom (logging / identity)
APIFormat string `json:"api_format"` // openai_response / openai_chat_completions / anthropic_message / mock
BaseURL string `json:"base_url,omitempty"`
APIKey string `json:"api_key,omitempty"`
ModelID string `json:"model_id"`
Timeout int `json:"timeout_seconds"`
}
ModelConfig describes which vendor and API protocol to use. Vendor and APIFormat are independent: BuildModel selects the client by APIFormat only; BaseURL/APIKey/ModelID come from config as-is.
func (ModelConfig) BuildModel ¶
func (c ModelConfig) BuildModel() (model.Model, error)
func (ModelConfig) BuildModelWithLogger ¶ added in v0.3.1
BuildModelWithLogger builds a model using the application-owned logger. The same logger is propagated to the protocol adapter and the model I/O wrapper, so dynamically selected models use the same logging pipeline as Harness, Agent, tools and MCP clients.
type Option ¶ added in v0.2.0
type Option func(*harnessOptions)
Option customizes Harness dependencies without changing the serializable Config format.
func WithInputValidator ¶ added in v0.2.0
func WithInputValidator(validator security.InputValidator) Option
func WithLogger ¶ added in v0.3.0
WithLogger injects the application logger without changing slog.Default.
func WithMCPClient ¶ added in v0.3.0
WithMCPClient injects a preconfigured public MCP client. It is useful when authentication, custom TLS, proxies, or another HTTP transport must be configured programmatically instead of stored in JSON. An injected client replaces a configured client with the same name.
func WithModel ¶ added in v0.3.0
WithModel injects a preconfigured default Model. This is useful for custom HTTP transports, provider wrappers, tests, and application-owned retry policies. The serializable model configuration is still validated.
func WithOutputValidator ¶ added in v0.2.0
func WithOutputValidator(validator security.OutputValidator) Option
func WithPermissionManager ¶ added in v0.2.0
func WithPermissionManager(manager security.PermissionManager) Option
func WithSanitizer ¶ added in v0.2.0
type SecurityConfig ¶
type Task ¶ added in v0.3.0
type Task struct {
// contains filtered or unexported fields
}
Task is an in-memory runtime for one caller-owned task ID. It has no storage or network transport responsibility; applications provide those concerns by consuming EventSink events and returning required acknowledgements.
func (*Task) AnswerInteraction ¶ added in v0.3.0
func (t *Task) AnswerInteraction(ctx context.Context, requestID string, answers map[string][]string) error
AnswerInteraction acknowledges and delivers a response to a waiting turn.
func (*Task) CancelTurn ¶ added in v0.3.0
CancelTurn explicitly cancels a background turn.
func (*Task) Close ¶ added in v0.3.0
func (t *Task) Close()
Close cancels active turns and releases only in-memory task state.
func (*Task) StartAgent ¶ added in v0.3.0
func (t *Task) StartAgent(ctx context.Context, agentName, input string, options ...engine.RunOption) (*taskpkg.Turn, error)
StartAgent starts one Agent turn and returns immediately after the required start events have been acknowledged.
func (*Task) StartWorkflow ¶ added in v0.3.0
func (t *Task) StartWorkflow(ctx context.Context, workflowName, input string) (*taskpkg.Turn, error)
StartWorkflow starts one Workflow turn asynchronously.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
jd-cs-service
command
|
|
|
Package engine implements Agent execution, bounded tool-call loops, streaming, per-Agent Tool scopes, and per-run options.
|
Package engine implements Agent execution, bounded tool-call loops, streaming, per-Agent Tool scopes, and per-run options. |
|
examples
|
|
|
jdcs
Package jdcs demonstrates a customer-service application built exclusively from tracklogic-agent's public packages.
|
Package jdcs demonstrates a customer-service application built exclusively from tracklogic-agent's public packages. |
|
Package interaction defines provider-neutral requests and responses for pausing an Agent turn while an application collects user input.
|
Package interaction defines provider-neutral requests and responses for pausing an Agent turn while an application collects user input. |
|
Package mcp implements a public Model Context Protocol client and converts remote MCP tools into tracklogic-agent model tool definitions.
|
Package mcp implements a public Model Context Protocol client and converts remote MCP tools into tracklogic-agent model tool definitions. |
|
Package memory defines conversation memory and provides a concurrent buffer implementation.
|
Package memory defines conversation memory and provides a concurrent buffer implementation. |
|
Package model defines the model abstraction and built-in OpenAI, Anthropic, Chat Completions, and mock implementations.
|
Package model defines the model abstraction and built-in OpenAI, Anthropic, Chat Completions, and mock implementations. |
|
Package security defines replaceable permission, validation, and sanitizing components together with default in-memory implementations.
|
Package security defines replaceable permission, validation, and sanitizing components together with default in-memory implementations. |
|
Package task defines the protocol-neutral Task, Turn, Item, event, and checkpoint contracts used by applications that host the Harness behind a desktop, web, IDE, or service boundary.
|
Package task defines the protocol-neutral Task, Turn, Item, event, and checkpoint contracts used by applications that host the Harness behind a desktop, web, IDE, or service boundary. |
|
Package tool defines executable Agent tools and a concurrent registry.
|
Package tool defines executable Agent tools and a concurrent registry. |
|
builtin
Package builtin provides bounded general-purpose tools for files, HTTP, JSON, calculation, directories, and time.
|
Package builtin provides bounded general-purpose tools for files, HTTP, JSON, calculation, directories, and time. |
|
Package types contains stable protocol values shared across the model, memory, security, and engine layers.
|
Package types contains stable protocol values shared across the model, memory, security, and engine layers. |
|
Package workflow composes engine Agents into validated teams and stateful workflows.
|
Package workflow composes engine Agents into validated teams and stateful workflows. |