agent

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package agent provides cagent integration for MCP tools

Package agent provides cagent runtime configuration and setup

Package agent provides agent configuration and management functionality

Package agent provides model-specific client initialization and management functionality

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDefaultConfig added in v0.1.6

func CreateDefaultConfig() error

CreateDefaultConfig creates a default agent configuration file if it doesn't exist

func CreateDefaultConfigForce added in v0.1.6

func CreateDefaultConfigForce() error

CreateDefaultConfigForce creates a default agent configuration file, overwriting if it exists

func GetDefaultConfigYAML added in v0.1.6

func GetDefaultConfigYAML() string

GetDefaultConfigYAML returns the embedded default configuration as a YAML string

func InitializeModelClient added in v0.1.6

func InitializeModelClient(config ModelConfig, logger *common.Logger) (*openai.Client, error)

InitializeModelClient creates and configures the appropriate model client based on the model class

func ValidateModelConfig added in v0.1.6

func ValidateModelConfig(config ModelConfig, logger *common.Logger) error

ValidateModelConfig validates the model configuration for the specified model class

Types

type Agent

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

Agent represents an MCP agent

func New

func New(cfg AgentConfig, logger *common.Logger) *Agent

New creates a new agent instance

func (*Agent) Run

func (a *Agent) Run(ctx context.Context, userInput chan string, agentOutput chan string) error

Run executes the agent using cagent multi-agent framework

func (*Agent) Validate

func (a *Agent) Validate() error

Validate checks if the configuration is valid

type AgentConfig

type AgentConfig struct {
	ToolsFile   string // Path to the YAML configuration file defining available tools
	UserPrompt  string // Initial user prompt to send to the LLM
	Once        bool   // Whether to run in one-shot mode (exit after first response)
	Version     string // Version information for the agent
	ModelConfig        // Embedded model configuration (Model, APIKey, APIURL, Prompts)
}

AgentConfig holds the configuration for the agent including tools file location, user prompts, execution mode, and embedded model configuration (API keys, model name, etc.)

type AgentConfigFile added in v0.1.6

type AgentConfigFile struct {
	Models []ModelConfig `yaml:"models"` // Legacy: flat list of models

	// Role-based configuration for multi-agent system
	Orchestrator *ModelConfig `yaml:"orchestrator,omitempty"` // Root agent that plans and orchestrates
	ToolRunner   *ModelConfig `yaml:"tool-runner,omitempty"`  // Sub-agent that executes tools
}

AgentConfigFile holds the agent configuration from file

type CagentRuntime added in v0.1.7

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

CagentRuntime wraps the cagent runtime and session

func CreateCagentRuntime added in v0.1.7

func CreateCagentRuntime(
	ctx context.Context,
	srv *server.Server,
	orchestratorConfig ModelConfig,
	toolRunnerConfig ModelConfig,
	userPrompt string,
	logger *common.Logger,
) (*CagentRuntime, error)

CreateCagentRuntime creates and configures a cagent runtime Uses a single agent approach for better tool execution continuity

func (*CagentRuntime) ContinueConversation added in v0.1.7

func (cr *CagentRuntime) ContinueConversation(userMessage string) error

ContinueConversation adds a new user message to the session and continues the conversation

func (*CagentRuntime) RunStream added in v0.1.7

func (cr *CagentRuntime) RunStream(ctx context.Context) <-chan runtime.Event

RunStream starts the streaming runtime and returns the event channel

func (*CagentRuntime) Runtime added in v0.1.7

func (cr *CagentRuntime) Runtime() runtime.Runtime

Runtime returns the underlying cagent runtime for advanced operations like Resume

type Config added in v0.1.6

type Config struct {
	Agent AgentConfigFile `yaml:"agent"`
}

Config holds the complete agent configuration

func GetConfig added in v0.1.6

func GetConfig() (*Config, error)

GetConfig returns the agent configuration from the config file The config file is located at ~/.mcpshell/agent.yaml

func GetDefaultConfig added in v0.1.6

func GetDefaultConfig() (*Config, error)

GetDefaultConfig returns the default agent configuration parsed from the embedded config_sample.yaml

func (*Config) GetDefaultModel added in v0.1.6

func (c *Config) GetDefaultModel() *ModelConfig

GetDefaultModel returns the model configuration that has default=true If no default is found, returns the first model in the list If no models are configured, returns nil

func (*Config) GetModelByName added in v0.1.6

func (c *Config) GetModelByName(name string) *ModelConfig

GetModelByName returns the model configuration with the specified name

func (*Config) GetOrchestratorModel added in v0.1.7

func (c *Config) GetOrchestratorModel() *ModelConfig

