prompt

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const MaxSkillDescChars = 250

MaxSkillDescChars is the maximum characters for skill descriptions in listings Reference: Claude Code's MAX_LISTING_DESC_CHARS = 250

Variables

This section is empty.

Functions

func BuildDefaultPrompt

func BuildDefaultPrompt(req *types.RunRequest, enabledTools []string) string

BuildDefaultPrompt builds the default system prompt using the prompt builder

func BuildDynamicPrompt

func BuildDynamicPrompt(req *types.RunRequest) string

BuildDynamicPrompt builds only the dynamic sections (Skills, MCPs, Context, Files, A2A, InternalAgents, ResponseSchema) These are always recalculated per request

func BuildSimplePrompt

func BuildSimplePrompt(customPrompt string) string

BuildSimplePrompt builds a simple prompt without the full section structure This is useful when you just need a basic prompt quickly

func BuildStaticPrompt

func BuildStaticPrompt(enabledTools []string) string

BuildStaticPrompt builds only the static sections, including selected capability guidance. These can be cached per agent + tools combination

func GetA2AAgentsSection

func GetA2AAgentsSection(a2a []types.A2AAgentConfig) string

GetA2AAgentsSection returns the A2A agents section

func GetActionsSection

func GetActionsSection() string

GetActionsSection returns the careful actions section (dangerous operations)

func GetContextSection

func GetContextSection(context map[string]any) string

GetContextSection returns the context variables section

func GetDoingTasksSection

func GetDoingTasksSection() string

GetDoingTasksSection returns the task execution rules section

func GetFilesSection

func GetFilesSection(files []types.FileConfig) string

GetFilesSection returns the uploaded files section

func GetInternalAgentsSection

func GetInternalAgentsSection(agents []types.InternalAgentConfig) string

GetInternalAgentsSection returns the internal agents section

func GetIntroSection

func GetIntroSection() string

GetIntroSection returns the identity definition section

func GetMcpSection

func GetMcpSection(mcps []types.MCPConfig) string

GetMcpSection returns the MCP instructions section (dynamic)

func GetMemorySection

func GetMemorySection(indexLines []string) string

GetMemorySection returns the memory section for the prompt memories 是记忆内容列表,index 是索引列表(用于展示)

func GetOutputEfficiencySection

func GetOutputEfficiencySection() string

GetOutputEfficiencySection returns the output efficiency section

func GetResponseLanguageSection added in v0.1.2

func GetResponseLanguageSection(locale, userPrompt string) string

GetResponseLanguageSection applies the frontend selection unless the user explicitly requests a different response language in the current message.

func GetResponseSchemaSection

func GetResponseSchemaSection(schema *types.ResponseSchemaConfig) string

GetResponseSchemaSection returns the response schema section for structured output

func GetRuntimeContextSection added in v0.1.2

func GetRuntimeContextSection(now time.Time, requestContext ...map[string]any) string

GetRuntimeContextSection returns per-request temporal context that must not be cached.

func GetSkillUsageSection

func GetSkillUsageSection() string

GetSkillUsageSection returns practical examples of skill usage

func GetSkillsSection

func GetSkillsSection(skills []types.Skill) string

GetSkillsSection returns the available skills section with metadata (dynamic) Reference: DB-GPT's progressive disclosure pattern

func GetSkillsSystemSection

func GetSkillsSystemSection() string

GetSkillsSystemSection returns the skills system guidance (Reference: DB-GPT SKILLS_SYSTEM_PROMPT) This instructs the LLM on how to use skills

func GetSystemSection

func GetSystemSection() string

GetSystemSection returns the system rules section

func GetToneAndStyleSection

func GetToneAndStyleSection() string

GetToneAndStyleSection returns the tone and style section

func GetUsingCapabilitiesSection added in v0.1.2

func GetUsingCapabilitiesSection(enabledCapabilities []string) string

GetUsingCapabilitiesSection returns guidance for selected abilities.

Types

type CachedPrompt

type CachedPrompt struct {
	StaticSections string
	ToolsHash      string
	BuiltAt        time.Time
}

