polaris

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2025 License: MIT Imports: 19 Imported by: 0

README

polaris: A Distributed AI Agent Framework for Function Calling

MIT License GoDoc Go Report Card Releases

polaris is a Go framework for building distributed AI agents.

These agents run as lightweight sidecars alongside your applications, securely exposing system capabilities and local resources (like logs or metrics) via Function Calling. This enables AI models (such as Google's Vertex AI Gemini) to intelligently interact with your distributed infrastructure through a unified polaris interface, simplifying complex coordination. The framework is designed for parallel execution to handle demanding workloads.

Why polaris ?

Building robust server-side Function Calling, especially in distributed systems, presents significant hurdles:

  • Schema Management Complexity: Keeping function definitions consistent across multiple services is challenging.
  • Coordination Difficulties: Orchestrating interactions between services (RPC) often requires complex transport logic and boilerplate code.
  • Integration Friction: Adding Function Calling capabilities to existing services can demand substantial code modifications.

polaris is a distributed AI agent framework designed to simplify this.

It offers a novel approach focused on ease of use and intelligent coordination:

  • Centralized registry Cluster: Provides a highly available, central point for managing function schemas and discovering services, eliminating synchronization headaches.
  • Lightweight Sidecar Agents: polaris agents run alongside your applications as sidecars. This minimizes the need for direct code integration into your existing services.
  • Context-Aware Execution: The sidecar model allows agents to directly access local context, such as logs or metrics. This enables smarter Function Calling – for example, an agent can analyze local server logs and metrics simultaneously to diagnose an issue.
  • Efficient Operation: Currently leverages Gemini for its reasoning, requiring minimal computational resources on the agent side.

In essence, polaris enables "AI-driven RPC" – using the power of Function Calling to intelligently orchestrate procedure calls across your distributed system, simplifying development and unlocking new possibilities for AI agent collaboration.

Features

  1. Distributed Agent Architecture: Deploy lightweight polaris agents across your infrastructure (servers, containers). Each agent registers specific functions, making local resources or actions available network-wide.
  2. Access Local Resources via AI: Enable AI models to securely query log files, fetch system status, execute commands, or interact with other server-local resources through the Function Calls exposed by your distributed agents.
  3. Parallel Execution: Handles heavy workloads efficiently by executing incoming Function Call requests in parallel across agents, preventing bottlenecks.
  4. Simplified JSON Schema: Define function parameters and responses with a much more concise and readable syntax compared to standard library methods.
  5. Simple Agent Implementation: Easily define and register functions ("Tools") within a polaris agent to interact with local files, APIs, or system commands.
  6. Vertex AI Gemini Focused: Optimized for seamless integration and interaction with Vertex AI Gemini models for orchestrating function calls.
  7. Support MCP (Experimental): Tools can be integrated with MCP (see _example/mcp-tool)

Installation

go get github.com/octu0/polaris

Architecture overview

Polaris Architecture

Simplified JSON Schema Definition

Defining the structure (Schema) for your functions is significantly easier with polaris compared to standard Go structures for AI Function Calling.

Traditional Method (e.g., using genai library):

FunctionDeclarations: []*genai.FunctionDeclaration{
    {
        Name:        "FuncName",
        Description: "FuncDesc",
        Parameters: &genai.Schema{
            Type: genai.TypeObject,
            Properties: map[string]*genai.Schema{
                "param1": {
                    Type:        genai.TypeString,
                    Description: "desc param1",
                },
                "param2": {
                    Type:        genai.TypeInteger,
                    Description: "desc param2",
                },
                "param3": {
                    Type:        genai.TypeArray,
                    Description: "desc param3",
                    Items: &genai.Schema{
                        Type: genai.TypeObject,
                        Properties: map[string]*genai.Schema{
                            "param4": {
                                Type:        genai.TypeString,
                                Description: "desc param4",
                            },
                            "param5": {
                                Type:        genai.TypeBool,
                                Description: "desc param5",
                            },
                        },
                    },
                },
            },
            Required: []string{"param1", "param2"},
        },
        Response: &genai.Schema{
            Type: genai.TypeObject,
            Properties: map[string]*genai.Schema{
                "result1": {
                    Type: genai.TypeString,
                    Description: "result1",
                },
                "result2": {
                    Type: genai.TypeString,
                    Description: "result2",
                },
            },
            Required: []string{"result1"},
        },
    },
}

With polaris:

tool := Tool{
    Name:        "FuncName",
    Description: "FuncDesc",
    Parameters: Object{
        Properties: Properties{
            "param1": String{ Description: "desc param1", Required: true },
            "param2": Int{ Description: "desc param2", Required: true },
            "param3": ObjectArray{
                Description: "desc param3",
                Items: Properties{
                    "param4": String{ Description: "desc param4" },
                    "param5": Bool{ Description: "desc param5" },
                },
            },
        },
    },
    Response: Object{
        Properties: Properties{
            "result1": String{ Description: "result1", Required: true },
            "result2": String{ Description: "result2" },
        },
    },
}

Implementing polaris Agent/Tool

You can easily create a standalone agent (or integrate polaris into an existing service) that registers specific 'Tools' (Functions). This agent runs, connects to the registry, and listens for requests (orchestrated by the AI) to execute its registered tools.

package main

import (
    "fmt"
    "os"

    "github.com/octu0/polaris"
)

// Example: Tool to read the last N lines of a specific log file
func registerLogReaderAgent(conn *polaris.Conn, logFilePath string) error {
    // Ensure the log file exists (basic check)
    if _, err := os.Stat(logFilePath); os.IsNotExist(err) {
        return fmt.Errorf("log file not found: %s", logFilePath)
    }

    return conn.RegisterTool(polaris.Tool{
        Name:        "read_log_file",
        Description: fmt.Sprintf("Reads the last N lines from the log file: %s", logFilePath),
        Parameters: polaris.Object{
            Properties: polaris.Properties{
                "lines": polaris.Int{
                    Description: "Number of lines to read from the end of the file",
                    Required:    true,
                    Default:     10,
                },
            },
        },
        Response: polaris.Object{
            Properties: polaris.Properties{
                "log_content": polaris.String{
                    Description: "The last N lines of the log file",
                    Required:    true,
                },
            },
        },
        // The handler function implements the tool's logic
        Handler: func(r *polaris.ReqCtx) error {
            linesToRead := r.Int("lines")
            if linesToRead <= 0 {
                linesToRead = 10 // Use default if invalid
            }

            // --- Placeholder for actual file reading logic ---
            // In a real implementation, you would securely read the
            // last 'linesToRead' lines from 'logFilePath'.
            // Example (conceptual, needs robust implementation):
            // content, err := readLastLines(logFilePath, linesToRead)
            // if err != nil {
            //     return fmt.Errorf("failed to read log file: %w", err)
            // }
            // --- End Placeholder ---

            // Dummy content for example:
            content := fmt.Sprintf("Read last %d lines of %s (implementation pending)", linesToRead, logFilePath)

            r.Set(polaris.Resp{
                "log_content": content,
            })
            return nil // Return nil on success
        },
    })
}

func main() {
    // Example: Run an agent exposing a log reader tool
    logFileToMonitor := "/var/log/app.log" // Example log file path

    // Connect the agent to the polaris registry
    conn, err := polaris.Connect(polaris.ConnectAddress("127.0.0.1", "4222"))
    if err != nil {
        panic(fmt.Sprintf("Agent failed to connect: %v", err))
    }
    defer conn.Close()
    fmt.Printf("Agent connected, monitoring %s\n", logFileToMonitor)

    // Register the specific tool this agent provides
    if err := registerLogReaderAgent(conn, logFileToMonitor); err != nil {
        panic(fmt.Sprintf("Agent failed to register tool: %v", err))
    }
    fmt.Println("Log reader tool registered successfully.")

    // Keep the agent running to listen for function call requests
    fmt.Println("Agent running...")
    <-make(chan struct{}) // Block forever
}

Usage Example: AI Orchestrating Distributed Agents

From your central application or AI orchestrator service, connect to the polaris registry.
An AI model like Gemini can then discover and invoke functions hosted by your distributed polaris agents based on user prompts. The AI doesn't need to know where the agent is running, only that the function is available.

package main

import (
    "context"
    "fmt"

    "github.com/octu0/polaris"
)

func main() {
    ctx := context.Background()

    // Connect to the polaris registry (same network as the agents)
    conn, err := polaris.Connect(polaris.ConnectAddress("127.0.0.1", "4222"))
    if err != nil {
        panic(err)
    }
    defer conn.Close()
    fmt.Println("Orchestrator connected.")

    // Create a session with Vertex AI Gemini
    // Ensure your environment is configured for Vertex AI authentication
    session, err := conn.Use(
        ctx,
        polaris.UseModel("gemini-2.5-pro-exp-03-25"),
        polaris.UseSystemInstruction(
            polaris.AddTextSystemInstruction("You can interact with server logs using available tools."),
        ),
        polaris.UseTemperature(0.2),
    )
    if err != nil {
        panic(fmt.Sprintf("Failed to create AI session: %v", err))
    }
    defer session.Close()
    fmt.Println("AI session created.")

    // Define the prompt for the AI, asking it to use a tool potentially hosted on a remote agent
    prompt := `
        Can you show me the last 5 lines from the /var/log/app.log file?
    `
    fmt.Printf("Sending prompt to AI: %s\n", prompt)

    // Send the prompt. polaris + Gemini will find the 'read_log_file' tool
    // (registered by one of the agents) and attempt to call it.
    it, err := session.SendText(prompt)
    if err != nil {
        panic(fmt.Sprintf("Failed to send prompt: %v", err))
    }

    // Stream and print the AI's response
    fmt.Println("AI Response:")
    for msg, err := range it {
        if err != nil {
            // Handle potential errors during streaming (e.g., function call failure)
            fmt.Printf("Error during response stream: %v\n", err)
            break
        }
        fmt.Println(msg) // Print the content part of the message
    }
    fmt.Println("Interaction complete.")
}

Usage Example: Simple LLM call with JSON Schema

It can be used without linking with Tool/Agent. You can get the data in any format by specifying JSON Schema.

package main

import (
    "context"
    "fmt"

    "github.com/octu0/polaris"
)

func main() {
    ctx := context.TODO()

    gen, err := polaris.GenerateJSON(
        ctx,
        polaris.UseModel("gemini-2.5-pro-exp-03-25"),
        polaris.UseTemperature(0.2),
        polaris.UseJSONOutput(polaris.Object{
            Description: "result of each",
            Properties: polaris.Properties{
                "resultA": polaris.Int{
                    Description: "result 1",
                    Required:    true,
                },
                "resultB": polaris.Int{
                    Description: "result 2",
                    Required:    true,
                },
            },
        }),
    )
    if err != nil {
        panic(err)
    }

    prompt := `
        execute this task:
        1. Sum 35 and 21
        2. multiply by 88 using one previous answer.
    `
    resp, err := gen(prompt)
    if err != nil {
        panic(err)
    }
    fmt.Println(resp)
}

Other Examples

See _example for examples of other cases.

Dependencies

Using polaris, AI orchestration capabilities, requires bellow:

  1. Google Cloud Project:
    • Access to a Google Cloud project where you can enable APIs and manage resources.
  2. Vertex AI API Enabled:
    • The Vertex AI API must be enabled within your Google Cloud project.
  3. Authentication:
    • Environment Variables:
      • GOOGLE_APPLICATION_CREDENTIALS: Set this to the path of your service account key JSON file.
      • GOOGLE_CLOUD_PROJECT: Set this to your Google Cloud Project ID.

License

MIT, see LICENSE file for details.

Documentation

Overview

Example (JsonOutput_outputSchema)
ctx := context.TODO()

gen, err := GenerateJSON(
	ctx,
	UseModel("gemini-2.5-pro-exp-03-25"),
	UseTemperature(0.2),
	UseJSONOutput(Object{
		Description: "result of each",
		Properties: Properties{
			"resultA": Int{
				Description: "result 1",
				Required:    true,
			},
			"resultB": Int{
				Description: "result 2",
				Required:    true,
			},
		},
	}),
)
if err != nil {
	panic(err)
}

prompt := `
		execute this task:
		1. Sum 35 and 21
		2. multiply by 88 using one previous answer.
	`
resp, err := gen(prompt)
if err != nil {
	panic(err)
}
fmt.Println("resultA=", resp["resultA"])
fmt.Println("resultB=", resp["resultB"])
Output:

resultA= 56
resultB= 4928
Example (JsonOutput_promptInstruction)
ctx := context.TODO()

session, err := Generate(
	ctx,
	UseModel("gemini-2.5-pro-exp-03-25"),
	UseTemperature(0.2),
	UseJSONOutput(nil),
)
if err != nil {
	panic(err)
}
defer session.Close()

prompt := `
		execute this task:
		1. Sum 35 and 21
		2. multiply by 88 using one previous answer.
		3. Return the result by following "JSONSchema" format.

		output(JSONSchema):
		ret={
			"resultA": int,
			"resultB": int,
		}
		Return: ret
	`
it, err := session.SendText(prompt)
if err != nil {
	panic(err)
}
for msg, err := range it {
	if err != nil {
		panic(err)
	}
	fmt.Println(msg)
}
Output:

{
  "resultA": 56,
  "resultB": 4928
}

Index

Examples

Constants

View Source
const (
	TopicRegisterTool   string = "polaris:tool:register"
	TopicUnregisterTool string = "polaris:tool:unregister"
	TopicToolKeepalive  string = "polaris:tool:keepalive"
	TopicListTool       string = "polaris:tool:list"
)
View Source
const (
	AppName string = "polaris"
	Version string = "1.3.1"
)

Variables

This section is empty.

Functions

func AddBinarySystemInstruction

func AddBinarySystemInstruction(data []byte, mimeType string) func() []genai.Part

func AddTextSystemInstruction

func AddTextSystemInstruction(values ...string) func() []genai.Part

func GobEncoder

func GobEncoder[T any]() *gobEncoder[T]

cloud.google.com/go/vertexai/genai are not support json

func JSONEncoder

func JSONEncoder[T any]() *jsonEncoder[T]

google.golang.org/genai supports json

Types

type Array

type Array struct {
	Description string
	Items       TypeDef
	Required    bool
	Nullable    NullableType
}
*genai.Schema{
  Type:        genai.TypeArray,
  Description: "...",
  Items:       &genai.Schema{...},
}

func (Array) IsRequired

func (a Array) IsRequired() bool

func (Array) Schema

func (a Array) Schema() *genai.Schema

type Bool

type Bool struct {
	Description string
	Default     bool
	Required    bool
	Nullable    NullableType
}
*genai.Schema{
  Type:        genai.TypeBoolean,
  Description: "...",
}

func (Bool) IsRequired

func (b Bool) IsRequired() bool

func (Bool) Schema

func (b Bool) Schema() *genai.Schema

type BoolArray

type BoolArray struct {
	Description     string
	ItemDescription string
	Required        bool
	Nullable        NullableType
}
	*genai.Schema{
	  Type:        genai.TypeArray,
	  Description: "...",
	  Items:       &genai.Schema{
     Type:        genai.TypeBoolean,
     Description: "...",
   },
	}

func (BoolArray) IsRequired

func (ba BoolArray) IsRequired() bool

func (BoolArray) Schema

func (ba BoolArray) Schema() *genai.Schema

type Conn

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

func Connect

func Connect(options ...ConnectOptionFunc) (*Conn, error)

func (*Conn) Call added in v1.1.0

func (c *Conn) Call(ctx context.Context, name string, req Req) (Resp, error)

func (*Conn) Close

func (c *Conn) Close()

func (*Conn) RegisterSSEMCPTools added in v1.2.4

func (c *Conn) RegisterSSEMCPTools(baseURL string, initReq mcp.InitializeRequest, options ...transport.ClientOption) error

func (*Conn) RegisterTool

func (c *Conn) RegisterTool(t Tool) error

func (*Conn) Tool added in v1.1.0

func (c *Conn) Tool(name string) (Tool, bool)

func (*Conn) UnregisterTools

func (c *Conn) UnregisterTools() error

func (*Conn) Use

func (c *Conn) Use(ctx context.Context, options ...UseOptionFunc) (Session, error)

type ConnectOption

type ConnectOption struct {
	NatsURL        []string
	Name           string
	Host           string
	Port           string
	UseTLS         bool
	AuthUser       string
	AuthPassword   string
	NoRandomize    bool
	NoEcho         bool
	Timeout        time.Duration
	AllowReconnect bool
	MaxReconnects  int
	ReconnectWait  time.Duration
	ReqTimeout     time.Duration
}

type ConnectOptionFunc

type ConnectOptionFunc func(*ConnectOption)

func AllowReconnect

func AllowReconnect(allowReconnect bool) ConnectOptionFunc

func ConnectAddress

func ConnectAddress(host, port string) ConnectOptionFunc

func ConnectAuth

func ConnectAuth(user, password string) ConnectOptionFunc

func ConnectNoEcho

func ConnectNoEcho(noEcho bool) ConnectOptionFunc

func ConnectNoRandomize

func ConnectNoRandomize(noRandomize bool) ConnectOptionFunc

func ConnectTLS

func ConnectTLS(useTLS bool) ConnectOptionFunc

func ConnectTimeout

func ConnectTimeout(timeout time.Duration) ConnectOptionFunc

func MaxReconnects

func MaxReconnects(maxReconnects int) ConnectOptionFunc

func Name

func Name(name string) ConnectOptionFunc

func NatsURL

func NatsURL(url ...string) ConnectOptionFunc

func ReconnectWait

func ReconnectWait(reconnectWait time.Duration) ConnectOptionFunc

func RequestTimeout added in v1.2.2

func RequestTimeout(timeout time.Duration) ConnectOptionFunc

type Encoder

type Encoder[T any] interface {
	Encode(v T) ([]byte, error)
	Decode([]byte) (T, error)
}

type ErrorHandler added in v1.2.3

type ErrorHandler func(error)

type Float

type Float struct {
	Description string
	Default     float64
	Required    bool
	Nullable    NullableType
}
*genai.Schema{
  Type:        genai.TypeNumber,
  Description: "...",
}

func (Float) IsRequired

func (f Float) IsRequired() bool

func (Float) Schema

func (f Float) Schema() *genai.Schema

type FloatArray

type FloatArray struct {
	Description     string
	ItemDescription string
	Required        bool
	Nullable        NullableType
}
	*genai.Schema{
	  Type:        genai.TypeArray,
	  Description: "...",
	  Items:       &genai.Schema{
     Type:        genai.TypeNumber,
     Description: "...",
   },
	}

func (FloatArray) IsRequired

func (fa FloatArray) IsRequired() bool

func (FloatArray) Schema

func (fa FloatArray) Schema() *genai.Schema

type GenerateJSONFunc added in v1.2.0

type GenerateJSONFunc func(...string) (Resp, error)

func GenerateJSON added in v1.1.0

func GenerateJSON(ctx context.Context, options ...UseOptionFunc) (GenerateJSONFunc, error)

type Int

type Int struct {
	Description string
	Default     int
	Required    bool
	Nullable    NullableType
}
*genai.Schema{
  Type:        genai.TypeInteger,
  Description: "...",
}

func (Int) IsRequired

func (i Int) IsRequired() bool

func (Int) Schema

func (i Int) Schema() *genai.Schema

type IntArray

type IntArray struct {
	Description     string
	ItemDescription string
	Required        bool
	Nullable        NullableType
}
	*genai.Schema{
	  Type:        genai.TypeArray,
	  Description: "...",
	  Items:       &genai.Schema{
     Type:        genai.TypeInteger,
     Description: "...",
   },
	}

func (IntArray) IsRequired

func (ia IntArray) IsRequired() bool

func (IntArray) Schema

func (ia IntArray) Schema() *genai.Schema

type IntEnum

type IntEnum struct {
	Description string
	Values      []string
	Required    bool
	Nullable    NullableType
}
	*genai.Schema{
	  Type:        genai.TypeInteger,
	  Description: "...",
   Enum:        []string{"100", "200", "300"},
   Format:      "enum",
	}

func (IntEnum) IsRequired

func (ie IntEnum) IsRequired() bool

func (IntEnum) Schema

func (ie IntEnum) Schema() *genai.Schema

type LiveSession

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

func (*LiveSession) Close

func (s *LiveSession) Close() error

func (*LiveSession) JSONOutput added in v1.1.0

func (s *LiveSession) JSONOutput() bool

func (*LiveSession) SendText

func (s *LiveSession) SendText(values ...string) (iter.Seq2[string, error], error)

type Logger

type Logger interface {
	Debugf(string, ...any)
	Infof(string, ...any)
	Warnf(string, ...any)
	Errorf(string, ...any)
}

type NullableType

type NullableType string
const (
	NullableYes NullableType = "yes"
	NullableNo  NullableType = "no"
)

func (NullableType) Nullable

func (n NullableType) Nullable() bool

type Object

type Object struct {
	Description string
	Properties  Properties
	Required    bool
	Nullable    NullableType
}
*genai.Schema{
  Type:        genai.TypeObject,
  Description: "...",
  Properties:  map[string]*genai.Schema{...},
}

func (Object) IsRequired

func (o Object) IsRequired() bool

func (Object) Schema

func (o Object) Schema() *genai.Schema

type ObjectArray

type ObjectArray struct {
	Description     string
	ItemDescription string
	Required        bool
	Nullable        NullableType
	Items           Properties
}
	*genai.Schema{
	  Type:        genai.TypeArray,
	  Description: "...",
	  Items:       &genai.Schema{
     Type:        genai.TypeObject,
     Properties:  map[string]*genai.Schema{
       ...
     },
   },
	}

func (ObjectArray) IsRequired

func (oa ObjectArray) IsRequired() bool

func (ObjectArray) Schema

func (oa ObjectArray) Schema() *genai.Schema

type Properties

type Properties map[string]TypeDef

type Registry

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

func CreateRegistry

func CreateRegistry(opts ...RegistryOption) (*Registry, error)

func (*Registry) Close

func (r *Registry) Close()

type RegistryClusterOption

type RegistryClusterOption func(*server.ClusterOpts)

func WithClussterAdvertise

func WithClussterAdvertise(advertise string) RegistryClusterOption

func WithClusterHost

func WithClusterHost(host string) RegistryClusterOption

func WithClusterName

func WithClusterName(name string) RegistryClusterOption

func WithClusterPort

func WithClusterPort(port int) RegistryClusterOption

type RegistryOption

type RegistryOption func(*server.Options)

func WithBind

func WithBind(host string, port int) RegistryOption

func WithClusterOption

func WithClusterOption(opts ...RegistryClusterOption) RegistryOption

func WithMaxPayload

func WithMaxPayload(size int32) RegistryOption

func WithRoutes

func WithRoutes(routesStr string) RegistryOption

type Req added in v1.1.0

type Req = jsonMap

type ReqCtx added in v1.3.0

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

func (*ReqCtx) Bool added in v1.3.0

func (c *ReqCtx) Bool(key string) bool

func (*ReqCtx) Float64 added in v1.3.0

func (c *ReqCtx) Float64(key string) float64

func (*ReqCtx) FloatArray added in v1.3.0

func (c *ReqCtx) FloatArray(key string) []float64

func (*ReqCtx) Int added in v1.3.0

func (c *ReqCtx) Int(key string) int

func (*ReqCtx) IntArray added in v1.3.0

func (c *ReqCtx) IntArray(key string) []int

func (*ReqCtx) Object added in v1.3.0

func (c *ReqCtx) Object(key string) *ReqCtx

func (*ReqCtx) ObjectArray added in v1.3.0

func (c *ReqCtx) ObjectArray(key string) []*ReqCtx

func (*ReqCtx) Req added in v1.3.0

func (c *ReqCtx) Req() Req

func (*ReqCtx) String added in v1.3.0

func (c *ReqCtx) String(key string) string

func (*ReqCtx) StringArray added in v1.3.0

func (c *ReqCtx) StringArray(key string) []string

type Resp

type Resp = jsonMap

type RespError

type RespError struct {
	Success bool   `json:"success"`
	Msg     string `json:"msg"`
}

func (RespError) Err

func (e RespError) Err() error

func (RespError) String

func (e RespError) String() string

type Session

type Session interface {
	SendText(...string) (iter.Seq2[string, error], error)
	Close() error
	JSONOutput() bool
}

func Generate added in v1.2.0

func Generate(ctx context.Context, options ...UseOptionFunc) (Session, error)

type String

type String struct {
	Description string
	Default     string
	Required    bool
	Nullable    NullableType
}
*genai.Schema{
  Type:       genai.TypeString,
  Description "...",
}

func (String) IsRequired

func (s String) IsRequired() bool

func (String) Schema

func (s String) Schema() *genai.Schema

type StringArray

type StringArray struct {
	Description     string
	ItemDescription string
	Required        bool
	Nullable        NullableType
}
	*genai.Schema{
	  Type:        genai.TypeArray,
	  Description: "...",
	  Items:       &genai.Schema{
     Type:        genai.TypeString,
     Description: "...",
   },
	}

func (StringArray) IsRequired

func (sa StringArray) IsRequired() bool

func (StringArray) Schema

func (sa StringArray) Schema() *genai.Schema

type StringEnum

type StringEnum struct {
	Description string
	Values      []string
	Required    bool
	Nullable    NullableType
}
	*genai.Schema{
	  Type:        genai.TypeString,
	  Description: "...",
   Enum:        []string{"north", "east", "south", "west"},
   Format:      "enum",
	}

func (StringEnum) IsRequired

func (se StringEnum) IsRequired() bool

func (StringEnum) Schema

func (se StringEnum) Schema() *genai.Schema

type SystemInstructionOptfion

type SystemInstructionOptfion func() []genai.Part

type Tool

type Tool struct {
	Name         string
	Description  string
	Parameters   Object
	Response     Object
	Handler      ToolHandler
	ErrorHandler ErrorHandler
}

func (Tool) FunctionDeclaration

func (t Tool) FunctionDeclaration() genai.FunctionDeclaration

type ToolHandler

type ToolHandler func(*ReqCtx) (Resp, error)

type TypeDef

type TypeDef interface {
	Schema() *genai.Schema
	IsRequired() bool
}

type UseOption

type UseOption struct {
	Model              string
	UseLocalTool       bool
	SystemInstructions []genai.Part
	Temperature        float32
	TopP               float32
	MaxOutputTokens    int32
	JSONOutput         bool
	OutputSchema       TypeDef
	Logger             Logger
	DebugMode          bool
	DefaultArgsFunc    func() map[string]any
}

type UseOptionFunc

type UseOptionFunc func(*UseOption)

func UseDebugMode

func UseDebugMode(enable bool) UseOptionFunc

func UseDefaultArgs

func UseDefaultArgs(fn func() map[string]any) UseOptionFunc

func UseJSONOutput

func UseJSONOutput(schema TypeDef) UseOptionFunc

func UseLocalTool

func UseLocalTool(enable bool) UseOptionFunc

func UseLogger

func UseLogger(lg Logger) UseOptionFunc

func UseMaxOutputTokens

func UseMaxOutputTokens(size int32) UseOptionFunc

func UseModel

func UseModel(name string) UseOptionFunc

func UseSystemInstruction

func UseSystemInstruction(sysInstructionOptions ...SystemInstructionOptfion) UseOptionFunc

func UseTemperature

func UseTemperature(v float32) UseOptionFunc

func UseToolJSONOutput added in v1.1.0

func UseToolJSONOutput(conn *Conn, toolName string) UseOptionFunc

func UseTopP

func UseTopP(v float32) UseOptionFunc

Jump to

Keyboard shortcuts

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