frags

package module
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: AGPL-3.0 Imports: 31 Imported by: 2

README

Welcome to Frags

Note: The project is still in development, but you can already try it out.

What is Frags?

Frags is an advanced AI/LLM Agent dedicated to executing complex workflows of data retrieval, transformation, extraction and aggregation. It is designed to be highly customizable and extensible, allowing you to integrate it with your own tools and processes. Its main goal is precision and focus, and it's a system dedicated to engineers and specialists rather than a code-free quick fix.

Frags comes as a CLI tool and as a library to be integrated into Golang projects.

Main features
  • Multi LLM: Frags supports multiple LLMs, allowing you to choose the one that best suits your needs.
  • Dedicated almost exclusively to producing structured content: the purpose of Frags is to be integrated in advanced workflows, therefore its output needs to be perfectly predictable and consumable by a machine.
  • Orchestration system: Frags is not an agent to which you ask a question a simple answer back. The whole purpose of Frags is to allow the user to describe complex data retrieval, transformation, extraction and aggregation to produce complex data structures.
  • Advanced support for tools: Frags has a whole standardized system to integrate with internal (as in: provided by the integrator) and external tools (as in: MCP servers).
  • Anti-context-bloating: Frags multi-session system allows you to define and organize what is present in the LLM context, based on the session task, improving focus and reducing the risk of hallucinations
  • Output segmentation: Frags allows you to segment your output into multiple parts, allowing you to overcome output token limitations, and improving answer quality.
  • Advanced pre/post-processing: Frags allows you to define custom pre/post-processing steps, scripts, tools, and transformers, reducing the amount of LLM work where not necessary, reducing cost, improving performance and answer quality.
  • Modularity: Frags is designed to be easily extensible, allowing you to add new features and integrate them with your own tools.
Use cases
  • Research/Paper: when your needs go beyond getting a straight answer, but need a whole structured research on sophisticated topics. The context reduction, focus enhancement, document ingestion combined with internet search allows you to design how your paper should contain in each section, allowing the LLM to focus on each objective and produce data you can process however you want.
  • Data extraction: Frags allows you to define complex data extraction pipelines, allowing you to extract data from documents, making sure the output is structured and predictable. This makes it easy to plug into other systems that expect predefined fields and values.
  • Data transformation/analysis: From data retrieval (via the Internet, databases or any MCP tool available) to analysis or transformation, Frags can guide the process and provide solid data structures, skimming the context and increasing the credibility of the results.
  • Reporting: Connect Frags to data sources and define complex reporting templates that describe the entire status of a system, division or company. Connect the output to a reporting tool to produce quality reports.
  • Notes augmentation: give Frags your notes and design how you want the LLM to expand them into a fully featured document.
  • Chatbot augmentation: improve your chatbot from an "answers machine" to an "explanation engine."
  • Creative writing: Frags can be used to generate creative content, allowing you to design how your writing should look like, and how it should be structured.

Find the full documentation in the Frags Wiki

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MergeJSONInto added in v0.6.0

func MergeJSONInto(target interface{}, jsonBytes []byte) error

MergeJSONInto unmarshals jsonBytes into target (which must be a pointer to a struct or pointer to a map). Top-level (direct children of the root) slice/array fields are appended to (not replaced). Top-level map fields are merged (keys inserted/overwritten). Other fields are overwritten. Nested objects deeper than the root are unmarshaled normally.

Types

type Ai

type Ai interface {
	Ask(ctx *util.FragsContext, text string, schema *schema.Schema, tools ToolDefinitions, runner ExportableRunner, resources ...resources.ResourceData) ([]byte, error)
	New() Ai
	SetFunctions(functions ExternalFunctions)
	RunFunction(ctx *util.FragsContext, functionCall FunctionCaller, runner ExportableRunner) (any, error)
	SetSystemPrompt(systemPrompt string)
}

Ai is an interface for AI models.

type CollectionConfig added in v0.12.0

type CollectionConfig struct {
	Params   map[string]string `json:"params,omitempty"`
	Disabled bool              `json:"disabled"`
}

CollectionConfig defines the configuration for a collection

type Components added in v0.3.0

