Documentation
¶
Overview ¶
Package vllmsdk provides agent ergonomics backed by VLLM.
Index ¶
- Constants
- Variables
- func ErrorResult(message string) *mcp.CallToolResult
- func ImageResult(data []byte, mimeType string) *mcp.CallToolResult
- func MessagesFromChannel(ch <-chan StreamingMessage) iter.Seq[StreamingMessage]
- func MessagesFromContent(content UserMessageContent) iter.Seq[StreamingMessage]
- func MessagesFromSlice(msgs []StreamingMessage) iter.Seq[StreamingMessage]
- func NewMcpTool(name, description string, inputSchema *jsonschema.Schema) *mcp.Tool
- func NopLogger() *slog.Logger
- func ParseArguments(req *mcp.CallToolRequest) (map[string]any, error)
- func Query(ctx context.Context, content UserMessageContent, opts ...Option) iter.Seq2[Message, error]
- func QueryStream(ctx context.Context, messages iter.Seq[StreamingMessage], opts ...Option) iter.Seq2[Message, error]
- func SimpleSchema(props map[string]string) *jsonschema.Schema
- func SingleMessage(content UserMessageContent) iter.Seq[StreamingMessage]
- func TextResult(text string) *mcp.CallToolResult
- func Validate(schema, input map[string]any) error
- func WithClient(ctx context.Context, fn func(Client) error, opts ...Option) error
- type AssistantMessage
- type AssistantMessageError
- type AsyncHookJSONOutput
- type BaseHookInput
- type CallToolRequest
- type CallToolResult
- type ChatRequest
- type Client
- type ContentBlock
- type Effort
- type HookCallback
- type HookContext
- type HookEvent
- type HookInput
- type HookJSONOutput
- type HookMatcher
- type HookSpecificOutput
- type ImageBlock
- type InputAudioBlock
- type InputAudioRef
- type InputFileBlock
- type InputFileRef
- type InputImageBlock
- type InputImageRef
- type InputVideoBlock
- type InputVideoRef
- type MCPHTTPServerConfig
- type MCPSSEServerConfig
- type MCPSdkServerConfig
- type MCPServerConfig
- type MCPServerStatus
- type MCPServerType
- type MCPStatus
- type MCPStdioServerConfig
- type McpAudioContent
- type McpContent
- type McpImageContent
- type McpTextContent
- type McpTool
- type McpToolAnnotations
- type McpToolHandler
- type Message
- type MessageParseError
- type MessageStream
- type Model
- type ModelArchitecture
- type ModelEndpoint
- type ModelInfo
- type ModelListResponse
- type ModelPerRequestLimits
- type ModelPricing
- type ModelSupportedParameters
- type ModelTopProvider
- type NotificationHookInput
- type NotificationHookSpecificOutput
- type Option
- func WithAPIKey(apiKey string) Option
- func WithAllowedTools(tools ...string) Option
- func WithBackground(background bool) Option
- func WithBaseURL(baseURL string) Option
- func WithCanUseTool(callback ToolPermissionCallback) Option
- func WithCwd(cwd string) Option
- func WithDisallowedTools(tools ...string) Option
- func WithEffort(effort config.Effort) Option
- func WithEnableFileCheckpointing(enable bool) Option
- func WithFallbackModel(model string) Option
- func WithForkSession(fork bool) Option
- func WithFrequencyPenalty(v float64) Option
- func WithHTTPReferer(referer string) Option
- func WithHooks(hooks map[HookEvent][]*HookMatcher) Option
- func WithImageConfig(cfg map[string]any) Option
- func WithInclude(include ...string) Option
- func WithIncludePartialMessages(include bool) Option
- func WithInstructions(instructions string) Option
- func WithLogger(logger *slog.Logger) Option
- func WithLogprobs(enable bool) Option
- func WithMCPConfig(config string) Option
- func WithMCPServers(servers map[string]MCPServerConfig) Option
- func WithMaxBudgetUSD(budget float64) Option
- func WithMaxOutputTokens(max int) Option
- func WithMaxTokens(max int) Option
- func WithMaxToolCalls(max int) Option
- func WithMaxToolIterations(max int) Option
- func WithMaxTurns(maxTurns int) Option
- func WithModalities(modalities ...string) Option
- func WithModel(model string) Option
- func WithModels(models ...string) Option
- func WithOnUserInput(callback UserInputCallback) Option
- func WithOutputFormat(format map[string]any) Option
- func WithParallelToolCalls(enable bool) Option
- func WithPermissionMode(mode string) Option
- func WithPermissionPromptToolName(name string) Option
- func WithPlugins(plugins ...*SdkPluginConfig) Option
- func WithPresencePenalty(v float64) Option
- func WithPreviousResponseID(responseID string) Option
- func WithPrompt(prompt map[string]any) Option
- func WithPromptCacheKey(key string) Option
- func WithProvider(provider map[string]any) Option
- func WithReasoning(reasoning map[string]any) Option
- func WithRequestTimeout(timeout time.Duration) Option
- func WithResponseText(text map[string]any) Option
- func WithResume(sessionID string) Option
- func WithRoute(route string) Option
- func WithSDKTools(tools ...Tool) Option
- func WithSafetyIdentifier(safetyID string) Option
- func WithSeed(seed int64) Option
- func WithServiceTier(tier string) Option
- func WithSessionID(sessionID string) Option
- func WithSessionStorePath(path string) Option
- func WithStop(stop ...string) Option
- func WithStore(store bool) Option
- func WithSystemPrompt(prompt string) Option
- func WithSystemPromptPreset(preset *SystemPromptPreset) Option
- func WithTemperature(temperature float64) Option
- func WithThinking(thinking config.ThinkingConfig) Option
- func WithToolChoice(choice any) Option
- func WithTools(tools config.ToolsConfig) Option
- func WithTopK(topK float64) Option
- func WithTopLogprobs(v int) Option
- func WithTopP(topP float64) Option
- func WithTrace(enable bool) Option
- func WithTransport(transport Transport) Option
- func WithTruncation(truncation string) Option
- func WithUser(user string) Option
- func WithVLLMAPIMode(mode config.VLLMAPIMode) Option
- func WithVLLMExtra(extra map[string]any) Option
- func WithVLLMMetadata(metadata map[string]any) Option
- func WithVLLMPlugins(plugins ...map[string]any) Option
- func WithXTitle(title string) Option
- type PermissionBehavior
- type PermissionMode
- type PermissionRequestHookInput
- type PermissionRequestHookSpecificOutput
- type PermissionResult
- type PermissionResultAllow
- type PermissionResultDeny
- type PermissionRuleValue
- type PermissionUpdate
- type PermissionUpdateDestination
- type PermissionUpdateType
- type PostToolUseFailureHookInput
- type PostToolUseFailureHookSpecificOutput
- type PostToolUseHookInput
- type PostToolUseHookSpecificOutput
- type PreCompactHookInput
- type PreToolUseHookInput
- type PreToolUseHookSpecificOutput
- type ResultMessage
- type Schema
- type SchemaBuilder
- func (b *SchemaBuilder) Build() map[string]any
- func (b *SchemaBuilder) OptionalProperty(name, goType string) *SchemaBuilder
- func (b *SchemaBuilder) OptionalPropertyWithDescription(name, goType, description string) *SchemaBuilder
- func (b *SchemaBuilder) Property(name, goType string) *SchemaBuilder
- func (b *SchemaBuilder) PropertyWithDescription(name, goType, description string) *SchemaBuilder
- type SdkMcpServerInstance
- type SdkMcpTool
- type SdkMcpToolHandler
- type SdkMcpToolOption
- type SdkPluginConfig
- type SessionStat
- type StopHookInput
- type StreamEvent
- type StreamingMessage
- type StreamingMessageContent
- type SubagentStartHookInput
- type SubagentStartHookSpecificOutput
- type SubagentStopHookInput
- type SyncHookJSONOutput
- type SystemMessage
- type SystemPromptPreset
- type TextBlock
- type ThinkingBlock
- type ThinkingConfig
- type ThinkingConfigAdaptive
- type ThinkingConfigDisabled
- type ThinkingConfigEnabled
- type Tool
- type ToolFunc
- type ToolPermissionCallback
- type ToolPermissionContext
- type ToolPermissionDeniedError
- type ToolResultBlock
- type ToolUseBlock
- type ToolsConfig
- type ToolsList
- type ToolsPreset
- type Transport
- type UnsupportedControlError
- type UnsupportedHookEventError
- type UnsupportedHookOutputError
- type Usage
- type UserInputAnswer
- type UserInputCallback
- type UserInputQuestion
- type UserInputQuestionOption
- type UserInputRequest
- type UserInputResponse
- type UserMessage
- type UserMessageContent
- type UserPromptSubmitHookInput
- type UserPromptSubmitHookSpecificOutput
- type VLLMAPIMode
- type VLLMAgentOptions
- type VLLMSDKError
Constants ¶
const ( // VLLMAPIModeChatCompletions uses /chat/completions. VLLMAPIModeChatCompletions = config.VLLMAPIModeChatCompletions // VLLMAPIModeResponses uses /responses. VLLMAPIModeResponses = config.VLLMAPIModeResponses )
const ( // EffortLow uses minimal thinking. EffortLow = config.EffortLow // EffortMedium uses moderate thinking. EffortMedium = config.EffortMedium // EffortHigh uses deep thinking. EffortHigh = config.EffortHigh // EffortMax uses maximum thinking depth. EffortMax = config.EffortMax )
const ( // AssistantMessageErrorAuthFailed indicates authentication failure. AssistantMessageErrorAuthFailed = message.AssistantMessageErrorAuthFailed // AssistantMessageErrorBilling indicates a billing error. AssistantMessageErrorBilling = message.AssistantMessageErrorBilling // AssistantMessageErrorRateLimit indicates rate limiting. AssistantMessageErrorRateLimit = message.AssistantMessageErrorRateLimit // AssistantMessageErrorInvalidReq indicates an invalid request. AssistantMessageErrorInvalidReq = message.AssistantMessageErrorInvalidReq // AssistantMessageErrorServer indicates a server error. AssistantMessageErrorServer = message.AssistantMessageErrorServer // AssistantMessageErrorUnknown indicates an unknown error. AssistantMessageErrorUnknown = message.AssistantMessageErrorUnknown )
const ( // BlockTypeText contains plain text content. BlockTypeText = message.BlockTypeText // BlockTypeImage contains generated image output content. BlockTypeImage = message.BlockTypeImage // BlockTypeImageURL contains input image URL or data-url content. BlockTypeImageURL = message.BlockTypeImageURL // BlockTypeFile contains input file content. BlockTypeFile = message.BlockTypeFile // BlockTypeInputAudio contains input audio content. BlockTypeInputAudio = message.BlockTypeInputAudio // BlockTypeVideoURL contains input video URL or data-url content. BlockTypeVideoURL = message.BlockTypeVideoURL // BlockTypeThinking contains model reasoning content. BlockTypeThinking = message.BlockTypeThinking // BlockTypeToolUse contains tool-call content. BlockTypeToolUse = message.BlockTypeToolUse // BlockTypeToolResult contains tool-result content. BlockTypeToolResult = message.BlockTypeToolResult )
const ( // HookEventPreToolUse is triggered before a tool is used. HookEventPreToolUse = hook.EventPreToolUse // HookEventPostToolUse is triggered after a tool is used. HookEventPostToolUse = hook.EventPostToolUse // HookEventUserPromptSubmit is triggered when a user submits a prompt. HookEventUserPromptSubmit = hook.EventUserPromptSubmit // HookEventStop is triggered when a session stops. HookEventStop = hook.EventStop // HookEventSubagentStop is triggered when a subagent stops. HookEventSubagentStop = hook.EventSubagentStop // HookEventPreCompact is triggered before compaction. HookEventPreCompact = hook.EventPreCompact // HookEventPostToolUseFailure is triggered after a tool use fails. HookEventPostToolUseFailure = hook.EventPostToolUseFailure // HookEventNotification is triggered when a notification is sent. HookEventNotification = hook.EventNotification // HookEventSubagentStart is triggered when a subagent starts. HookEventSubagentStart = hook.EventSubagentStart // HookEventPermissionRequest is triggered when a permission is requested. HookEventPermissionRequest = hook.EventPermissionRequest )
const ( // PermissionModeDefault uses standard permission prompts. PermissionModeDefault = permission.ModeDefault // PermissionModeAcceptEdits automatically accepts file edits. PermissionModeAcceptEdits = permission.ModeAcceptEdits // PermissionModePlan enables plan mode for implementation planning. PermissionModePlan = permission.ModePlan // PermissionModeBypassPermissions bypasses all permission checks. PermissionModeBypassPermissions = permission.ModeBypassPermissions )
const ( // PermissionUpdateTypeAddRules adds new permission rules. PermissionUpdateTypeAddRules = permission.UpdateTypeAddRules // PermissionUpdateTypeReplaceRules replaces existing permission rules. PermissionUpdateTypeReplaceRules = permission.UpdateTypeReplaceRules // PermissionUpdateTypeRemoveRules removes permission rules. PermissionUpdateTypeRemoveRules = permission.UpdateTypeRemoveRules // PermissionUpdateTypeSetMode sets the permission mode. PermissionUpdateTypeSetMode = permission.UpdateTypeSetMode // PermissionUpdateTypeAddDirectories adds accessible directories. PermissionUpdateTypeAddDirectories = permission.UpdateTypeAddDirectories // PermissionUpdateTypeRemoveDirectories removes accessible directories. PermissionUpdateTypeRemoveDirectories = permission.UpdateTypeRemoveDirectories )
const ( // PermissionUpdateDestUserSettings stores in user-level settings. PermissionUpdateDestUserSettings = permission.UpdateDestUserSettings // PermissionUpdateDestProjectSettings stores in project-level settings. PermissionUpdateDestProjectSettings = permission.UpdateDestProjectSettings // PermissionUpdateDestLocalSettings stores in local-level settings. PermissionUpdateDestLocalSettings = permission.UpdateDestLocalSettings // PermissionUpdateDestSession stores in the current session only. PermissionUpdateDestSession = permission.UpdateDestSession )
const ( // PermissionBehaviorAllow automatically allows the operation. PermissionBehaviorAllow = permission.BehaviorAllow // PermissionBehaviorDeny automatically denies the operation. PermissionBehaviorDeny = permission.BehaviorDeny // PermissionBehaviorAsk prompts the user for permission. PermissionBehaviorAsk = permission.BehaviorAsk )
const ( // MCPServerTypeStdio uses stdio for communication. MCPServerTypeStdio = mcp.ServerTypeStdio // MCPServerTypeSSE uses Server-Sent Events. MCPServerTypeSSE = mcp.ServerTypeSSE // MCPServerTypeHTTP uses HTTP for communication. MCPServerTypeHTTP = mcp.ServerTypeHTTP // MCPServerTypeSDK uses the SDK interface. MCPServerTypeSDK = mcp.ServerTypeSDK )
const Version = "0.1.0"
Version is the SDK version.
Variables ¶
var ( // ErrClientNotConnected indicates the client is not connected. ErrClientNotConnected = internalerrors.ErrClientNotConnected // ErrClientAlreadyConnected indicates the client is already connected. ErrClientAlreadyConnected = internalerrors.ErrClientAlreadyConnected // ErrClientClosed indicates the client has been closed and cannot be reused. ErrClientClosed = internalerrors.ErrClientClosed // ErrTransportNotConnected indicates the transport is not connected. ErrTransportNotConnected = internalerrors.ErrTransportNotConnected // ErrRequestTimeout indicates a request timed out. ErrRequestTimeout = internalerrors.ErrRequestTimeout // ErrSessionNotFound indicates a requested local session does not exist. ErrSessionNotFound = internalerrors.ErrSessionNotFound // ErrUnsupportedFeature indicates an API-compatible feature that is not implemented by this backend. ErrUnsupportedFeature = errors.New("unsupported feature in VLLM backend") // ErrUnsupportedControl indicates a control-plane operation is not supported by backend. ErrUnsupportedControl = controlplane.ErrUnsupportedControl // ErrNoCheckpoint indicates rewind was requested without an available checkpoint. ErrNoCheckpoint = session.ErrNoCheckpoint )
Re-export sentinel errors from internal package.
var NewUserMessageContent = message.NewUserMessageContent
NewUserMessageContent creates UserMessageContent from a string.
var NewUserMessageContentBlocks = message.NewUserMessageContentBlocks
NewUserMessageContentBlocks creates UserMessageContent from blocks.
Functions ¶
func ErrorResult ¶
func ErrorResult(message string) *mcp.CallToolResult
ErrorResult creates a CallToolResult indicating an error.
func ImageResult ¶
func ImageResult(data []byte, mimeType string) *mcp.CallToolResult
ImageResult creates a CallToolResult with image content.
func MessagesFromChannel ¶
func MessagesFromChannel(ch <-chan StreamingMessage) iter.Seq[StreamingMessage]
MessagesFromChannel creates a MessageStream from a channel. This is useful for dynamic message generation where messages are produced over time. The iterator completes when the channel is closed.
func MessagesFromContent ¶
func MessagesFromContent(content UserMessageContent) iter.Seq[StreamingMessage]
MessagesFromContent creates a single-message stream from user content.
func MessagesFromSlice ¶
func MessagesFromSlice(msgs []StreamingMessage) iter.Seq[StreamingMessage]
MessagesFromSlice creates a MessageStream from a slice of StreamingMessages. This is useful for sending a fixed set of messages in streaming mode.
func NewMcpTool ¶
func NewMcpTool(name, description string, inputSchema *jsonschema.Schema) *mcp.Tool
NewMcpTool creates an mcp.Tool with the given parameters. This is useful when you need direct access to the MCP Tool type.
func NopLogger ¶
NopLogger returns a logger that discards all output. Use this when you want silent operation with no logging overhead.
func ParseArguments ¶
func ParseArguments(req *mcp.CallToolRequest) (map[string]any, error)
ParseArguments unmarshals CallToolRequest arguments into a map. This is a convenience function for extracting tool input.
func Query ¶
func Query( ctx context.Context, content UserMessageContent, opts ...Option, ) iter.Seq2[Message, error]
Query executes a one-shot query and returns a message iterator.
func QueryStream ¶
func QueryStream( ctx context.Context, messages iter.Seq[StreamingMessage], opts ...Option, ) iter.Seq2[Message, error]
QueryStream executes a one-shot query from a stream of user messages.
func SimpleSchema ¶
func SimpleSchema(props map[string]string) *jsonschema.Schema
SimpleSchema creates a jsonschema.Schema from a simple type map.
Input format: {"a": "float64", "b": "string"}
Type mappings:
- "string" → {"type": "string"}
- "int", "int64" → {"type": "integer"}
- "float64", "float" → {"type": "number"}
- "bool" → {"type": "boolean"}
- "[]string" → {"type": "array", "items": {"type": "string"}}
- "any", "object" → {"type": "object"}
func SingleMessage ¶
func SingleMessage(content UserMessageContent) iter.Seq[StreamingMessage]
SingleMessage creates a MessageStream with a single user message.
func TextResult ¶
func TextResult(text string) *mcp.CallToolResult
TextResult creates a CallToolResult with text content.
func Validate ¶
Validate checks if the input matches the schema requirements. Returns an error if required fields are missing.
func WithClient ¶
WithClient manages client lifecycle with automatic cleanup.
This helper creates a client, starts it with the provided options, executes the callback function, and ensures proper cleanup via Close() when done.
The callback receives a fully initialized Client that is ready for use. If the callback returns an error, it is returned to the caller. If Close() fails, a warning is logged but does not override the callback's error.
Example usage:
err := vllmsdk.WithClient(ctx, func(c vllmsdk.Client) error {
if err := c.Query(ctx, Text("Hello")); err != nil {
return err
}
for msg, err := range c.ReceiveResponse(ctx) {
if err != nil {
return err
}
// process message...
}
return nil
},
vllmsdk.WithLogger(log),
vllmsdk.WithPermissionMode("acceptEdits"),
)
Types ¶
type AssistantMessage ¶
type AssistantMessage = message.AssistantMessage
AssistantMessage represents a message from the model.
type AssistantMessageError ¶
type AssistantMessageError = message.AssistantMessageError
AssistantMessageError represents error types from the assistant.
type AsyncHookJSONOutput ¶
type AsyncHookJSONOutput = hook.AsyncJSONOutput
AsyncHookJSONOutput represents an async hook output.
type BaseHookInput ¶
BaseHookInput contains common fields for all hook inputs.
type CallToolRequest ¶
type CallToolRequest = mcp.CallToolRequest
CallToolRequest is the request passed to tool handlers.
type CallToolResult ¶
type CallToolResult = mcp.CallToolResult
CallToolResult is the server's response to a tool call. Use TextResult, ErrorResult, or ImageResult helpers to create results.
type ChatRequest ¶
type ChatRequest = config.ChatRequest
ChatRequest is the normalized VLLM request sent through a Transport.
type Client ¶
type Client interface {
// Start initializes the client runtime.
// Must be called before any other methods.
// Returns a transport/runtime error on failure.
Start(ctx context.Context, opts ...Option) error
// StartWithContent initializes the runtime and immediately sends initial user content.
// Equivalent to calling Start() followed by Query(ctx, content).
// The content is sent to the "default" session.
// Returns a transport/runtime error on failure.
StartWithContent(ctx context.Context, content UserMessageContent, opts ...Option) error
// StartWithStream initializes the runtime and consumes the provided input iterator
// as the initial message stream for the active session.
// The iterator is consumed in a separate goroutine; use context cancellation to abort.
// Returns a transport/runtime error on failure.
StartWithStream(ctx context.Context, messages iter.Seq[StreamingMessage], opts ...Option) error
// Query sends user content to the active session.
// Returns immediately after sending; use ReceiveMessages() or ReceiveResponse() to get responses.
// Optional sessionID defaults to "default" for multi-session support.
Query(ctx context.Context, content UserMessageContent, sessionID ...string) error
// ReceiveMessages returns an iterator that yields messages indefinitely.
// Messages are yielded as they arrive until EOF, an error occurs, or context is cancelled.
// Unlike ReceiveResponse, this iterator does not stop at ResultMessage.
// Use iter.Pull2 if you need pull-based iteration instead of range.
ReceiveMessages(ctx context.Context) iter.Seq2[Message, error]
// ReceiveResponse returns an iterator that yields messages until a ResultMessage is received.
// Messages are yielded as they arrive for streaming consumption.
// The iterator stops after yielding the ResultMessage.
// Use iter.Pull2 if you need pull-based iteration instead of range.
// To collect all messages into a slice, use slices.Collect or a simple loop.
ReceiveResponse(ctx context.Context) iter.Seq2[Message, error]
// Interrupt cancels the current in-flight request.
Interrupt(ctx context.Context) error
// SetPermissionMode changes the permission mode during conversation.
// Valid modes: "default", "acceptEdits", "plan", "bypassPermissions"
SetPermissionMode(ctx context.Context, mode string) error
// SetModel changes the AI model during conversation.
// Pass nil to use the default model.
SetModel(ctx context.Context, model *string) error
// ListModels returns the available VLLM models using the current client options.
ListModels(ctx context.Context) ([]ModelInfo, error)
// ListModelsResponse returns the full VLLM model discovery payload.
ListModelsResponse(ctx context.Context) (*ModelListResponse, error)
// GetServerInfo returns runtime metadata for the active client session.
// Returns nil when the client is not connected.
GetServerInfo() map[string]any
// GetMCPStatus returns MCP server connection status for the current runtime.
// Returns the status of all configured MCP servers.
GetMCPStatus(ctx context.Context) (*MCPStatus, error)
// ReconnectMCPServer reconnects a disconnected or failed MCP server.
ReconnectMCPServer(ctx context.Context, serverName string) error
// ToggleMCPServer enables or disables an MCP server.
ToggleMCPServer(ctx context.Context, serverName string, enabled bool) error
// StopTask stops a running task by task ID.
StopTask(ctx context.Context, taskID string) error
// RewindFiles rewinds tracked files to their state at a specific user message.
// The userMessageID should be the ID of a previous user message in the conversation.
// Requires EnableFileCheckpointing=true in VLLMAgentOptions.
RewindFiles(ctx context.Context, userMessageID string) error
// SendToolResult sends a tool result for a pending tool call.
SendToolResult(ctx context.Context, toolUseID, content string, isError bool) error
// Close terminates the session and cleans up resources.
// After Close(), the client cannot be reused. Safe to call multiple times.
Close() error
}
Client provides an interactive, stateful interface for multi-turn VLLM conversations.
Unlike the one-shot Query() function, Client maintains session state across multiple exchanges. It supports interruption, tool loops, and local session state.
Lifecycle: clients are single-use. After Close(), create a new client with NewClient().
Example usage:
client := NewClient()
defer func() { _ = client.Close() }()
err := client.Start(ctx,
WithLogger(slog.Default()),
WithPermissionMode("acceptEdits"),
)
if err != nil {
log.Fatal(err)
}
// Send a query
err = client.Query(ctx, NewUserMessageContent("What is 2+2?"))
if err != nil {
log.Fatal(err)
}
// Receive all messages for this response (stops at ResultMessage)
for msg, err := range client.ReceiveResponse(ctx) {
if err != nil {
log.Fatal(err)
}
// Process message...
}
// Or receive messages indefinitely (for continuous streaming)
for msg, err := range client.ReceiveMessages(ctx) {
if err != nil {
break
}
// Process message...
}
type ContentBlock ¶
type ContentBlock = message.ContentBlock
ContentBlock represents a block of content within a message.
type HookCallback ¶
HookCallback is the function signature for hook callbacks.
type HookJSONOutput ¶
type HookJSONOutput = hook.JSONOutput
HookJSONOutput is the interface for hook output types.
type HookMatcher ¶
HookMatcher configures which tools/events a hook applies to.
type HookSpecificOutput ¶
type HookSpecificOutput = hook.SpecificOutput
HookSpecificOutput is the interface for hook-specific outputs.
type ImageBlock ¶
type ImageBlock = message.ImageBlock
ImageBlock contains a generated image reference.
type InputAudioBlock ¶
type InputAudioBlock = message.InputAudioBlock
InputAudioBlock contains an input audio payload for multimodal prompts.
func AudioInput ¶
func AudioInput(format, data string) *InputAudioBlock
AudioInput creates an input audio block from base64 audio plus its format.
type InputAudioRef ¶
type InputAudioRef = message.InputAudioRef
InputAudioRef contains base64-encoded input audio plus its format.
type InputFileBlock ¶
type InputFileBlock = message.InputFileBlock
InputFileBlock contains an input file reference for multimodal prompts.
func FileInput ¶
func FileInput(filename, fileData string) *InputFileBlock
FileInput creates an input file block from a URL or data URL.
type InputFileRef ¶
type InputFileRef = message.InputFileRef
InputFileRef identifies an input file URL or data URL.
type InputImageBlock ¶
type InputImageBlock = message.InputImageBlock
InputImageBlock contains an input image reference for multimodal prompts.
func ImageInput ¶
func ImageInput(url string) *InputImageBlock
ImageInput creates an input image block from a URL or data URL.
type InputImageRef ¶
type InputImageRef = message.InputImageRef
InputImageRef identifies an input image URL or data URL.
type InputVideoBlock ¶
type InputVideoBlock = message.InputVideoBlock
InputVideoBlock contains an input video reference for multimodal prompts.
func VideoInput ¶
func VideoInput(url string) *InputVideoBlock
VideoInput creates an input video block from a URL or data URL.
type InputVideoRef ¶
type InputVideoRef = message.InputVideoRef
InputVideoRef identifies an input video URL or data URL.
type MCPHTTPServerConfig ¶
type MCPHTTPServerConfig = mcp.HTTPServerConfig
MCPHTTPServerConfig configures an HTTP-based MCP server.
type MCPSSEServerConfig ¶
type MCPSSEServerConfig = mcp.SSEServerConfig
MCPSSEServerConfig configures a Server-Sent Events MCP server.
type MCPSdkServerConfig ¶
type MCPSdkServerConfig = mcp.SdkServerConfig
MCPSdkServerConfig configures an SDK-provided MCP server.
func CreateSdkMcpServer ¶
func CreateSdkMcpServer(name, version string, tools ...*SdkMcpTool) *MCPSdkServerConfig
CreateSdkMcpServer creates an in-process MCP server configuration with SdkMcpTool tools.
This function creates an MCP server that runs within your application, providing better performance than external MCP servers.
The returned config can be used directly in VLLMAgentOptions.MCPServers:
addTool := vllmsdk.NewSdkMcpTool("add", "Add two numbers",
vllmsdk.SimpleSchema(map[string]string{"a": "float64", "b": "float64"}),
func(ctx context.Context, req *vllmsdk.CallToolRequest) (*vllmsdk.CallToolResult, error) {
args, _ := vllmsdk.ParseArguments(req)
a, b := args["a"].(float64), args["b"].(float64)
return vllmTextResult(fmt.Sprintf("Result: %v", a+b)), nil
},
)
calculator := vllmsdk.CreateSdkMcpServer("calculator", "1.0.0", addTool)
options := &vllmsdk.VLLMAgentOptions{
MCPServers: map[string]vllmsdk.MCPServerConfig{
"calculator": calculator,
},
AllowedTools: []string{"mcp__calculator__add"},
}
Parameters:
- name: Server name (also used as key in MCPServers map, determines tool naming: mcp__<name>__<toolName>)
- version: Server version string
- tools: SdkMcpTool instances to register with the server
type MCPServerConfig ¶
type MCPServerConfig = mcp.ServerConfig
MCPServerConfig is the interface for MCP server configurations.
type MCPServerStatus ¶
type MCPServerStatus = mcp.ServerStatus
MCPServerStatus represents the connection status of a single MCP server.
type MCPServerType ¶
type MCPServerType = mcp.ServerType
MCPServerType represents the type of MCP server.
type MCPStdioServerConfig ¶
type MCPStdioServerConfig = mcp.StdioServerConfig
MCPStdioServerConfig configures a stdio-based MCP server.
type McpAudioContent ¶
type McpAudioContent = mcp.AudioContent
McpAudioContent represents audio content in a tool result.
type McpContent ¶
McpContent is the interface for content types in tool results.
type McpImageContent ¶
type McpImageContent = mcp.ImageContent
McpImageContent represents image content in a tool result.
type McpTextContent ¶
type McpTextContent = mcp.TextContent
McpTextContent represents text content in a tool result.
type McpToolAnnotations ¶
type McpToolAnnotations = mcp.ToolAnnotations
McpToolAnnotations describes optional hints about tool behavior. Fields include ReadOnlyHint, DestructiveHint, IdempotentHint, OpenWorldHint, and Title.
type McpToolHandler ¶
type McpToolHandler = mcp.ToolHandler
McpToolHandler is the function signature for low-level tool handlers.
type MessageParseError ¶
type MessageParseError = internalerrors.MessageParseError
MessageParseError indicates message parsing failed.
type MessageStream ¶
type MessageStream = iter.Seq[StreamingMessage]
MessageStream is an iterator that yields streaming messages.
type ModelArchitecture ¶
type ModelArchitecture = model.Architecture
ModelArchitecture describes the underlying model family where available.
type ModelEndpoint ¶
ModelEndpoint identifies an endpoint a model supports.
type ModelListResponse ¶
type ModelListResponse = model.ListResponse
ModelListResponse contains the full model discovery payload.
func ListModelsResponse ¶
func ListModelsResponse(ctx context.Context, opts ...Option) (*ModelListResponse, error)
ListModelsResponse returns the full vLLM model discovery payload.
type ModelPerRequestLimits ¶
type ModelPerRequestLimits = model.PerRequestLimits
ModelPerRequestLimits captures request limits where available.
type ModelPricing ¶
ModelPricing contains VLLM pricing fields as returned by discovery endpoints.
type ModelSupportedParameters ¶
type ModelSupportedParameters = model.SupportedParameters
ModelSupportedParameters records provider-supported request parameters.
type ModelTopProvider ¶
type ModelTopProvider = model.TopProvider
ModelTopProvider describes provider-side limits and moderation behavior.
type NotificationHookInput ¶
type NotificationHookInput = hook.NotificationInput
NotificationHookInput is the input for Notification hooks.
type NotificationHookSpecificOutput ¶
type NotificationHookSpecificOutput = hook.NotificationSpecificOutput
NotificationHookSpecificOutput is the hook-specific output for Notification.
type Option ¶
type Option func(*VLLMAgentOptions)
Option configures VLLMAgentOptions using the functional options pattern. This is the primary option type for configuring clients and queries.
func WithAllowedTools ¶
WithAllowedTools sets pre-approved tools that can be used without prompting.
func WithBackground ¶
WithBackground sets responses.background.
func WithCanUseTool ¶
func WithCanUseTool(callback ToolPermissionCallback) Option
WithCanUseTool sets a callback for permission checking before each tool use.
func WithDisallowedTools ¶
WithDisallowedTools sets tools that are explicitly blocked.
func WithEffort ¶
WithEffort sets the thinking effort level.
func WithEnableFileCheckpointing ¶
WithEnableFileCheckpointing enables file change tracking and rewinding.
func WithFallbackModel ¶
WithFallbackModel specifies a model to use if the primary model fails.
func WithForkSession ¶
WithForkSession indicates whether to fork the resumed session to a new ID.
func WithFrequencyPenalty ¶
WithFrequencyPenalty sets frequency penalty.
func WithHTTPReferer ¶
WithHTTPReferer sets the HTTP-Referer header for VLLM requests.
func WithHooks ¶
func WithHooks(hooks map[HookEvent][]*HookMatcher) Option
WithHooks configures event hooks for tool interception.
func WithImageConfig ¶
WithImageConfig sets provider-specific image config.
func WithInclude ¶
WithInclude sets responses.include entries.
func WithIncludePartialMessages ¶
WithIncludePartialMessages enables streaming of partial message updates.
func WithInstructions ¶
WithInstructions sets responses.instructions.
func WithLogger ¶
WithLogger sets the logger for debug output. If not set, logging is disabled (silent operation).
func WithLogprobs ¶
WithLogprobs enables token log probabilities where supported.
func WithMCPConfig ¶
WithMCPConfig sets a path to an MCP config file or a raw JSON string. If set, this takes precedence over WithMCPServers.
func WithMCPServers ¶
func WithMCPServers(servers map[string]MCPServerConfig) Option
WithMCPServers configures external MCP servers to connect to. Map key is the server name, value is the server configuration.
func WithMaxBudgetUSD ¶
WithMaxBudgetUSD sets a cost limit for the session in USD.
func WithMaxOutputTokens ¶
WithMaxOutputTokens sets responses.max_output_tokens.
func WithMaxToolCalls ¶
WithMaxToolCalls sets responses.max_tool_calls.
func WithMaxToolIterations ¶
WithMaxToolIterations sets maximum tool-call loops per query.
func WithMaxTurns ¶
WithMaxTurns limits the maximum number of conversation turns.
func WithModalities ¶
WithModalities sets output modalities.
func WithModels ¶
WithModels sets candidate fallback models for VLLM routing.
func WithOnUserInput ¶
func WithOnUserInput(callback UserInputCallback) Option
WithOnUserInput sets a callback for handling SDK user-input tool prompts.
func WithOutputFormat ¶
WithOutputFormat specifies a JSON schema for structured output.
The canonical format uses a wrapper object:
vllmsdk.WithOutputFormat(map[string]any{
"type": "json_schema",
"schema": map[string]any{
"type": "object",
"properties": map[string]any{...},
"required": []string{...},
},
})
Raw JSON schemas (without the wrapper) are also accepted and auto-wrapped:
vllmsdk.WithOutputFormat(map[string]any{
"type": "object",
"properties": map[string]any{...},
"required": []string{...},
})
Structured output is available on ResultMessage.StructuredOutput (parsed) or ResultMessage.Result (JSON string).
func WithParallelToolCalls ¶
WithParallelToolCalls sets parallel_tool_calls.
func WithPermissionMode ¶
WithPermissionMode controls how permissions are handled. Valid values: "default", "acceptEdits", "plan", "bypassPermissions".
func WithPermissionPromptToolName ¶
WithPermissionPromptToolName specifies the tool name to use for permission prompts.
func WithPlugins ¶
func WithPlugins(plugins ...*SdkPluginConfig) Option
WithPlugins configures plugins to load.
func WithPresencePenalty ¶
WithPresencePenalty sets presence penalty.
func WithPreviousResponseID ¶
WithPreviousResponseID sets responses.previous_response_id.
func WithPrompt ¶
WithPrompt sets responses.prompt payload.
func WithPromptCacheKey ¶
WithPromptCacheKey sets responses.prompt_cache_key.
func WithProvider ¶
WithProvider sets VLLM provider preferences.
func WithReasoning ¶
WithReasoning sets VLLM reasoning configuration.
func WithRequestTimeout ¶
WithRequestTimeout sets HTTP request timeout for VLLM calls.
func WithResponseText ¶
WithResponseText sets responses.text payload directly.
func WithResume ¶
WithResume sets a session ID to resume from.
func WithSDKTools ¶
WithSDKTools registers high-level Tool instances as an in-process MCP server. Tools are exposed under the "sdk" MCP server name (tool names: mcp__sdk__<name>). Each tool is automatically added to AllowedTools.
func WithSafetyIdentifier ¶
WithSafetyIdentifier sets responses.safety_identifier.
func WithServiceTier ¶
WithServiceTier sets responses.service_tier.
func WithSessionID ¶
WithSessionID sets request session_id.
func WithSessionStorePath ¶
WithSessionStorePath enables durable session persistence at a JSON file path. When set, resume/fork state can survive process restarts.
func WithSystemPrompt ¶
WithSystemPrompt sets the system message to send to the model.
func WithSystemPromptPreset ¶
func WithSystemPromptPreset(preset *SystemPromptPreset) Option
WithSystemPromptPreset sets a preset system prompt configuration. If set, this takes precedence over WithSystemPrompt.
func WithTemperature ¶
WithTemperature sets sampling temperature.
func WithThinking ¶
func WithThinking(thinking config.ThinkingConfig) Option
WithThinking sets the thinking configuration.
func WithToolChoice ¶
WithToolChoice sets the tool_choice payload.
func WithTools ¶
func WithTools(tools config.ToolsConfig) Option
WithTools specifies which tools are available. Accepts ToolsList (tool names) or *ToolsPreset.
func WithTopLogprobs ¶
WithTopLogprobs sets top_logprobs where supported.
func WithTransport ¶
WithTransport injects a custom transport implementation. The transport must implement the Transport interface.
func WithTruncation ¶
WithTruncation sets responses.truncation.
func WithVLLMAPIMode ¶
func WithVLLMAPIMode(mode config.VLLMAPIMode) Option
WithVLLMAPIMode selects the VLLM API surface.
func WithVLLMExtra ¶
WithVLLMExtra merges raw request fields into the outgoing payload.
func WithVLLMMetadata ¶
WithVLLMMetadata sets request metadata.
func WithVLLMPlugins ¶
WithVLLMPlugins sets VLLM plugin payloads.
func WithXTitle ¶
WithXTitle sets the X-Title header for VLLM requests.
type PermissionBehavior ¶
type PermissionBehavior = permission.Behavior
PermissionBehavior represents the permission behavior for a rule.
type PermissionMode ¶
type PermissionMode = permission.Mode
PermissionMode represents different permission handling modes.
type PermissionRequestHookInput ¶
type PermissionRequestHookInput = hook.PermissionRequestInput
PermissionRequestHookInput is the input for PermissionRequest hooks.
type PermissionRequestHookSpecificOutput ¶
type PermissionRequestHookSpecificOutput = hook.PermissionRequestSpecificOutput
PermissionRequestHookSpecificOutput is the hook-specific output for PermissionRequest.
type PermissionResult ¶
type PermissionResult = permission.Result
PermissionResult is the interface for permission decision results.
type PermissionResultAllow ¶
type PermissionResultAllow = permission.ResultAllow
PermissionResultAllow represents an allow decision.
type PermissionResultDeny ¶
type PermissionResultDeny = permission.ResultDeny
PermissionResultDeny represents a deny decision.
type PermissionRuleValue ¶
type PermissionRuleValue = permission.RuleValue
PermissionRuleValue represents a permission rule.
type PermissionUpdate ¶
type PermissionUpdate = permission.Update
PermissionUpdate represents a permission update request.
type PermissionUpdateDestination ¶
type PermissionUpdateDestination = permission.UpdateDestination
PermissionUpdateDestination represents where permission updates are stored.
type PermissionUpdateType ¶
type PermissionUpdateType = permission.UpdateType
PermissionUpdateType represents the type of permission update.
type PostToolUseFailureHookInput ¶
type PostToolUseFailureHookInput = hook.PostToolUseFailureInput
PostToolUseFailureHookInput is the input for PostToolUseFailure hooks.
type PostToolUseFailureHookSpecificOutput ¶
type PostToolUseFailureHookSpecificOutput = hook.PostToolUseFailureSpecificOutput
PostToolUseFailureHookSpecificOutput is the hook-specific output for PostToolUseFailure.
type PostToolUseHookInput ¶
type PostToolUseHookInput = hook.PostToolUseInput
PostToolUseHookInput is the input for PostToolUse hooks.
type PostToolUseHookSpecificOutput ¶
type PostToolUseHookSpecificOutput = hook.PostToolUseSpecificOutput
PostToolUseHookSpecificOutput is the hook-specific output for PostToolUse.
type PreCompactHookInput ¶
type PreCompactHookInput = hook.PreCompactInput
PreCompactHookInput is the input for PreCompact hooks.
type PreToolUseHookInput ¶
type PreToolUseHookInput = hook.PreToolUseInput
PreToolUseHookInput is the input for PreToolUse hooks.
type PreToolUseHookSpecificOutput ¶
type PreToolUseHookSpecificOutput = hook.PreToolUseSpecificOutput
PreToolUseHookSpecificOutput is the hook-specific output for PreToolUse.
type ResultMessage ¶
type ResultMessage = message.ResultMessage
ResultMessage represents the final result of a query.
type Schema ¶
type Schema = jsonschema.Schema
Schema is a JSON Schema object for tool input validation.
type SchemaBuilder ¶
type SchemaBuilder struct {
// contains filtered or unexported fields
}
SchemaBuilder provides a fluent interface for building JSON schemas.
func NewSchemaBuilder ¶
func NewSchemaBuilder() *SchemaBuilder
NewSchemaBuilder creates a new SchemaBuilder.
func (*SchemaBuilder) Build ¶
func (b *SchemaBuilder) Build() map[string]any
Build returns the complete JSON Schema.
func (*SchemaBuilder) OptionalProperty ¶
func (b *SchemaBuilder) OptionalProperty(name, goType string) *SchemaBuilder
OptionalProperty adds an optional property (not in required list).
func (*SchemaBuilder) OptionalPropertyWithDescription ¶
func (b *SchemaBuilder) OptionalPropertyWithDescription(name, goType, description string) *SchemaBuilder
OptionalPropertyWithDescription adds an optional property with description.
func (*SchemaBuilder) Property ¶
func (b *SchemaBuilder) Property(name, goType string) *SchemaBuilder
Property adds a property with the given name and Go type. The property is marked as required by default.
func (*SchemaBuilder) PropertyWithDescription ¶
func (b *SchemaBuilder) PropertyWithDescription(name, goType, description string) *SchemaBuilder
PropertyWithDescription adds a property with type and description.
type SdkMcpServerInstance ¶
type SdkMcpServerInstance = mcp.ServerInstance
SdkMcpServerInstance is the interface that SDK MCP servers must implement.
type SdkMcpTool ¶
type SdkMcpTool struct {
ToolName string
ToolDescription string
ToolSchema *jsonschema.Schema
ToolHandler SdkMcpToolHandler
ToolAnnotations *mcp.ToolAnnotations
}
SdkMcpTool represents a tool created with NewSdkMcpTool.
func NewSdkMcpTool ¶
func NewSdkMcpTool( name, description string, inputSchema *jsonschema.Schema, handler SdkMcpToolHandler, opts ...SdkMcpToolOption, ) *SdkMcpTool
NewSdkMcpTool creates an SdkMcpTool with optional configuration.
The inputSchema should be a *jsonschema.Schema. Use SimpleSchema for convenience or create a full Schema struct for more control.
Use WithAnnotations to set MCP tool annotations (hints about tool behavior).
Example with SimpleSchema:
addTool := vllmsdk.NewSdkMcpTool("add", "Add two numbers",
vllmsdk.SimpleSchema(map[string]string{"a": "float64", "b": "float64"}),
func(ctx context.Context, req *vllmsdk.CallToolRequest) (*vllmsdk.CallToolResult, error) {
args, _ := vllmsdk.ParseArguments(req)
a, b := args["a"].(float64), args["b"].(float64)
return vllmTextResult(fmt.Sprintf("Result: %v", a+b)), nil
},
vllmsdk.WithAnnotations(&vllmsdk.McpToolAnnotations{
ReadOnlyHint: true,
}),
)
func (*SdkMcpTool) Annotations ¶
func (t *SdkMcpTool) Annotations() *mcp.ToolAnnotations
Annotations returns the tool annotations, or nil if not set.
func (*SdkMcpTool) Description ¶
func (t *SdkMcpTool) Description() string
Description returns the tool description.
func (*SdkMcpTool) Handler ¶
func (t *SdkMcpTool) Handler() SdkMcpToolHandler
Handler returns the tool handler function.
func (*SdkMcpTool) InputSchema ¶
func (t *SdkMcpTool) InputSchema() *jsonschema.Schema
InputSchema returns the JSON Schema for the tool input.
type SdkMcpToolHandler ¶
type SdkMcpToolHandler = mcp.ToolHandler
SdkMcpToolHandler is the function signature for SdkMcpTool handlers. It receives the context and request, and returns the result.
Use ParseArguments to extract input as map[string]any from the request. Use TextResult, ErrorResult, or ImageResult helpers to create results.
Example:
func(ctx context.Context, req *vllmsdk.CallToolRequest) (*vllmsdk.CallToolResult, error) {
args, err := vllmsdk.ParseArguments(req)
if err != nil {
return vllmsdk.ErrorResult(err.Error()), nil
}
a := args["a"].(float64)
return vllmTextResult(fmt.Sprintf("Result: %v", a)), nil
}
type SdkMcpToolOption ¶
type SdkMcpToolOption func(*SdkMcpTool)
SdkMcpToolOption configures an SdkMcpTool during construction.
func WithAnnotations ¶
func WithAnnotations(annotations *mcp.ToolAnnotations) SdkMcpToolOption
WithAnnotations sets MCP tool annotations (hints about tool behavior). Annotations describe properties like whether a tool is read-only, destructive, idempotent, or operates in an open world.
type SdkPluginConfig ¶
type SdkPluginConfig = config.PluginConfig
SdkPluginConfig configures a plugin to load.
type SessionStat ¶
type SessionStat struct {
SessionID string
CreatedAt string
UpdatedAt string
MessageCount int
UserTurns int
CheckpointCount int
FileCheckpointCount int
}
SessionStat contains metadata about a locally persisted SDK session.
func ListSessions ¶
func ListSessions(ctx context.Context, opts ...Option) ([]SessionStat, error)
ListSessions returns local SDK sessions from the configured session store.
func StatSession ¶
StatSession returns metadata for a locally persisted SDK session.
type StreamEvent ¶
type StreamEvent = message.StreamEvent
StreamEvent represents a raw streaming event from the VLLM backend.
type StreamingMessage ¶
type StreamingMessage = message.StreamingMessage
StreamingMessage represents a message sent in streaming mode.
func NewUserMessage ¶
func NewUserMessage(content UserMessageContent) StreamingMessage
NewUserMessage creates a StreamingMessage with type "user". This is a convenience constructor for creating user messages.
type StreamingMessageContent ¶
type StreamingMessageContent = message.StreamingMessageContent
StreamingMessageContent represents the content of a streaming message.
type SubagentStartHookInput ¶
type SubagentStartHookInput = hook.SubagentStartInput
SubagentStartHookInput is the input for SubagentStart hooks.
type SubagentStartHookSpecificOutput ¶
type SubagentStartHookSpecificOutput = hook.SubagentStartSpecificOutput
SubagentStartHookSpecificOutput is the hook-specific output for SubagentStart.
type SubagentStopHookInput ¶
type SubagentStopHookInput = hook.SubagentStopInput
SubagentStopHookInput is the input for SubagentStop hooks.
type SyncHookJSONOutput ¶
type SyncHookJSONOutput = hook.SyncJSONOutput
SyncHookJSONOutput represents a sync hook output.
type SystemMessage ¶
type SystemMessage = message.SystemMessage
SystemMessage represents a system message.
type SystemPromptPreset ¶
type SystemPromptPreset = config.SystemPromptPreset
SystemPromptPreset defines a system prompt preset configuration.
type ThinkingBlock ¶
type ThinkingBlock = message.ThinkingBlock
ThinkingBlock contains model reasoning or thinking output.
type ThinkingConfig ¶
type ThinkingConfig = config.ThinkingConfig
ThinkingConfig controls extended thinking behavior.
type ThinkingConfigAdaptive ¶
type ThinkingConfigAdaptive = config.ThinkingConfigAdaptive
ThinkingConfigAdaptive enables adaptive thinking mode.
type ThinkingConfigDisabled ¶
type ThinkingConfigDisabled = config.ThinkingConfigDisabled
ThinkingConfigDisabled disables extended thinking.
type ThinkingConfigEnabled ¶
type ThinkingConfigEnabled = config.ThinkingConfigEnabled
ThinkingConfigEnabled enables thinking with a specific token budget.
type Tool ¶
type Tool interface {
// Name returns the unique identifier for this tool.
Name() string
// Description returns a human-readable description for the model.
Description() string
// InputSchema returns a JSON schema describing expected input.
// The schema should follow JSON Schema Draft 7 specification.
InputSchema() map[string]any
// Execute runs the tool with the provided input.
// The input will be validated against InputSchema before execution.
Execute(ctx context.Context, input map[string]any) (map[string]any, error)
}
Tool represents a custom tool that the SDK can invoke through VLLM tool calling.
Tools allow users to extend agent capabilities with domain-specific functionality. When registered, the model can discover and execute these tools during a session.
Example:
tool := vllmsdk.NewTool(
"calculator",
"Performs basic arithmetic operations",
map[string]any{
"type": "object",
"properties": map[string]any{
"operation": map[string]any{
"type": "string",
"enum": []string{"add", "subtract", "multiply", "divide"},
},
"a": map[string]any{"type": "number"},
"b": map[string]any{"type": "number"},
},
"required": []string{"operation", "a", "b"},
},
func(ctx context.Context, input map[string]any) (map[string]any, error) {
op := input["operation"].(string)
a := input["a"].(float64)
b := input["b"].(float64)
var result float64
switch op {
case "add":
result = a + b
case "subtract":
result = a - b
case "multiply":
result = a * b
case "divide":
if b == 0 {
return nil, fmt.Errorf("division by zero")
}
result = a / b
}
return map[string]any{"result": result}, nil
},
)
func NewTool ¶
NewTool creates a Tool from a function.
This is a convenience constructor for creating tools without implementing the full Tool interface.
Parameters:
- name: Unique identifier for the tool (e.g., "calculator", "search_database")
- description: Human-readable description of what the tool does
- schema: JSON Schema defining the expected input structure
- fn: Function that executes the tool logic
type ToolPermissionCallback ¶
type ToolPermissionCallback = permission.Callback
ToolPermissionCallback is called before each tool use for permission checking.
type ToolPermissionContext ¶
type ToolPermissionContext = permission.Context
ToolPermissionContext provides context for tool permission callbacks.
type ToolPermissionDeniedError ¶
type ToolPermissionDeniedError = internalerrors.ToolPermissionDeniedError
ToolPermissionDeniedError indicates a tool execution was denied by permission policy.
type ToolResultBlock ¶
type ToolResultBlock = message.ToolResultBlock
ToolResultBlock contains the result of a tool execution.
type ToolUseBlock ¶
type ToolUseBlock = message.ToolUseBlock
ToolUseBlock represents the model invoking a tool.
type ToolsConfig ¶
type ToolsConfig = config.ToolsConfig
ToolsConfig is an interface for configuring available tools. It represents either a list of tool names or a preset configuration.
type ToolsPreset ¶
type ToolsPreset = config.ToolsPreset
ToolsPreset represents a preset configuration for available tools.
type Transport ¶
type Transport interface {
Start(ctx context.Context) error
CreateStream(ctx context.Context, req *ChatRequest) (<-chan map[string]any, <-chan error)
Close() error
}
Transport defines the runtime transport interface.
type UnsupportedControlError ¶
type UnsupportedControlError = controlplane.UnsupportedControlError
UnsupportedControlError indicates a control-plane operation is unsupported by this backend.
type UnsupportedHookEventError ¶
type UnsupportedHookEventError = internalerrors.UnsupportedHookEventError
UnsupportedHookEventError indicates a configured hook event is not supported by this backend.
type UnsupportedHookOutputError ¶
type UnsupportedHookOutputError = internalerrors.UnsupportedHookOutputError
UnsupportedHookOutputError indicates a hook output field is unsupported by this backend.
type UserInputAnswer ¶
UserInputAnswer contains the user's response(s) to a single question.
type UserInputCallback ¶
UserInputCallback handles user-input requests and returns answers.
type UserInputQuestion ¶
UserInputQuestion represents a single user-input prompt.
type UserInputQuestionOption ¶
type UserInputQuestionOption = userinput.QuestionOption
UserInputQuestionOption represents a selectable choice in a user-input question.
type UserInputRequest ¶
UserInputRequest contains parsed user-input payload data.
type UserInputResponse ¶
UserInputResponse contains answers keyed by question ID.
type UserMessage ¶
type UserMessage = message.UserMessage
UserMessage represents a message from the user.
type UserMessageContent ¶
type UserMessageContent = message.UserMessageContent
UserMessageContent represents content that can be either a string or []ContentBlock.
func Blocks ¶
func Blocks(blocks ...ContentBlock) UserMessageContent
Blocks creates block-based user content.
type UserPromptSubmitHookInput ¶
type UserPromptSubmitHookInput = hook.UserPromptSubmitInput
UserPromptSubmitHookInput is the input for UserPromptSubmit hooks.
type UserPromptSubmitHookSpecificOutput ¶
type UserPromptSubmitHookSpecificOutput = hook.UserPromptSubmitSpecificOutput
UserPromptSubmitHookSpecificOutput is the hook-specific output for UserPromptSubmit.
type VLLMAPIMode ¶
type VLLMAPIMode = config.VLLMAPIMode
VLLMAPIMode selects which VLLM API surface to use.
type VLLMAgentOptions ¶
VLLMAgentOptions configures SDK and VLLM request behavior.
type VLLMSDKError ¶
type VLLMSDKError = internalerrors.VLLMSDKError
VLLMSDKError is the base interface for all SDK errors.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
cancellation
command
Package main demonstrates cancellation and graceful shutdown patterns.
|
Package main demonstrates cancellation and graceful shutdown patterns. |
|
client_multi_turn
command
|
|
|
error_handling
command
|
|
|
extended_thinking
command
Package main demonstrates extended thinking capabilities with VLLM.
|
Package main demonstrates extended thinking capabilities with VLLM. |
|
hooks
command
|
|
|
include_partial_messages
command
Package main demonstrates partial message streaming where incremental assistant updates are received as the model generates responses.
|
Package main demonstrates partial message streaming where incremental assistant updates are received as the model generates responses. |
|
interrupt
command
|
|
|
max_budget_usd
command
Package main demonstrates API cost control with budget limits.
|
Package main demonstrates API cost control with budget limits. |
|
mcp_calculator
command
Package main demonstrates how to create calculator tools using MCP servers.
|
Package main demonstrates how to create calculator tools using MCP servers. |
|
mcp_status
command
Package main demonstrates querying MCP server connection status.
|
Package main demonstrates querying MCP server connection status. |
|
memory_tool
command
Package main demonstrates a filesystem-backed memory tool for agent state persistence.
|
Package main demonstrates a filesystem-backed memory tool for agent state persistence. |
|
model_discovery
command
|
|
|
on_user_input
command
|
|
|
parallel_queries
command
Package main demonstrates running multiple Query() calls concurrently.
|
Package main demonstrates running multiple Query() calls concurrently. |
|
permissions
command
|
|
|
pipeline
command
Package main demonstrates multi-step LLM orchestration with Go control flow.
|
Package main demonstrates multi-step LLM orchestration with Go control flow. |
|
query_stream
command
|
|
|
quick_start
command
|
|
|
sdk_tools
command
|
|
|
sessions_local
command
|
|
|
structured_output
command
|
|
|
system_prompt
command
Package main demonstrates configuring system prompts.
|
Package main demonstrates configuring system prompts. |
|
vllm_chat_controls
command
|
|
|
vllm_extra
command
|
|
|
vllm_multimodal_image
command
|
|
|
vllm_multimodal_input
command
|
|
|
vllm_responses
command
|
|
|
vllm_responses_chaining
command
|
|
|
vllm_routing
command
|
|
|
internal
|
|
|
hook
Package hook provides hook types for intercepting runtime events.
|
Package hook provides hook types for intercepting runtime events. |
|
message
Package message provides internal message and content block types.
|
Package message provides internal message and content block types. |
|
permission
Package permission provides permission handling types.
|
Package permission provides permission handling types. |
|
scripts
|
|
|
example_verifier
command
|