API Reference
This page is the compact reference. If you are learning the library, start with Getting Started and Architecture first.
Packages
Section titled “Packages”| Package | Purpose |
|---|---|
github.com/Desarso/godantic | Agent constructors, model helpers, config builder, session re-exports. |
github.com/Desarso/godantic/models | Request, response, message, and tool declaration types. |
github.com/Desarso/godantic/stores | SQLite/Postgres stores and persistence interfaces. |
github.com/Desarso/godantic/common_tools | Built-in tools and tool declaration helpers. |
github.com/Desarso/godantic/sessions | HTTP and WebSocket session internals and interfaces. |
Agent Constructors
Section titled “Agent Constructors”func Create_Agent(model Model, tools []models.FunctionDeclaration, memory ...MemoryManager) Agentfunc Create_Agent_From_Config(config *WSConfig, tools []models.FunctionDeclaration, memory ...MemoryManager) AgentCreate_Agent is the direct path. Create_Agent_From_Config is useful when model/provider configuration is loaded dynamically.
Model Interface
Section titled “Model Interface”type Model interface { Model_Request(models.Model_Request, []models.FunctionDeclaration, []stores.Message) (models.Model_Response, error) Stream_Model_Request(models.Model_Request, []models.FunctionDeclaration, []stores.Message) (<-chan models.Model_Response, <-chan error)}Model Constructors
Section titled “Model Constructors”NewGeminiModel(modelName string)NewOpenRouterModel(modelName string)NewGroqModel(modelName string)NewCerebrasModel(modelName string)NewAnthropicModel(modelName string)With options:
NewAnthropicModelWithOptions(modelName string, temperature *float64, maxTokens *int, systemPrompt string)NewOpenRouterModelWithOptions(modelName string, temperature *float64, maxTokens *int, siteURL, siteName string)NewOpenRouterModelWithBaseURL(modelName, baseURL, apiKeyEnv string, temperature *float64, maxTokens *int)NewGroqModelWithOptions(modelName string, temperature *float64, maxTokens *int, systemPrompt string)NewCerebrasModelWithOptions(modelName string, temperature *float64, maxTokens *int, systemPrompt string, topP *float64, seed *int)Request Types
Section titled “Request Types”type Model_Request struct { User_Message *User_Message `json:"message,omitempty"` Tool_Results *[]Tool_Result `json:"tool_results,omitempty"` Client_ID string `json:"client_id,omitempty"` Input_Mode string `json:"input_mode,omitempty"` Language_Code string `json:"language_code,omitempty"`}type User_Message struct { Role string `json:"role"` Content Content `json:"content"`}
type User_Part struct { Text string `json:"text,omitempty"` InlineData *InlineData `json:"inline_data,omitempty"` ImageData *ImageData `json:"image_data,omitempty"` FileData *FileData `json:"file_data,omitempty"` FunctionResponse *FunctionResponse `json:"function_response,omitempty"`}Response Types
Section titled “Response Types”type Model_Response struct { Parts []Model_Part `json:"parts"` Warnings []HistoryWarning `json:"warnings,omitempty"`}
type Model_Part struct { Text *string `json:"text,omitempty"` FunctionCall *FunctionCall `json:"functionCall,omitempty"` Reasoning *string `json:"reasoning,omitempty"`}
type FunctionCall struct { ID string `json:"id,omitempty"` Name string `json:"name"` Args map[string]interface{} `json:"args"` ThoughtSignature string `json:"thoughtSignature,omitempty"`}HTTP Session
Section titled “HTTP Session”func NewHTTPSession(conversationID string, agent *Agent, store stores.MessageStore) *HTTPSessionCommon methods:
RunSingleInteraction(userMessage models.User_Message) (models.Model_Response, error)RunStreamInteraction(userMessage models.User_Message) (<-chan models.Model_Response, <-chan error)RunSingleInteractionWithRequest(request models.Model_Request) (models.Model_Response, error)RunStreamInteractionWithRequest(request models.Model_Request) (<-chan models.Model_Response, <-chan error)RunSSEInteraction(userMessage models.User_Message, writer SSEWriter, ctx context.Context) errorRunSSEInteractionWithRequest(request models.Model_Request, writer SSEWriter, ctx context.Context) errorGetChatHistory() ([]models.ChatMessageResponse, error)WebSocket Session
Section titled “WebSocket Session”func NewAgentSession( sessionID string, userID string, conn *websocket.Conn, agent *Agent, store stores.MessageStore, memory MemoryManager,) *AgentSessionCommon methods:
RunInteraction(req models.Model_Request) errorRunInteractionWithContext(ctx context.Context, req models.Model_Request) errorSetTraceStore(traceStore stores.TraceStore)Stores
Section titled “Stores”stores.NewSQLiteStoreSimple(dbPath string)stores.NewPostgresStoreSimple(dsn string)stores.NewStore(config *stores.StoreConfig)Store interface:
type MessageStore interface { SaveMessage(sessionID, role, messageType string, parts interface{}, functionID string) error SaveMessageWithUser(sessionID, userID, role, messageType string, parts interface{}, functionID string) error FetchHistory(sessionID string, limit int) ([]Message, error) CreateConversation(convoID, userID string) error ListConversations() ([]string, error) ListConversationsForUser(userID string) ([]ConversationInfo, error) Connect() error Close() error Ping() error}type FunctionDeclaration struct { Name string Description string Parameters Parameters Callable interface{}}Tool registration:
Create_Tool(fn interface{}) (models.FunctionDeclaration, error)Create_Tools(fns []interface{}) ([]models.FunctionDeclaration, error)Direct execution:
agent.ExecuteTool(functionName string, functionCallArgs map[string]interface{}, sessionID string) (string, error)agent.ApproveTool(name string, args map[string]interface{}) (bool, error)Built-in declaration helpers:
common_tools.DefaultTools()common_tools.WebSearchTool()common_tools.WebFetchTool()common_tools.ReadFileTool()common_tools.WriteFileTool()common_tools.EditFileTool()common_tools.ListDirectoryTool()common_tools.ShellExecTool()Config Builder
Section titled “Config Builder”config := godantic.NewWSConfig(). WithOpenRouter("openai/gpt-4o-mini"). WithSystemPrompt("You are concise and helpful."). WithSQLiteStore("chat.sqlite"). WithTools([]interface{}{common_tools.Brave_Search}). WithTemperature(0.2). WithMaxTokens(2048)Provider helpers:
WithProvider(provider ModelProvider)WithOpenRouter(model string)WithGroq(model string)WithCerebras(model string)WithAnthropic(model string)WithModelName(modelName string)