GetOrchestratorModel returns the orchestrator model configuration Falls back to default model if orchestrator is not specified

func (*Config) GetToolRunnerModel added in v0.1.7

func (c *Config) GetToolRunnerModel() *ModelConfig

GetToolRunnerModel returns the tool-runner model configuration Falls back to orchestrator model if tool-runner is not specified

type GenericProvider added in v0.1.6

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

GenericProvider implements ModelProvider for unknown/generic model types This allows for extensibility with other OpenAI-compatible APIs

func (*GenericProvider) GetProviderName added in v0.1.6

func (p *GenericProvider) GetProviderName() string

func (*GenericProvider) InitializeClient added in v0.1.6

func (p *GenericProvider) InitializeClient(config ModelConfig, logger *common.Logger) (*openai.Client, error)

func (*GenericProvider) ValidateConfig added in v0.1.6

func (p *GenericProvider) ValidateConfig(config ModelConfig, logger *common.Logger) error

type MCPToolSet added in v0.1.7

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

MCPToolSet wraps MCP server tools for use with cagent

func NewMCPToolSet added in v0.1.7

func NewMCPToolSet(srv *server.Server, logger *common.Logger) *MCPToolSet

NewMCPToolSet creates a new MCP tool set for cagent

func (*MCPToolSet) GetTools added in v0.1.7

func (m *MCPToolSet) GetTools() ([]cagentTools.Tool, error)

GetTools returns all MCP tools as cagent-compatible tools

type ModelConfig added in v0.1.6

type ModelConfig struct {
	Model   string               `yaml:"model"`
	Class   string               `yaml:"class,omitempty"`   // Class of the model, e.g., "ollama", "openai", etc.
	Name    string               `yaml:"name,omitempty"`    // Name of the model, optional
	Default bool                 `yaml:"default,omitempty"` // Whether this is the default model
	APIKey  string               `yaml:"api-key,omitempty"` // API key, optional
	APIURL  string               `yaml:"api-url,omitempty"` // API URL, optional
	Prompts common.PromptsConfig `yaml:"prompts,omitempty"` // Prompts configuration, optional
}

ModelConfig holds configuration for a single model

type ModelManager added in v0.1.6

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

ModelManager manages different model providers and routes requests to the appropriate one

func NewModelManager added in v0.1.6

func NewModelManager(logger *common.Logger) *ModelManager

NewModelManager creates a new model manager with all supported providers

func (*ModelManager) InitializeClient added in v0.1.6

func (mm *ModelManager) InitializeClient(config ModelConfig) (*openai.Client, error)

InitializeClient initializes a client for the given model configuration

func (*ModelManager) RegisterProvider added in v0.1.6

func (mm *ModelManager) RegisterProvider(class string, provider ModelProvider)

RegisterProvider registers a new model provider

func (*ModelManager) ValidateConfig added in v0.1.6

func (mm *ModelManager) ValidateConfig(config ModelConfig) error

ValidateConfig validates the configuration for the given model class

type ModelProvider added in v0.1.6

type ModelProvider interface {
	// InitializeClient creates and configures the client for this model provider
	InitializeClient(config ModelConfig, logger *common.Logger) (*openai.Client, error)

	// ValidateConfig validates the configuration for this model provider
	ValidateConfig(config ModelConfig, logger *common.Logger) error

	// GetProviderName returns the human-readable name of the provider
	GetProviderName() string
}

ModelProvider defines the interface for different model providers

type OllamaProvider added in v0.1.6

type OllamaProvider struct{}

OllamaProvider implements ModelProvider for Ollama models

func (*OllamaProvider) GetProviderName added in v0.1.6

func (p *OllamaProvider) GetProviderName() string

func (*OllamaProvider) InitializeClient added in v0.1.6

func (p *OllamaProvider) InitializeClient(config ModelConfig, logger *common.Logger) (*openai.Client, error)

func (*OllamaProvider) ValidateConfig added in v0.1.6

func (p *OllamaProvider) ValidateConfig(config ModelConfig, logger *common.Logger) error

type OpenAIProvider added in v0.1.6

type OpenAIProvider struct{}

OpenAIProvider implements ModelProvider for OpenAI models

func (*OpenAIProvider) GetProviderName added in v0.1.6

func (p *OpenAIProvider) GetProviderName() string

func (*OpenAIProvider) InitializeClient added in v0.1.6

func (p *OpenAIProvider) InitializeClient(config ModelConfig, logger *common.Logger) (*openai.Client, error)

func (*OpenAIProvider) ValidateConfig added in v0.1.6

func (p *OpenAIProvider) ValidateConfig(config ModelConfig, logger *common.Logger) error

Jump to

Keyboard shortcuts

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