type Components struct {
	Prompts map[string]string        `yaml:"prompts" json:"prompts,omitempty"`
	Schemas map[string]schema.Schema `yaml:"schemas" json:"schemas,omitempty"`
}

Components holds the reusable components of the sessions and schema

type Dependencies added in v0.3.0

type Dependencies []Dependency

Dependencies is a list of Dependencies

type Dependency added in v0.3.0

type Dependency struct {
	Session    *string `json:"session" yaml:"session"`
	Expression *string `json:"expression" yaml:"expression"`
}

Dependency defines whether this session can run or should: * wait on another Session to complete * run at all, based on an Expression

type DependencyCheckResult added in v0.3.0

type DependencyCheckResult string

DependencyCheckResult is the result of a dependency check.

const (
	DependencyCheckPassed     DependencyCheckResult = "passed"
	DependencyCheckFailed     DependencyCheckResult = "failed"
	DependencyCheckUnsolvable DependencyCheckResult = "unsolvable"
)

type DummyAi

type DummyAi struct {
	History []dummyHistoryItem
}

DummyAi is a dummy AI model for testing purposes.

func NewDummyAi

func NewDummyAi() *DummyAi

NewDummyAi returns a new DummyAi instance.

func (*DummyAi) Ask

func (d *DummyAi) Ask(_ *util.FragsContext, text string, schema *schema.Schema, _ ToolDefinitions, _ ExportableRunner, resources ...resources.ResourceData) ([]byte, error)

Ask returns a dummy response for testing purposes.

func (*DummyAi) New

func (d *DummyAi) New() Ai

func (*DummyAi) RunFunction added in v0.7.0

func (d *DummyAi) RunFunction(_ *util.FragsContext, _ FunctionCaller, _ ExportableRunner) (any, error)

func (*DummyAi) SetFunctions added in v0.5.0

func (d *DummyAi) SetFunctions(_ ExternalFunctions)

func (*DummyAi) SetSystemPrompt added in v0.6.0

func (d *DummyAi) SetSystemPrompt(_ string)

type DummyScriptEngine added in v0.10.0

type DummyScriptEngine struct{}

func (*DummyScriptEngine) RunCode added in v0.10.0

type ExportableRunner added in v0.9.0

type ExportableRunner interface {
	Transformers() *Transformers
	RunFunction(ctx *util.FragsContext, name string, args map[string]any) (any, error)
	ScriptEngine() ScriptEngine
	Logger() *log.StreamerLogger
}

type ExternalFunction added in v0.19.0

type ExternalFunction struct {
	Func        func(ctx *util.FragsContext, data map[string]any) (any, error) `yaml:"-"`
	Name        string                                                         `yaml:"name"`
	Collection  string                                                         `yaml:"collection"`
	Description string                                                         `yaml:"description"`
	Schema      *schema.Schema                                                 `yaml:"schema"`
}

ExternalFunction represents a function that can be called by the AI model. Name is the function name. ToolsCollection is the MCP server or collection that contains the function. Description is the function description Schema is the input schema for the function.

func (ExternalFunction) Run added in v0.19.0

func (f ExternalFunction) Run(ctx *util.FragsContext, args map[string]any, runner ExportableRunner) (any, error)

Run runs the function, applying any transformers defined in the runner.

func (ExternalFunction) String added in v0.19.0

func (f ExternalFunction) String() string

type ExternalFunctions added in v0.19.0

type ExternalFunctions map[string]ExternalFunction

ExternalFunctions is a map of functions, indexed by name.

func (ExternalFunctions) Get added in v0.19.0

Get returns a function by name.

func (ExternalFunctions) ListByCollection added in v0.19.0

func (f ExternalFunctions) ListByCollection(collection string) ExternalFunctions

ListByCollection returns a subset of functions, filtered by MCP server or collection

func (ExternalFunctions) String added in v0.19.0

func (f ExternalFunctions) String() string

type FunctionCallDestination added in v0.15.0

type FunctionCallDestination string
const (
	AiFunctionCallDestination      FunctionCallDestination = "ai"
	VarsFunctionCallDestination    FunctionCallDestination = "vars"
	ContextFunctionCallDestination FunctionCallDestination = "context"
)

