mirror of
https://github.com/mudler/LocalAI.git
synced 2026-11-06 20:43:27 -05:00
A saved agent keeps its own skills in LocalAI/agents/<agent>/skills. Only a chat that runs that agent sees them. They sit between the folder and personal layers, so an agent's version of a skill wins for that agent, and they count as granted without being listed in the agent's skills. An agent writes one by a skill change proposal, as before; the new layer only reads them. A proposal for an agent skill cannot take the name of a core skill or of a document slot (read from slots.json). When writing-skills loads in a chat of a saved agent it starts with "Do not write files. Call propose_change with kind skill.", and the skills.write grant makes it visible to the agent. The Skills list gains the agent layer, with the agent's ID and name, and a skill can be read or removed (to the Trash) with the agent query parameter. Assisted-by: Claude:claude-sonnet-5-5 go swag
87 lines
2.4 KiB
Go
87 lines
2.4 KiB
Go
package studio
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"sort"
|
|
"strings"
|
|
|
|
"github.com/mudler/LocalAI/core/services/studio/agents"
|
|
"github.com/mudler/LocalAI/core/services/studio/session"
|
|
)
|
|
|
|
// scope is what a saved agent allows a chat. It only narrows: each list is
|
|
// intersected with what the user may use at the time of the turn. A nil scope is
|
|
// a plain chat, which gets everything its user may use.
|
|
type scope struct {
|
|
agentName string
|
|
agentID string // the saved agent of the chat; its skills layer is granted
|
|
instructions string
|
|
deleted bool // the chat names an agent that no longer exists
|
|
mcp []string
|
|
addons map[string]bool
|
|
collections map[string]bool
|
|
skills map[string]bool
|
|
builtins map[string]bool // the builtin grants the agent holds now
|
|
builtinNames []string
|
|
skillNames []string
|
|
addonNames []string
|
|
collNames []string
|
|
}
|
|
|
|
func set(l []string) map[string]bool {
|
|
m := make(map[string]bool, len(l))
|
|
for _, v := range l {
|
|
m[v] = true
|
|
}
|
|
return m
|
|
}
|
|
|
|
// scopeOf returns the scope of a chat, or nil for a plain chat.
|
|
func (s *Service) scopeOf(ctx context.Context, rec session.ChatRecord) *scope {
|
|
if rec.AgentID == "" {
|
|
return nil
|
|
}
|
|
if s.d.Agents == nil {
|
|
return &scope{deleted: true}
|
|
}
|
|
ag, err := s.d.Agents.Get(ctx, rec.Principal, rec.AgentID)
|
|
if errors.Is(err, agents.ErrNotFound) {
|
|
return &scope{deleted: true}
|
|
}
|
|
if err != nil {
|
|
s.log.Warn("studio: agent unavailable", "chat", rec.ID, "agent", rec.AgentID, "error", err)
|
|
return &scope{deleted: true}
|
|
}
|
|
held := s.usableGrants(ctx, rec.Principal, ag.Builtins)
|
|
return &scope{
|
|
agentID: rec.AgentID, agentName: ag.Name,
|
|
builtins: set(held), builtinNames: held,
|
|
instructions: strings.TrimSpace(ag.Instructions), mcp: ag.MCPServers,
|
|
addons: set(ag.Addons), collections: set(ag.Collections), skills: set(ag.Skills),
|
|
addonNames: ag.Addons, collNames: ag.Collections, skillNames: ag.Skills,
|
|
}
|
|
}
|
|
|
|
// unavailable renders the grants that could not be used into one line for the
|
|
// model. Empty when nothing is missing.
|
|
func unavailable(parts ...[]string) string {
|
|
var all []string
|
|
for _, p := range parts {
|
|
all = append(all, p...)
|
|
}
|
|
if len(all) == 0 {
|
|
return ""
|
|
}
|
|
sort.Strings(all)
|
|
return "unavailable this turn: " + strings.Join(all, ", ")
|
|
}
|
|
|
|
func prefixed(prefix string, names []string) []string {
|
|
out := make([]string, len(names))
|
|
for i, n := range names {
|
|
out[i] = prefix + " " + n
|
|
}
|
|
return out
|
|
}
|