usecase

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 14 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 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 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"`
	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/plan/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"`
}

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"
	AgentOperationPlan    AgentOperation = "planning"
)

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)
	PlanAgent(ctx context.Context, req AgentExecuteRequest, traceID string) (*agent.PlanResult, *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

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/plan 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