type FunctionCaller added in v0.19.0

type FunctionCaller struct {
	Name        string                     `yaml:"name" json:"name"`
	Code        *string                    `yaml:"code" json:"code"`
	Args        map[string]any             `yaml:"args" json:"args"`
	Description *string                    `yaml:"description" json:"description"`
	In          *FunctionCallDestination   `yaml:"in" json:"in" validate:"omitempty,oneof=ai vars context"`
	Var         *string                    `yaml:"var" json:"var"`
	Func        FunctionCallerCallbackFunc `yaml:"-" json:"-"`
}

FunctionCaller Represents a function invocation. NOTE: description is meant to explain to LLM what the output data is about when the function is called by an entity that's not the LLM itself. IMPORTANT: if Code is not nil, this will trigger the execution of the scripting engine. If the engine is nil, nothing will happen.

type FunctionCallerCallbackFunc added in v0.21.0

type FunctionCallerCallbackFunc func(ctx *util.FragsContext, data map[string]any) (any, error)

type FunctionCallers added in v0.19.0

type FunctionCallers []FunctionCaller

func (FunctionCallers) FilterAiFunctionCalls added in v0.19.0

func (f FunctionCallers) FilterAiFunctionCalls() FunctionCallers

func (FunctionCallers) FilterContextFunctionCalls added in v0.19.0

func (f FunctionCallers) FilterContextFunctionCalls() FunctionCallers

func (FunctionCallers) FilterVarsFunctionCalls added in v0.19.0

func (f FunctionCallers) FilterVarsFunctionCalls() FunctionCallers

type McpServerConfig added in v0.5.0

type McpServerConfig struct {
	Command      string            `json:"command,omitempty"`
	Args         []string          `json:"args,omitempty"`
	Env          map[string]string `json:"env,omitempty"`
	Cwd          string            `json:"cwd,omitempty"`
	Transport    string            `json:"transport,omitempty"`
	Url          string            `json:"url,omitempty"`
	Headers      map[string]string `json:"headers,omitempty"`
	Disabled     bool              `json:"disabled"`
	ClientID     *string           `json:"client_id,omitempty"`
	ClientSecret *string           `json:"client_secret,omitempty"`
	Token        *string           `json:"token,omitempty"`
}

McpServerConfig defines the configuration to connect to a MCP server

type McpServerConfigs added in v0.12.0

type McpServerConfigs map[string]McpServerConfig

McpServerConfigs is a map of MCP servers

func (McpServerConfigs) AsToolDefinitions added in v0.12.0

func (m McpServerConfigs) AsToolDefinitions() ToolDefinitions

AsToolDefinitions returns the MCP server configs as tool definitions

func (McpServerConfigs) McpTools added in v0.12.0

func (m McpServerConfigs) McpTools() McpTools

McpTools returns McpTool instances for each server configuration

type McpTool added in v0.5.0

type McpTool struct {
	Name string
	// contains filtered or unexported fields
}

McpTool is a wrapper around the MCP client

func NewMcpTool added in v0.5.0

func NewMcpTool(name string, serverConfig McpServerConfig) *McpTool

NewMcpTool creates a new MCP client wrapper

func (*McpTool) AsFunctions added in v0.5.0

func (c *McpTool) AsFunctions(ctx context.Context) (ExternalFunctions, error)

AsFunctions returns the tools as functions

func (*McpTool) Close added in v0.5.0

func (c *McpTool) Close() error

Close closes the connection to the server

func (*McpTool) Connect added in v0.5.0

func (c *McpTool) Connect(ctx context.Context, logger *log.StreamerLogger) error

Connect connects to the MCP server

func (*McpTool) ConnectSSE added in v0.5.0

func (c *McpTool) ConnectSSE(ctx context.Context, logger *log.StreamerLogger) error

ConnectSSE connects to the MCP server using an SSE transport

func (*McpTool) ConnectStd added in v0.5.0

func (c *McpTool) ConnectStd(ctx context.Context, _ *log.StreamerLogger) error

ConnectStd connects to the MCP server using a std/stdout transport

