refactor: move webui.listen_addr from core.daemon to webui category

This commit is contained in:
JianFeeeee
2026-07-14 11:22:46 +08:00
parent 28dc095dc5
commit c7e22fbe30
15 changed files with 1813 additions and 379 deletions

View File

@ -1522,6 +1522,9 @@ func (a *Agent) buildSystemPrompt(memContext string, userInput string) string {
prompt += "\n\n" + a.indexer.BuildToolPrompt()
}
// 动态工具目录
prompt += a.buildToolCatalog()
return prompt
}
@ -1549,6 +1552,41 @@ func cleanParams(params map[string]interface{}) map[string]interface{} {
return cleaned
}
func (a *Agent) buildToolCatalog() string {
defs := a.buildToolDefs()
if len(defs) == 0 {
return ""
}
var sb strings.Builder
sb.WriteString("\n\n【可用工具列表】")
seen := make(map[string]bool)
for _, d := range defs {
t, ok := d.(map[string]interface{})
if !ok {
continue
}
fn, ok := t["function"].(map[string]interface{})
if !ok {
continue
}
name, _ := fn["name"].(string)
if name == "" || seen[name] {
continue
}
seen[name] = true
desc, _ := fn["description"].(string)
sb.WriteString(fmt.Sprintf("\n- %s", name))
if desc != "" {
// only first 80 chars of description
if len(desc) > 80 {
desc = desc[:80] + "..."
}
sb.WriteString(": " + desc)
}
}
return sb.String()
}
func (a *Agent) buildToolDefs() []interface{} {
var tools []interface{}

View File

@ -2,6 +2,7 @@ package core
import (
"fmt"
"log"
"sync"
sdk "gitcode.com/JianFeeeee/HomeAgent/internal/sdk"
@ -85,6 +86,7 @@ func inferToolPlugin(name string) string {
// - 只读操作先调用 ctx.RLock() / defer ctx.RUnlock()
// - 写操作(如设置 ctx.Response先调用 ctx.Lock() / defer ctx.Unlock()
// 如果任意 handler 设置了 Response后续 handler 可通过 ctx.IsResponded() 判断后提前返回。
// handler 返回的 error 会被收集到 ctx.Errors 中并记录日志,不会中断其他 handler 的执行。
func (h *StageHost) RunStage(stage sdk.Stage, ctx *sdk.StageContext) {
h.mu.RLock()
handlers := h.stages[stage]
@ -93,14 +95,29 @@ func (h *StageHost) RunStage(stage sdk.Stage, ctx *sdk.StageContext) {
return
}
var wg sync.WaitGroup
errCh := make(chan error, len(handlers))
for _, handler := range handlers {
wg.Add(1)
go func(fn sdk.StageHandler) {
defer wg.Done()
fn(ctx)
if err := fn(ctx); err != nil {
errCh <- err
}
}(handler)
}
wg.Wait()
close(errCh)
var errs []string
for err := range errCh {
errs = append(errs, err.Error())
log.Printf("[stage] %s handler error: %v", stage, err)
}
if len(errs) > 0 {
ctx.Lock()
ctx.Errors = append(ctx.Errors, errs...)
ctx.Unlock()
}
}
func (h *StageHost) ToolCount() int {

View File

@ -68,32 +68,32 @@ func channelInfoFromIO(ch agentIO.ChannelInfo) ChannelInfo {
}
type MemoryStatus struct {
Available bool `json:"available"`
EntityCount int `json:"entity_count,omitempty"`
RelationCount int `json:"relation_count,omitempty"`
EntityTypes int `json:"entity_types,omitempty"`
Available bool `json:"available"`
EntityCount int `json:"entity_count"`
RelationCount int `json:"relation_count"`
EntityTypes int `json:"entity_types"`
}
type KnowledgeStatus struct {
Available bool `json:"available"`
ItemCount int `json:"item_count,omitempty"`
ItemCount int `json:"item_count"`
Items []string `json:"items,omitempty"`
}
type DocumentStatus struct {
Available bool `json:"available"`
DocCount int `json:"doc_count,omitempty"`
VectorCount int `json:"vector_count,omitempty"`
DocCount int `json:"doc_count"`
VectorCount int `json:"vector_count"`
}
type TextMemoryStatus struct {
Available bool `json:"available"`
FileCount int `json:"file_count,omitempty"`
FileCount int `json:"file_count"`
}
type SocialStatus struct {
Available bool `json:"available"`
PersonCount int `json:"person_count,omitempty"`
PersonCount int `json:"person_count"`
}
type SkillsStatus struct {