Help us shape the future of Go! Take the 2026 Go Developer Survey

usecase

package
v1.11.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyChatRouteMetadata

func ApplyChatRouteMetadata(metadata map[string]string, provider string, policy llmcore.RoutePolicy, endpointMode string) map[string]string

ApplyChatRouteMetadata merges provider, policy, and endpoint mode into metadata.

func IsSupportedExecutionMode added in v1.8.10

func IsSupportedExecutionMode(mode string) bool

func NormalizeEndpointMode

func NormalizeEndpointMode(raw string) (string, *types.Error)

NormalizeEndpointMode validates and normalizes the endpoint mode.

func NormalizeProviderHint

func NormalizeProviderHint(raw string) (string, *types.Error)

NormalizeProviderHint validates and normalizes the provider hint.

func NormalizeRouteMetadata

func NormalizeRouteMetadata(in map[string]string) map[string]string

NormalizeRouteMetadata trims metadata keys.

func NormalizeRoutePolicy

func NormalizeRoutePolicy(raw string) (llmcore.RoutePolicy, *types.Error)

NormalizeRoutePolicy validates and normalizes the route policy.

func NormalizeRouteTags

func NormalizeRouteTags(in []string) []string

NormalizeRouteTags deduplicates and trims route tags.

func SupportedExecutionModes added in v1.8.10

func SupportedExecutionModes() []string

func SupportedRoutePolicies

func SupportedRoutePolicies() []string

SupportedRoutePolicies returns the list of valid route policy values.

func ToTypesAgentError

func ToTypesAgentError(err error) *types.Error

ToTypesAgentError converts an error to *types.Error when needed.

Types

type AgentExecuteRequest

type AgentExecuteRequest struct {
	AgentID     string            `json:"agent_id"`
	AgentIDs    []string          `json:"agent_ids,omitempty"`
	Mode        string            `json:"mode,omitempty"`
	Content     string            `json:"content"`
	Provider    string            `json:"provider,omitempty"`
	Model       string            `json:"model,omitempty"`
	RoutePolicy string            `json:"route_policy,omitempty"`
	Metadata    map[string]string `json:"metadata,omitempty"`
	Tags        []string          `json:"tags,omitempty"`
	Context     map[string]any    `json:"context,omitempty"`
	Variables   map[string]string `json:"variables,omitempty"`
}

AgentExecuteRequest is the request payload for agent execute/stream operations.

type AgentExecuteResponse

type AgentExecuteResponse struct {
	TraceID               string         `json:"trace_id"`
	Content               string         `json:"content"`
	Metadata              map[string]any `json:"metadata,omitempty"`
	TokensUsed            int            `json:"tokens_used,omitempty"`
	Cost                  float64        `json:"cost,omitempty"`
	Duration              string         `json:"duration"`
	FinishReason          string         `json:"finish_reason,omitempty"`
	CurrentStage          string         `json:"current_stage,omitempty"`
	IterationCount        int            `json:"iteration_count,omitempty"`
	SelectedReasoningMode string         `json:"selected_reasoning_mode,omitempty"`
	StopReason            string         `json:"stop_reason,omitempty"`
	CheckpointID          string         `json:"checkpoint_id,omitempty"`
	Resumable             bool           `json:"resumable"`
}

AgentExecuteResponse is the response payload for agent execute operations.

type AgentOperation

type AgentOperation string

AgentOperation identifies the business intent for resolver fallback messages.

const (
	AgentOperationExecute AgentOperation = "execution"
	AgentOperationStream  AgentOperation = "streaming"
)

type AgentResolver

type AgentResolver func(ctx context.Context, agentID string) (agent.Agent, error)

AgentResolver resolves an agent ID to a live Agent instance. This decouples the handler from how agents are stored/managed at runtime.

type AgentService

type AgentService interface {
	ResolveForOperation(ctx context.Context, agentID string, op AgentOperation) (agent.Agent, *types.Error)
	ListAgents(ctx context.Context) ([]*discovery.AgentInfo, *types.Error)
	GetAgent(ctx context.Context, agentID string) (*discovery.AgentInfo, *types.Error)
	ExecuteAgent(ctx context.Context, req AgentExecuteRequest, traceID string) (*AgentExecuteResponse, time.Duration, *types.Error)
	ExecuteAgentStream(ctx context.Context, req AgentExecuteRequest, traceID string, emitter agent.RuntimeStreamEmitter) *types.Error
}

AgentService encapsulates runtime agent resolution and endpoint availability checks.

type ChatCompletionResult

type ChatCompletionResult struct {
	Response *api.ChatResponse
	Raw      *llm.ChatResponse
	Duration time.Duration
}

ChatCompletionResult captures completion output and execution metadata.

type ChatConverter

type ChatConverter interface {
	ToLLMRequest(req *api.ChatRequest) *llm.ChatRequest
	ToAPIResponse(resp *llm.ChatResponse) *api.ChatResponse
}

ChatConverter centralizes request/response conversion between API and LLM layers. Implementations are provided by the handlers layer.

type ChatService

type ChatService interface {
	Complete(ctx context.Context, req *api.ChatRequest) (*ChatCompletionResult, *types.Error)
	Stream(ctx context.Context, req *api.ChatRequest) (<-chan llmcore.UnifiedChunk, *types.Error)
	SupportedRoutePolicies() []string
	DefaultRoutePolicy() string
}

ChatService encapsulates chat routing and gateway invocation logic.

func NewDefaultChatService

func NewDefaultChatService(
	gateway llmcore.Gateway,
	chatProvider llm.Provider,
	toolManager agent.ToolManager,
	converter ChatConverter,
	logger *zap.Logger,
) ChatService

NewDefaultChatService constructs a ChatService with gateway, provider, tool manager, and converter.

type DefaultAgentService

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

DefaultAgentService is the default AgentService implementation used by AgentHandler.

func NewDefaultAgentService

func NewDefaultAgentService(registry discovery.Registry, resolver AgentResolver) *DefaultAgentService

NewDefaultAgentService constructs a service with resolver+registry fallback strategy.

func (*DefaultAgentService) ExecuteAgent

func (*DefaultAgentService) ExecuteAgentStream

func (s *DefaultAgentService) ExecuteAgentStream(ctx context.Context, req AgentExecuteRequest, traceID string, emitter agent.RuntimeStreamEmitter) *types.Error

func (*DefaultAgentService) GetAgent

func (s *DefaultAgentService) GetAgent(ctx context.Context, agentID string) (*discovery.AgentInfo, *types.Error)

func (*DefaultAgentService) ListAgents

func (s *DefaultAgentService) ListAgents(ctx context.Context) ([]*discovery.AgentInfo, *types.Error)

func (*DefaultAgentService) PlanAgent

PlanAgent remains an internal helper for package-level tests and direct usecase calls. It is no longer part of the public HTTP/API execution surface.

func (*DefaultAgentService) ResolveForOperation

func (s *DefaultAgentService) ResolveForOperation(ctx context.Context, agentID string, op AgentOperation) (agent.Agent, *types.Error)

ResolveForOperation resolves an agent for execute/stream operations.

type DefaultChatService

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

DefaultChatService is the default ChatService implementation.

func (*DefaultChatService) Complete

func (*DefaultChatService) DefaultRoutePolicy

func (s *DefaultChatService) DefaultRoutePolicy() string

func (*DefaultChatService) Stream

func (*DefaultChatService) SupportedRoutePolicies

func (s *DefaultChatService) SupportedRoutePolicies() []string

Jump to

Keyboard shortcuts

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