func (*McpTool) ConnectStreamableHttp added in v0.7.1

func (c *McpTool) ConnectStreamableHttp(ctx context.Context, logger *log.StreamerLogger) error

ConnectStreamableHttp connects to the MCP server using a Streamable HTTP transport, which is now the default. In case of failure, it falls back to SSE transport

func (*McpTool) ListTools added in v0.5.0

func (c *McpTool) ListTools(ctx context.Context) (ToolDefinitions, error)

ListTools lists the tools available on the server

func (*McpTool) Run added in v0.5.0

func (c *McpTool) Run(ctx *util.FragsContext, name string, arguments any) (any, error)

Run runs a tool on the server

func (*McpTool) WithOAuthProvider added in v0.23.0

func (c *McpTool) WithOAuthProvider(oauthProvider mcpauth.GenericOauthProvider) *McpTool

type McpTools added in v0.11.0

type McpTools []*McpTool

func (McpTools) AsFunctions added in v0.11.0

func (m McpTools) AsFunctions(ctx context.Context) (ExternalFunctions, error)

AsFunctions returns all the tools as functions

func (McpTools) Close added in v0.11.0

func (m McpTools) Close() error

Close closes all the connections

func (McpTools) Connect added in v0.11.0

func (m McpTools) Connect(ctx context.Context, logger *log.StreamerLogger) error

Connect connects to all the servers

func (McpTools) WithOAuthProvider added in v0.23.0

func (m McpTools) WithOAuthProvider(oauthProvider mcpauth.GenericOauthProvider) McpTools

type McpTransport added in v0.6.3

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

McpTransport is a wrapper around the default http.RoundTripper that adds default headers to every request

func NewMcpTransport added in v0.11.0

func NewMcpTransport(headers map[string]string, inner http.RoundTripper) *McpTransport

NewMcpTransport creates a new McpTransport instance

func (*McpTransport) RoundTrip added in v0.6.3

