Documentation
¶
Index ¶
- func ParseModelName(modelString string) (provider, model string)
- type Agent
- func (a *Agent) Close() error
- func (a *Agent) GenerateWithLoop(ctx context.Context, messages []fantasy.Message, onToolCall ToolCallHandler, ...) (*GenerateWithLoopResult, error)
- func (a *Agent) GenerateWithLoopAndStreaming(ctx context.Context, messages []fantasy.Message, onToolCall ToolCallHandler, ...) (*GenerateWithLoopResult, error)
- func (a *Agent) GetLoadedServerNames() []string
- func (a *Agent) GetLoadingMessage() string
- func (a *Agent) GetModel() fantasy.LanguageModel
- func (a *Agent) GetTools() []fantasy.AgentTool
- type AgentConfig
- type AgentCreationOptions
- type GenerateWithLoopResult
- type ResponseHandler
- type SpinnerFunc
- type StreamingResponseHandler
- type ToolApprovalHandler
- type ToolCallContentHandler
- type ToolCallHandler
- type ToolExecutionHandler
- type ToolResultHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseModelName ¶ added in v0.19.0
ParseModelName extracts provider and model name from a model string. Model strings are formatted as "provider:model" (e.g., "anthropic:claude-3-5-sonnet-20241022"). If the string doesn't contain a colon, returns "unknown" for both provider and model.
Types ¶
type Agent ¶ added in v0.10.0
type Agent struct {
// contains filtered or unexported fields
}
Agent represents an AI agent with MCP tool integration using the fantasy library. It manages the interaction between an LLM and various tools through the MCP protocol.
func CreateAgent ¶ added in v0.19.0
func CreateAgent(ctx context.Context, opts *AgentCreationOptions) (*Agent, error)
CreateAgent creates an agent with optional spinner for Ollama models. It shows a loading spinner for Ollama models if ShowSpinner is true and not in quiet mode. Returns the created agent or an error if creation fails.
func NewAgent ¶ added in v0.10.0
func NewAgent(ctx context.Context, agentConfig *AgentConfig) (*Agent, error)
NewAgent creates a new Agent with MCP tool integration and streaming support.
func (*Agent) GenerateWithLoop ¶ added in v0.10.0
func (a *Agent) GenerateWithLoop(ctx context.Context, messages []fantasy.Message, onToolCall ToolCallHandler, onToolExecution ToolExecutionHandler, onToolResult ToolResultHandler, onResponse ResponseHandler, onToolCallContent ToolCallContentHandler, onToolApproval ToolApprovalHandler, ) (*GenerateWithLoopResult, error)
GenerateWithLoop processes messages with a custom loop that displays tool calls in real-time.
func (*Agent) GenerateWithLoopAndStreaming ¶ added in v0.18.0
func (a *Agent) GenerateWithLoopAndStreaming(ctx context.Context, messages []fantasy.Message, onToolCall ToolCallHandler, onToolExecution ToolExecutionHandler, onToolResult ToolResultHandler, onResponse ResponseHandler, onToolCallContent ToolCallContentHandler, onStreamingResponse StreamingResponseHandler, onToolApproval ToolApprovalHandler, ) (*GenerateWithLoopResult, error)
GenerateWithLoopAndStreaming processes messages using the fantasy agent with streaming and callbacks. Fantasy handles the tool call loop internally. We map fantasy's rich callback system to mcphost's existing callback interface for UI integration.
func (*Agent) GetLoadedServerNames ¶ added in v0.19.0
GetLoadedServerNames returns the names of successfully loaded MCP servers.
func (*Agent) GetLoadingMessage ¶ added in v0.18.0
GetLoadingMessage returns the loading message from provider creation.
func (*Agent) GetModel ¶ added in v0.34.0
func (a *Agent) GetModel() fantasy.LanguageModel
GetModel returns the underlying fantasy LanguageModel.
type AgentConfig ¶ added in v0.10.0
type AgentConfig struct {
ModelConfig *models.ProviderConfig
MCPConfig *config.Config
SystemPrompt string
MaxSteps int
StreamingEnabled bool
DebugLogger tools.DebugLogger
}
AgentConfig holds configuration options for creating a new Agent.
type AgentCreationOptions ¶ added in v0.19.0
type AgentCreationOptions struct {
// ModelConfig specifies the LLM provider and model to use
ModelConfig *models.ProviderConfig
// MCPConfig contains MCP server configurations
MCPConfig *config.Config
// SystemPrompt is the initial system message for the agent
SystemPrompt string
// MaxSteps limits the number of tool calls (0 for unlimited)
MaxSteps int
// StreamingEnabled controls whether responses are streamed
StreamingEnabled bool
// ShowSpinner indicates whether to show a spinner for Ollama models during loading
ShowSpinner bool // For Ollama models
// Quiet suppresses the spinner even if ShowSpinner is true
Quiet bool // Skip spinner if quiet
// SpinnerFunc is the function to show spinner, provided by the caller
SpinnerFunc SpinnerFunc // Function to show spinner (provided by caller)
// DebugLogger is an optional logger for debugging MCP communications
DebugLogger tools.DebugLogger // Optional debug logger
}
AgentCreationOptions contains options for creating an agent. It extends AgentConfig with UI-related options for showing progress during creation.
type GenerateWithLoopResult ¶ added in v0.17.0
type GenerateWithLoopResult struct {
// FinalResponse is the last message generated by the model
FinalResponse *fantasy.Response
// ConversationMessages contains all messages in the conversation including tool calls and results
ConversationMessages []fantasy.Message
// TotalUsage contains aggregate token usage across all steps
TotalUsage fantasy.Usage
}
GenerateWithLoopResult contains the result and conversation history from an agent interaction.
type ResponseHandler ¶ added in v0.10.0
type ResponseHandler func(content string)
ResponseHandler is a function type for handling LLM responses.
type SpinnerFunc ¶ added in v0.19.0
SpinnerFunc is a function type for showing spinners during agent creation. It executes the provided function while displaying a spinner with the given message.
type StreamingResponseHandler ¶ added in v0.18.0
type StreamingResponseHandler func(content string)
StreamingResponseHandler is a function type for handling streaming LLM responses.
type ToolApprovalHandler ¶ added in v0.32.0
ToolApprovalHandler is a function type for handling user approval of tool calls.
type ToolCallContentHandler ¶ added in v0.10.0
type ToolCallContentHandler func(content string)
ToolCallContentHandler is a function type for handling content that accompanies tool calls.
type ToolCallHandler ¶ added in v0.10.0
type ToolCallHandler func(toolName, toolArgs string)
ToolCallHandler is a function type for handling tool calls as they happen.
type ToolExecutionHandler ¶ added in v0.11.0
ToolExecutionHandler is a function type for handling tool execution start/end events.
type ToolResultHandler ¶ added in v0.10.0
ToolResultHandler is a function type for handling tool results.