CachedPrompt represents a cached static sections prompt

type PromptBuilder

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

PromptBuilder builds structured system prompts

func NewPromptBuilder

func NewPromptBuilder() *PromptBuilder

NewPromptBuilder creates a new prompt builder

func (*PromptBuilder) AddCustomSection

func (b *PromptBuilder) AddCustomSection(name string, content string) *PromptBuilder

AddCustomSection adds a custom section with the given type and content

func (*PromptBuilder) AddDynamicSection

func (b *PromptBuilder) AddDynamicSection(sectionType SectionType, content string) *PromptBuilder

AddDynamicSection adds a dynamic section that should be recalculated

func (*PromptBuilder) AddStaticSection

func (b *PromptBuilder) AddStaticSection(sectionType SectionType, content string) *PromptBuilder

AddStaticSection adds a static (non-changing) section

func (*PromptBuilder) Build

func (b *PromptBuilder) Build() string

Build builds the final prompt string

func (*PromptBuilder) BuildWithCustomPrompt

func (b *PromptBuilder) BuildWithCustomPrompt(customPrompt string) string

BuildWithCustomPrompt builds prompt with custom system prompt prepended

func (*PromptBuilder) Clear

func (b *PromptBuilder) Clear() *PromptBuilder

Clear removes all sections

func (*PromptBuilder) GetDynamicSections

func (b *PromptBuilder) GetDynamicSections() string

GetDynamicSections returns only the dynamic sections joined together

func (*PromptBuilder) GetStaticSections

func (b *PromptBuilder) GetStaticSections() string

GetStaticSections returns only the static sections joined together

func (*PromptBuilder) Sections

func (b *PromptBuilder) Sections() []PromptSection

Sections returns all sections

type PromptCache

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

PromptCache caches static sections of prompts per agent

func NewPromptCache

func NewPromptCache() *PromptCache

NewPromptCache creates a new prompt cache

func (*PromptCache) Clear

func (c *PromptCache) Clear()

Clear removes all cached entries

func (*PromptCache) Get

func (c *PromptCache) Get(agentID string) (string, string, bool)

Get retrieves cached static sections for an agent Returns (content, toolsHash, found)

func (*PromptCache) Invalidate

func (c *PromptCache) Invalidate(agentID string)

Invalidate removes cached entry for an agent

func (*PromptCache) Set

func (c *PromptCache) Set(agentID string, staticSections string, toolsHash string)

Set stores static sections for an agent

func (*PromptCache) ShouldRefresh

func (c *PromptCache) ShouldRefresh(agentID string, currentToolsHash string) bool

ShouldRefresh checks if the cache should be refreshed based on tools hash

func (*PromptCache) Stats

func (c *PromptCache) Stats() (int, time.Time)

Stats returns cache statistics

type PromptSection

type PromptSection struct {
	Type    SectionType
	Content string
	Dynamic bool // 动态区块每次重新计算
}

PromptSection represents a single section in the prompt

type SectionType

type SectionType string

SectionType represents the type of prompt section

const (
	IntroSection             SectionType = "intro"
	SystemSection            SectionType = "system"
	DoingTasksSection        SectionType = "doing_tasks"
	ActionsSection           SectionType = "actions"
	UsingCapabilitiesSection SectionType = "using_capabilities"
	OutputEfficiencySection  SectionType = "output_efficiency"
	ToneAndStyleSection      SectionType = "tone_and_style"
	SkillsSection            SectionType = "skills"
	SkillsSystemSection      SectionType = "skills_system"
	SkillUsageSection        SectionType = "skill_usage"
	McpSection               SectionType = "mcp"
	EnvironmentSection       SectionType = "environment"
	SessionSpecificSection   SectionType = "session_specific"
	ContextSection           SectionType = "context"
	FilesSection             SectionType = "files"
	A2AAgentsSection         SectionType = "a2a_agents"
	InternalAgentsSection    SectionType = "internal_agents"
	MemorySection            SectionType = "memory"
	ResponseSchemaSection    SectionType = "response_schema"
)

Jump to

Keyboard shortcuts

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