Documentation
¶
Index ¶
- func ConvertToSchemaMessage(msg *Message) *schema.Message
- type MCPHost
- func (m *MCPHost) ClearSession()
- func (m *MCPHost) Close() error
- func (m *MCPHost) GetModelString() string
- func (m *MCPHost) GetSessionManager() *session.Manager
- func (m *MCPHost) LoadSession(path string) error
- func (m *MCPHost) Prompt(ctx context.Context, message string) (string, error)
- func (m *MCPHost) PromptWithCallbacks(ctx context.Context, message string, onToolCall func(name, args string), ...) (string, error)
- func (m *MCPHost) SaveSession(path string) error
- type Message
- type Options
- type ToolCall
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertToSchemaMessage ¶
ConvertToSchemaMessage converts an SDK message to the underlying schema message format used by the agent for LLM interactions.
Types ¶
type MCPHost ¶
type MCPHost struct {
// contains filtered or unexported fields
}
MCPHost provides programmatic access to mcphost functionality, allowing integration of MCP tools and LLM interactions into Go applications. It manages agents, sessions, and model configurations.
func New ¶
New creates an MCPHost instance using the same initialization as the CLI. It loads configuration, initializes MCP servers, creates the LLM model, and sets up the agent for interaction. Returns an error if initialization fails.
func (*MCPHost) ClearSession ¶
func (m *MCPHost) ClearSession()
ClearSession clears the current session history, starting a new conversation with an empty message history.
func (*MCPHost) Close ¶
Close cleans up resources including MCP server connections and model resources. Should be called when the MCPHost instance is no longer needed. Returns an error if cleanup fails.
func (*MCPHost) GetModelString ¶
GetModelString returns the current model string identifier (e.g., "anthropic:claude-3-sonnet" or "openai:gpt-4") being used by the agent.
func (*MCPHost) GetSessionManager ¶
GetSessionManager returns the current session manager for direct access to conversation history and session manipulation.
func (*MCPHost) LoadSession ¶
LoadSession loads a previously saved session from a file, restoring the conversation history. Returns an error if the file cannot be loaded or parsed.
func (*MCPHost) Prompt ¶
Prompt sends a message to the agent and returns the response. The agent may use tools as needed to generate the response. The conversation history is automatically maintained in the session. Returns an error if generation fails.
func (*MCPHost) PromptWithCallbacks ¶
func (m *MCPHost) PromptWithCallbacks( ctx context.Context, message string, onToolCall func(name, args string), onToolResult func(name, args, result string, isError bool), onStreaming func(chunk string), ) (string, error)
PromptWithCallbacks sends a message with callbacks for monitoring tool execution and streaming responses. The callbacks allow real-time observation of tool calls, results, and response generation. Returns the final response or an error.
func (*MCPHost) SaveSession ¶
SaveSession saves the current session to a file for later restoration. Returns an error if the session cannot be written to the specified path.
type Message ¶
Message is an alias for session.Message providing SDK users with access to message structures for conversation history and tool interactions.
func ConvertFromSchemaMessage ¶
ConvertFromSchemaMessage converts a schema message from the agent to an SDK message format for use in the SDK API.
type Options ¶
type Options struct {
Model string // Override model (e.g., "anthropic:claude-3-sonnet")
SystemPrompt string // Override system prompt
ConfigFile string // Override config file path
MaxSteps int // Override max steps (0 = use default)
Streaming bool // Enable streaming (default from config)
Quiet bool // Suppress debug output
}
Options configures MCPHost creation with optional overrides for model, prompts, configuration, and behavior settings. All fields are optional and will use CLI defaults if not specified.