func (t *McpTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip adds default headers to the request

type Parameter added in v0.13.0

type Parameter struct {
	Name   string         `yaml:"name" json:"name"`
	Schema *schema.Schema `yaml:"schema" json:"schema"`
}

type Parameters added in v0.13.0

type Parameters []Parameter

type ParametersConfig added in v0.13.0

type ParametersConfig struct {
	Parameters
	LooseType bool
}

ParametersConfig holds a list of Parameters and a flag to allow loose type checking. We're using this to allow less accurate input mechanisms (like a CLI) to input everything as strings, and still validate it against the schema.

func (*ParametersConfig) MarshalJSON added in v0.22.1

func (p *ParametersConfig) MarshalJSON() ([]byte, error)

func (*ParametersConfig) MarshalYAML added in v0.22.1

func (p *ParametersConfig) MarshalYAML() (interface{}, error)

func (*ParametersConfig) SetLooseType added in v0.13.0

func (p *ParametersConfig) SetLooseType(looseType bool)

SetLooseType sets the type check to "loose". It means that whenever the validator finds a string in a parameter, it will investigate whether the string represents the expected type

func (*ParametersConfig) UnmarshalJSON added in v0.13.0

func (p *ParametersConfig) UnmarshalJSON(data []byte) error

UnmarshalJSON allows unmarshaling a Parameters slice directly into ParametersConfig

func (*ParametersConfig) UnmarshalYAML added in v0.13.0

func (p *ParametersConfig) UnmarshalYAML(node *yaml.Node) error

func (*ParametersConfig) Validate added in v0.13.0

func (p *ParametersConfig) Validate(data any) error

type Parser added in v0.14.0

type Parser string
const (
	JsonParser Parser = "json"
	CsvParser  Parser = "csv"
)

type PrePrompt added in v0.16.0

type PrePrompt []string

func (*PrePrompt) UnmarshalYAML added in v0.16.0

func (p *PrePrompt) UnmarshalYAML(unmarshal func(interface{}) error) error

type RequiredTool added in v0.21.0

type RequiredTool struct {
	Name string   `json:"name" yaml:"name" validate:"required,min=1"`
	Type ToolType `json:"type" yaml:"type" validate:"required,min=1"`
}

RequiredTool allows the plan writer to define what tools are certainly required, and allow for the runner to check requirements and possibly fail if the requirements are not met

type RequiredTools added in v0.21.0

type RequiredTools []RequiredTool

RequiredTools is a collection of RequiredTool

func (RequiredTools) Check added in v0.21.0

func (r RequiredTools) Check(toolDefinitions ToolDefinitions) error

Check verifies whether the RequiredTools are present in the toolDefinitions. An error will be returned if a tool is missing. However, if toolDefinitions is nil, this function will pass and return no error.

type Resource

type Resource struct {
	Identifier string                         `json:"identifier" yaml:"identifier" validate:"required,min=1"`
	Params     map[string]string              `json:"params" yaml:"params"`
	In         *resources.ResourceDestination `json:"in" yaml:"in" validate:"omitempty,oneof=ai vars prePrompt prompt"`
	Var        *string                        `json:"var" yaml:"var"`
}

Resource defines a resource to load, with an identifier and a map of parameters

type Runner

type Runner[T any] struct {
	ExternalFunctions ExternalFunctions
	ToolsDefinitions  ToolDefinitions
	// contains filtered or unexported fields
}

Runner is a struct that runs a session manager.

func NewRunner

func NewRunner[T any](sessionManager SessionManager, resourceLoader resources.ResourceLoader, ai Ai, options ...RunnerOption) Runner[T]

NewRunner creates a new runner.

func (*Runner[T]) CheckDependencies added in v0.3.0

func (r *Runner[T]) CheckDependencies(dependencies Dependencies) (DependencyCheckResult, error)

CheckDependencies checks whether a session can start, cannot start yet, or will never start

func (*Runner[T]) IsCompleted added in v0.3.0

func (r *Runner[T]) IsCompleted() bool

IsCompleted returns true if all sessions are completed

func (*Runner[T]) ListFailedSessions added in v0.18.0

func (r *Runner[T]) ListFailedSessions() []string

func (*Runner[T]) ListQueued added in v0.3.0

func (r *Runner[T]) ListQueued() Sessions

ListQueued returns a list of queued sessions

func (*Runner[T]) Logger added in v0.14.1

func (r *Runner[T]) Logger() *log.StreamerLogger

func (*Runner[T]) Run

func (r *Runner[T]) Run(ctx *util.FragsContext, params any) (*T, error)

Run runs the runner against an optional collection fo parameters

func (*Runner[T]) RunAllFunctionCallers added in v0.19.0

func (r *Runner[T]) RunAllFunctionCallers(ctx *util.FragsContext, fc FunctionCallers, scope evaluators.EvalScope) (map[string]any, error)

RunAllFunctionCallers runs all the function calls in the given collection.

func (*Runner[T]) RunFunction added in v0.9.0

func (r *Runner[T]) RunFunction(ctx *util.FragsContext, name string, args map[string]any) (any, error)

func (*Runner[T]) RunSessionAiPreCallsToTextContext added in v0.17.0

func (r *Runner[T]) RunSessionAiPreCallsToTextContext(ctx *util.FragsContext, session Session, scope evaluators.EvalScope) (string, error)

RunSessionAiPreCallsToTextContext runs the pre-call functions and composes a textual context to be prepended to the actual prompt.

func (*Runner[T]) ScriptEngine added in v0.9.0

func (r *Runner[T]) ScriptEngine() ScriptEngine

func (*Runner[T]) SetStatus added in v0.3.0

func (r *Runner[T]) SetStatus(sessionID string, status SessionStatus)

SetStatus sets the status of a session (thread-safe)

func (*Runner[T]) Transformers added in v0.9.0

func (r *Runner[T]) Transformers() *Transformers

type RunnerOption

type RunnerOption func(*RunnerOptions)

RunnerOption is an option for the runner.

func WithExternalFunctions added in v0.19.0

func WithExternalFunctions(externalFunctions ExternalFunctions) RunnerOption

func WithLogger

func WithLogger(logger *log.StreamerLogger) RunnerOption

WithLogger sets the logger for the runner.

func WithScriptEngine added in v0.9.0

func WithScriptEngine(scriptEngine ScriptEngine) RunnerOption

func WithSessionWorkers

func WithSessionWorkers(sessionWorkers int) RunnerOption

WithSessionWorkers sets the number of workers for the runner.

func WithToolsDefinitions added in v0.21.0

func WithToolsDefinitions(toolsDefinitions ToolDefinitions) RunnerOption

type RunnerOptions

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

RunnerOptions are options for the runner.

type SafeMap added in v0.3.0

type SafeMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewSafeMap added in v0.3.0

func NewSafeMap[K comparable, V any]() *SafeMap[K, V]

func (*SafeMap[K, V]) Iter added in v0.3.0

func (sm *SafeMap[K, V]) Iter() map[K]V

func (*SafeMap[K, V]) Load added in v0.3.0

func (sm *SafeMap[K, V]) Load(key K) (V, bool)

func (*SafeMap[K, V]) Store added in v0.3.0

func (sm *SafeMap[K, V]) Store(key K, value V)

Store is strongly typed: K and V are enforced at compile time.

type ScriptEngine added in v0.9.0

type ScriptEngine interface {
	RunCode(ctx *util.FragsContext, code string, params any, runner ExportableRunner) (any, error)
}

ScriptEngine is the interface that wraps the RunCode method. Frags provides NO script engines, it's the program that includes Frags that provides one, if necessary. Beware though, most script engines pose a security risk.

type Session

type Session struct {
	PreCalls        FunctionCallers `json:"preCalls,omitempty" yaml:"preCalls" validate:"omitempty,dive"`
	PrePrompt       PrePrompt       `json:"prePrompt,omitempty" yaml:"prePrompt,omitempty"`
	Prompt          string          `json:"prompt,omitempty" yaml:"prompt,omitempty" validate:"omitempty,min=3"`
	NextPhasePrompt string          `json:"nextPhasePrompt,omitempty" yaml:"nextPhasePrompt,omitempty"`
	Resources       []Resource      `json:"resources,omitempty" yaml:"resources,omitempty" validate:"dive"`
	Timeout         *string         `json:"timeout,omitempty" yaml:"timeout,omitempty"`
	DependsOn       Dependencies    `json:"dependsOn,omitempty" yaml:"dependsOn,omitempty"`
	Context         bool            `json:"context" yaml:"context"`
	Attempts        int             `json:"attempts,omitempty" yaml:"attempts,omitempty"`
	Tools           ToolDefinitions `json:"tools,omitempty" yaml:"tools,omitempty"`
	IterateOn       *string         `json:"iterateOn,omitempty" yaml:"iterateOn,omitempty"`
	Vars            map[string]any  `json:"vars,omitempty" yaml:"vars,omitempty"`
}

Session defines an LLM session, with its own context. Each session has a Prompt, a NextPhasePrompt for the phases after the first, and a list of resources to load. Each session may also have a PrePrompt, that is an LLM interaction that happens before the main one, produces no structured data, and has the sole purpose to enrich the context and get it ready. This is mostly useful for situations in which we need to use an extraction functionality that poorly harmonizes with a structured output. PreCalls defines a list of functions to call before the main interaction. PrePrompt is the prompt that will be called before the main interaction. This is mainly for context enrichment Prompt defines the main interaction. NextPhasePrompt defines the prompt that will be called after the main interaction. Resources configure resource loaders to load files for the session. Timeout defines the maximum time the session can run for. DependsOn defines a list of sessions that must be completed before this session can start, and expressions defining code evaluations against the already extracted data, to determine whether the session can start. Context defines whether the partially extracted data should be passed to the session. Attempts defines the number of times each phase should be retried if it fails. ToolDefinitions defines the tools that can be used in this session. IterateOn describes a variable (typically a list) over which we will iterate the session. The session will run len(IterateOn) times. Use an github.com/expr-lang/expr expression. Vars defines variables that are local to the session.

func (*Session) HasPrePrompt added in v0.15.0

func (s *Session) HasPrePrompt() bool

func (*Session) HasPrompt added in v0.17.0

func (s *Session) HasPrompt() bool

func (*Session) RenderNextPhasePrompt added in v0.2.0

func (s *Session) RenderNextPhasePrompt(scope evaluators.EvalScope) (string, error)

RenderNextPhasePrompt renders the next phase prompt (which may contain Go templat es), with the given scope

func (*Session) RenderPrePrompts added in v0.16.0

func (s *Session) RenderPrePrompts(scope evaluators.EvalScope) (PrePrompt, error)

RenderPrePrompts renders the pre-prompt (which may contain Go templates), with the given scope

func (*Session) RenderPrompt added in v0.2.0

func (s *Session) RenderPrompt(scope evaluators.EvalScope) (string, error)

RenderPrompt renders the prompt (which may contain Go templates), with the given scope

type SessionManager

type SessionManager struct {
	Parameters    *ParametersConfig `yaml:"parameters,omitempty" json:"parameters,omitempty"`
	RequiredTools RequiredTools     `yaml:"requiredTools,omitempty" json:"requiredTools,omitempty"`
	Transformers  *Transformers     `yaml:"transformers,omitempty" json:"transformers,omitempty"`
	SystemPrompt  *string           `yaml:"systemPrompt,omitempty" json:"systemPrompt,omitempty"`
	Components    Components        `yaml:"components,omitempty" json:"components,omitempty"`
	Sessions      Sessions          `yaml:"sessions" json:"sessions" validate:"required,min=1,dive"`
	Schema        *schema.Schema    `yaml:"schema,omitempty" json:"schema,omitempty"`
	Vars          map[string]any    `yaml:"vars,omitempty" json:"vars,omitempty"`
	PreCalls      FunctionCallers   `yaml:"preCalls,omitempty" json:"preCalls,omitempty"`
}

SessionManager manages the LLM sessions and the schema. Sessions split the contribution on the schema

func NewSessionManager

func NewSessionManager() SessionManager

NewSessionManager creates a new SessionManager.

func (*SessionManager) FromYAML

func (s *SessionManager) FromYAML(data []byte) error

FromYAML unmarshals a YAML document into the SessionManager.

func (*SessionManager) SetSchema

func (s *SessionManager) SetSchema(schema schema.Schema)

SetSchema sets the schema in the SessionManager.

func (*SessionManager) SetSession

func (s *SessionManager) SetSession(sessionID string, session Session)

SetSession sets a session in the SessionManager.

type SessionStatus added in v0.3.0

type SessionStatus string

SessionStatus is the status of a session.

type Sessions

type Sessions map[string]Session

Sessions is a map of session IDs to sessions.

type ToolCollections added in v0.12.0

type ToolCollections []ToolsCollection

type ToolDefinition added in v0.12.0

type ToolDefinition struct {
	Name        string         `json:"name" yaml:"name"`
	Collection  string         `json:"-" yaml:"-"`
	Description string         `json:"description,omitempty" yaml:"description,omitempty"`
	Type        ToolType       `json:"type" yaml:"type" validate:"required"`
	InputSchema *schema.Schema `json:"inputSchema,omitempty" yaml:"inputSchema,omitempty"`
	Allowlist   *[]string      `json:"allowlist,omitempty" yaml:"allowlist,omitempty"`
}

ToolDefinition defines a tool that can be used in a session. A tool can define a function, an MCP server or a collection. Name is either the tool name of the function name Collection gets populated during mcp/collection tool breakdown into single functions Description is the tool description. Optional, as the tool should already have a description, fill if you wish to override the default Type is either internet_search, function, mcp or collection InputSchema defines the input schema for the tool. mcp and collection tools don't have an input schema. Allowlist is a list of allowed functions when the tool is MCP or collection. If nil, all functions are allowed.

func (ToolDefinition) String added in v0.12.0

func (t ToolDefinition) String() string

type ToolDefinitions added in v0.12.0

type ToolDefinitions []ToolDefinition

ToolDefinitions is a list of tools

func (*ToolDefinitions) Contains added in v0.21.0

func (t *ToolDefinitions) Contains(name string, toolType ToolType) bool

Contains checks whether a certain combination of tool name and tool type appears in tools definitions

func (*ToolDefinitions) HasType added in v0.12.0

func (t *ToolDefinitions) HasType(tt ToolType) bool

HasType returns true if the tool list contains a tool of the given type. This is useful for "special" tools like internet_search, in which the type is all it needs.

type ToolType added in v0.4.0

type ToolType string
const (
	ToolTypeInternetSearch ToolType = "internet_search"
	ToolTypeFunction       ToolType = "function"
	ToolTypeMCP            ToolType = "mcp"
	ToolTypeCollection     ToolType = "collection"
)

type ToolsCollection added in v0.12.0

type ToolsCollection interface {
	Name() string
	Description() string
	AsFunctions() ExternalFunctions
}

ToolsCollection is a collection of functions. This is an integration commodity that standardizes how collections are defined so that multiple integrations can easily integrate one with the other.

type ToolsCollectionConfigs added in v0.12.0

type ToolsCollectionConfigs map[string]CollectionConfig

ToolsCollectionConfigs is a map of collection names to collection configurations

func (ToolsCollectionConfigs) AsToolDefinitions added in v0.12.0

func (t ToolsCollectionConfigs) AsToolDefinitions() ToolDefinitions

AsToolDefinitions returns the collection configs as tool definitions

type ToolsConfig added in v0.12.0

type ToolsConfig struct {
	McpServers  McpServerConfigs       `json:"mcpServers,omitempty"`
	Collections ToolsCollectionConfigs `json:"collections,omitempty"`
}

ToolsConfig defines the configuration for the MCP clients and collections. This serves no specific purpose within Frags itself, but it can be used by integrating applications to standardize the configuration format.

func (ToolsConfig) AsToolDefinitions added in v0.12.0

func (t ToolsConfig) AsToolDefinitions() ToolDefinitions

AsToolDefinitions returns the tools config as tool definitions

type Transformer added in v0.8.0

type Transformer struct {
	Name             string                  `yaml:"name" json:"name"`
	OnFunctionInput  *string                 `yaml:"onFunctionInput,omitempty" json:"onFunctionInput,omitempty"`
	OnFunctionOutput *string                 `yaml:"onFunctionOutput,omitempty" json:"onFunctionOutput,omitempty"`
	OnResource       *string                 `yaml:"onResource,omitempty" json:"onResource,omitempty"`
	Jsonata          *string                 `yaml:"jsonata" json:"jsonata"`
	JmesPath         *string                 `yaml:"jmesPath" json:"jmesPath"`
	Expr             *string                 `yaml:"expr" json:"expr"`
	Parser           *Parser                 `yaml:"parser" json:"parser"`
	Code             *string                 `yaml:"code" json:"code"`
	Func             TransformerCallbackFunc `yaml:"-" json:"-"`
}

Transformer is a functionality that given a certain input, transforms it into another output using either a Jsonata expression or a custom script (if the scripting engine is available). The transformer will run on specific triggers. We currently support only OnFunctionOutput.

func (Transformer) Transform added in v0.8.0

func (t Transformer) Transform(ctx *util.FragsContext, data any, runner ExportableRunner) (any, error)

Transform applies the transformation to the given data

type TransformerCallbackFunc added in v0.21.0

type TransformerCallbackFunc func(ctx *util.FragsContext, data any, runner ExportableRunner) (any, error)

type Transformers added in v0.8.0

type Transformers []Transformer

func (Transformers) FilterOnFunctionInput added in v0.10.0

func (t Transformers) FilterOnFunctionInput(name string) Transformers

func (Transformers) FilterOnFunctionOutput added in v0.8.0

func (t Transformers) FilterOnFunctionOutput(name string) Transformers

FilterOnFunctionOutput filters the transformers based on the OnFunctionOutput trigger

func (Transformers) FilterOnResource added in v0.14.0

func (t Transformers) FilterOnResource(name string) Transformers

func (Transformers) Transform added in v0.8.0

func (t Transformers) Transform(ctx *util.FragsContext, data any, runner ExportableRunner) (any, error)

Transform applies all the transformations to the given data

Directories

Path Synopsis
chatgpt module
gemini module
ollama module

Jump to

Keyboard shortcuts

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