chore(prompts): Rename Prompt blocks to Dynamic prompts
This commit is contained in:
@@ -39,7 +39,7 @@ type options struct {
|
||||
kbResults int
|
||||
ragdb RAGDB
|
||||
|
||||
prompts []PromptBlock
|
||||
prompts []DynamicPrompt
|
||||
|
||||
systemPrompt string
|
||||
|
||||
@@ -212,7 +212,7 @@ func WithCharacterFile(path string) Option {
|
||||
// WithPrompts adds additional block prompts to the agent
|
||||
// to be rendered internally in the conversation
|
||||
// when processing the conversation to the LLM
|
||||
func WithPrompts(prompts ...PromptBlock) Option {
|
||||
func WithPrompts(prompts ...DynamicPrompt) Option {
|
||||
return func(o *options) error {
|
||||
o.prompts = prompts
|
||||
return nil
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package agent
|
||||
|
||||
type PromptBlock interface {
|
||||
type DynamicPrompt interface {
|
||||
Render(a *Agent) (string, error)
|
||||
Role() string
|
||||
}
|
||||
|
||||
@@ -18,22 +18,22 @@ type ActionsConfig struct {
|
||||
Config string `json:"config"`
|
||||
}
|
||||
|
||||
type PromptBlocksConfig struct {
|
||||
type DynamicPromptsConfig struct {
|
||||
Type string `json:"type"`
|
||||
Config string `json:"config"`
|
||||
}
|
||||
|
||||
func (d PromptBlocksConfig) ToMap() map[string]string {
|
||||
func (d DynamicPromptsConfig) ToMap() map[string]string {
|
||||
config := map[string]string{}
|
||||
json.Unmarshal([]byte(d.Config), &config)
|
||||
return config
|
||||
}
|
||||
|
||||
type AgentConfig struct {
|
||||
Connector []ConnectorConfig `json:"connectors" form:"connectors" `
|
||||
Actions []ActionsConfig `json:"actions" form:"actions"`
|
||||
PromptBlocks []PromptBlocksConfig `json:"promptblocks" form:"promptblocks"`
|
||||
MCPServers []agent.MCPServer `json:"mcp_servers" form:"mcp_servers"`
|
||||
Connector []ConnectorConfig `json:"connectors" form:"connectors" `
|
||||
Actions []ActionsConfig `json:"actions" form:"actions"`
|
||||
DynamicPrompts []DynamicPromptsConfig `json:"dynamic_prompts" form:"dynamic_prompts"`
|
||||
MCPServers []agent.MCPServer `json:"mcp_servers" form:"mcp_servers"`
|
||||
|
||||
Description string `json:"description" form:"description"`
|
||||
|
||||
@@ -63,14 +63,18 @@ type AgentConfig struct {
|
||||
}
|
||||
|
||||
type AgentConfigMeta struct {
|
||||
Fields []config.Field
|
||||
Connectors []config.FieldGroup
|
||||
Actions []config.FieldGroup
|
||||
PromptBlocks []config.Field
|
||||
MCPServers []config.Field
|
||||
Fields []config.Field
|
||||
Connectors []config.FieldGroup
|
||||
Actions []config.FieldGroup
|
||||
DynamicPrompts []config.FieldGroup
|
||||
MCPServers []config.Field
|
||||
}
|
||||
|
||||
func NewAgentConfigMeta(actionsConfig []config.FieldGroup, connectorsConfig []config.FieldGroup) AgentConfigMeta {
|
||||
func NewAgentConfigMeta(
|
||||
actionsConfig []config.FieldGroup,
|
||||
connectorsConfig []config.FieldGroup,
|
||||
dynamicPromptsConfig []config.FieldGroup,
|
||||
) AgentConfigMeta {
|
||||
return AgentConfigMeta{
|
||||
Fields: []config.Field{
|
||||
{
|
||||
@@ -261,9 +265,9 @@ func NewAgentConfigMeta(actionsConfig []config.FieldGroup, connectorsConfig []co
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
PromptBlocks: []config.Field{},
|
||||
Connectors: connectorsConfig,
|
||||
Actions: actionsConfig,
|
||||
DynamicPrompts: dynamicPromptsConfig,
|
||||
Connectors: connectorsConfig,
|
||||
Actions: actionsConfig,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ type AgentPool struct {
|
||||
imageModel, localRAGAPI, localRAGKey, apiKey string
|
||||
availableActions func(*AgentConfig) func(ctx context.Context, pool *AgentPool) []types.Action
|
||||
connectors func(*AgentConfig) []Connector
|
||||
promptBlocks func(*AgentConfig) []PromptBlock
|
||||
dynamicPrompt func(*AgentConfig) []DynamicPrompt
|
||||
timeout string
|
||||
conversationLogs string
|
||||
}
|
||||
@@ -76,7 +76,7 @@ func NewAgentPool(
|
||||
LocalRAGAPI string,
|
||||
availableActions func(*AgentConfig) func(ctx context.Context, pool *AgentPool) []types.Action,
|
||||
connectors func(*AgentConfig) []Connector,
|
||||
promptBlocks func(*AgentConfig) []PromptBlock,
|
||||
promptBlocks func(*AgentConfig) []DynamicPrompt,
|
||||
timeout string,
|
||||
withLogs bool,
|
||||
) (*AgentPool, error) {
|
||||
@@ -107,7 +107,7 @@ func NewAgentPool(
|
||||
managers: make(map[string]sse.Manager),
|
||||
connectors: connectors,
|
||||
availableActions: availableActions,
|
||||
promptBlocks: promptBlocks,
|
||||
dynamicPrompt: promptBlocks,
|
||||
timeout: timeout,
|
||||
conversationLogs: conversationPath,
|
||||
}, nil
|
||||
@@ -131,7 +131,7 @@ func NewAgentPool(
|
||||
pool: *poolData,
|
||||
connectors: connectors,
|
||||
localRAGAPI: LocalRAGAPI,
|
||||
promptBlocks: promptBlocks,
|
||||
dynamicPrompt: promptBlocks,
|
||||
availableActions: availableActions,
|
||||
timeout: timeout,
|
||||
conversationLogs: conversationPath,
|
||||
@@ -303,7 +303,7 @@ func (a *AgentPool) startAgentWithConfig(name string, config *AgentConfig) error
|
||||
}
|
||||
|
||||
connectors := a.connectors(config)
|
||||
promptBlocks := a.promptBlocks(config)
|
||||
promptBlocks := a.dynamicPrompt(config)
|
||||
actions := a.availableActions(config)(ctx, a)
|
||||
stateFile, characterFile := a.stateFiles(name)
|
||||
|
||||
|
||||
2
main.go
2
main.go
@@ -62,7 +62,7 @@ func main() {
|
||||
localRAG,
|
||||
services.Actions,
|
||||
services.Connectors,
|
||||
services.PromptBlocks,
|
||||
services.DynamicPrompts,
|
||||
timeout,
|
||||
withLogs,
|
||||
)
|
||||
|
||||
@@ -3,6 +3,7 @@ package services
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/mudler/LocalAgent/pkg/config"
|
||||
"github.com/mudler/LocalAgent/pkg/xlog"
|
||||
"github.com/mudler/LocalAgent/services/prompts"
|
||||
|
||||
@@ -11,7 +12,6 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// Connectors
|
||||
DynamicPromptCustom = "custom"
|
||||
)
|
||||
|
||||
@@ -19,10 +19,16 @@ var AvailableBlockPrompts = []string{
|
||||
DynamicPromptCustom,
|
||||
}
|
||||
|
||||
func PromptBlocks(a *state.AgentConfig) []agent.PromptBlock {
|
||||
promptblocks := []agent.PromptBlock{}
|
||||
func DynamicPromptsConfigMeta() []config.FieldGroup {
|
||||
return []config.FieldGroup{
|
||||
prompts.NewDynamicPromptConfigMeta(),
|
||||
}
|
||||
}
|
||||
|
||||
for _, c := range a.PromptBlocks {
|
||||
func DynamicPrompts(a *state.AgentConfig) []agent.DynamicPrompt {
|
||||
promptblocks := []agent.DynamicPrompt{}
|
||||
|
||||
for _, c := range a.DynamicPrompts {
|
||||
var config map[string]string
|
||||
if err := json.Unmarshal([]byte(c.Config), &config); err != nil {
|
||||
xlog.Info("Error unmarshalling connector config", err)
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/mudler/LocalAgent/core/agent"
|
||||
"github.com/mudler/LocalAgent/pkg/config"
|
||||
"github.com/mudler/LocalAgent/pkg/xlog"
|
||||
"github.com/traefik/yaegi/interp"
|
||||
"github.com/traefik/yaegi/stdlib"
|
||||
@@ -48,6 +49,38 @@ func (a *DynamicPrompt) callInit() error {
|
||||
return run()
|
||||
}
|
||||
|
||||
func NewDynamicPromptConfigMeta() config.FieldGroup {
|
||||
return config.FieldGroup {
|
||||
Name: "custom",
|
||||
Label: "Custom Prompt",
|
||||
Fields: []config.Field{
|
||||
{
|
||||
Name: "name",
|
||||
Label: "Name",
|
||||
Type: config.FieldTypeText,
|
||||
Required: true,
|
||||
HelpText: "A unique name for your custom prompt",
|
||||
Placeholder: "Enter a unique name",
|
||||
},
|
||||
{
|
||||
Name: "code",
|
||||
Label: "Go Code",
|
||||
Type: config.FieldTypeTextarea,
|
||||
Required: true,
|
||||
HelpText: "Enter code that implements the Render and Role functions here",
|
||||
Placeholder: "Write your Go code here",
|
||||
},
|
||||
{
|
||||
Name: "unsafe",
|
||||
Label: "Unsafe Code",
|
||||
Type: config.FieldTypeCheckbox,
|
||||
Required: false,
|
||||
HelpText: "Enable if the code needs to use unsafe Go features",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (a *DynamicPrompt) initializeInterpreter() error {
|
||||
if _, exists := a.config["code"]; exists && a.i == nil {
|
||||
unsafe := strings.ToLower(a.config["unsafe"]) == "true"
|
||||
|
||||
@@ -607,6 +607,7 @@ func (a *App) GetAgentConfigMeta() func(c *fiber.Ctx) error {
|
||||
configMeta := state.NewAgentConfigMeta(
|
||||
services.ActionsConfigMeta(),
|
||||
services.ConnectorsConfigMeta(),
|
||||
services.DynamicPromptsConfigMeta(),
|
||||
)
|
||||
return c.JSON(configMeta)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user