demo
This commit is contained in:
79
agents/agent.go
Normal file
79
agents/agent.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package agents
|
||||
|
||||
import "gocoder/db"
|
||||
|
||||
// Agent defines the interface that all agents must implement.
|
||||
type Agent interface {
|
||||
// Type returns the unique agent type identifier (e.g. "dadjokes", "poet", "robot").
|
||||
Type() string
|
||||
|
||||
// DisplayName returns the human-readable name for the agent.
|
||||
DisplayName() string
|
||||
|
||||
// Description returns a short description shown in the UI.
|
||||
Description() string
|
||||
|
||||
// Icon returns an SVG icon string (inline) for the agent selector.
|
||||
Icon() string
|
||||
|
||||
// SystemMessage returns the system prompt for this agent.
|
||||
SystemMessage() string
|
||||
|
||||
// ShouldRespond returns true if the agent should process the given user message.
|
||||
// When false, the agent will not be used even if selected.
|
||||
ShouldRespond(message string) bool
|
||||
|
||||
// RequiresWorkspace returns true if this agent needs a workspace location to function.
|
||||
RequiresWorkspace() bool
|
||||
}
|
||||
|
||||
// AgentRegistry holds all registered agents and provides lookup by type.
|
||||
type AgentRegistry struct {
|
||||
agents []Agent
|
||||
}
|
||||
|
||||
// NewAgentRegistry creates and registers all built-in agents.
|
||||
func NewAgentRegistry() *AgentRegistry {
|
||||
r := &AgentRegistry{}
|
||||
r.Register(&DadjokesAgent{})
|
||||
r.Register(&PoetAgent{})
|
||||
r.Register(&RobotAgent{})
|
||||
r.Register(&CompactorAgent{})
|
||||
r.Register(&CodingAgent{})
|
||||
return r
|
||||
}
|
||||
|
||||
// Register adds an agent to the registry.
|
||||
func (r *AgentRegistry) Register(a Agent) {
|
||||
r.agents = append(r.agents, a)
|
||||
}
|
||||
|
||||
// All returns all registered agents.
|
||||
func (r *AgentRegistry) All() []Agent {
|
||||
return r.agents
|
||||
}
|
||||
|
||||
// GetByType returns the agent with the given type.
|
||||
func (r *AgentRegistry) GetByType(t string) Agent {
|
||||
for _, a := range r.agents {
|
||||
if a.Type() == t {
|
||||
return a
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSystemMessages returns a slice of system messages for the selected agents.
|
||||
func (r *AgentRegistry) GetSystemMessages(agentTypes []string) []db.Message {
|
||||
var msgs []db.Message
|
||||
for _, t := range agentTypes {
|
||||
a := r.GetByType(t)
|
||||
if a != nil {
|
||||
msgs = append(msgs, db.Message{
|
||||
Role: "system",
|
||||
Content: a.SystemMessage(),
|
||||
})
|
||||
}
|
||||
}
|
||||
return msgs
|
||||
}
|
||||
Reference in New Issue
Block a user